import { findRuleByDottedName, nestedSituationToPathMap } from 'Engine/rules' import { compose, filter, map, toPairs } from 'ramda' import React, { useEffect } from 'react' import { Trans, withTranslation } from 'react-i18next' import { connect } from 'react-redux' import { batchActions } from 'redux-batched-actions' import { change, Field, reduxForm } from 'redux-form' import { flatRulesSelector, situationSelector, situationsWithDefaultsSelector } from 'Selectors/analyseSelectors' import './PeriodSwitch.css' export default compose( reduxForm({ form: 'conversation', destroyOnUnmount: false }), withTranslation(), connect( state => { let situation = situationsWithDefaultsSelector(state) if (Array.isArray(situation)) { situation = situation[0] } return { rules: flatRulesSelector(state), situation: nestedSituationToPathMap(situationSelector(state)), initialPériode: situation.période } }, dispatch => ({ batchPeriodChange: actions => dispatch(batchActions(actions)) }) ) )(function PeriodSwitch({ situation, rules, batchPeriodChange, initialPériode }) { useEffect(() => { !situation.période && updateSituation( initialPériode || 'année', batchPeriodChange, situation, rules ) return }) return (