import { findRuleByDottedName } from 'Engine/rules' import React, { useEffect } from 'react' import { Trans } from 'react-i18next' import { useDispatch, useSelector } from 'react-redux' import { flatRulesSelector, situationSelector } from 'Selectors/analyseSelectors' import './PeriodSwitch.css' export default function PeriodSwitch() { const dispatch = useDispatch() const rules = useSelector(flatRulesSelector) const situation = useSelector(situationSelector) const initialPeriod = useSelector( state => state.simulation?.config?.situation?.période ) useEffect(() => { !currentPeriod && updatePeriod(initialPeriod || 'année') }, []) const currentPeriod = situation.période const updatePeriod = toPeriod => { const needConversion = Object.keys(situation).filter(dottedName => { const rule = findRuleByDottedName(rules, dottedName) return rule?.période === 'flexible' }) dispatch({ type: 'UPDATE_PERIOD', toPeriod, needConversion }) } const periods = ['mois', 'année'] return ( {periods.map(period => ( ))} ) }