diff --git a/site/source/pages/simulateurs/reduction-generale/RéductionGénérale.tsx b/site/source/pages/simulateurs/reduction-generale/RéductionGénérale.tsx index e50f034f6..aa889bdb4 100644 --- a/site/source/pages/simulateurs/reduction-generale/RéductionGénérale.tsx +++ b/site/source/pages/simulateurs/reduction-generale/RéductionGénérale.tsx @@ -1,6 +1,8 @@ +import { DottedName } from 'modele-social' +import { PublicodesExpression } from 'publicodes' import { useCallback, useEffect, useState } from 'react' import { Trans, useTranslation } from 'react-i18next' -import { useSelector } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' import { styled } from 'styled-components' import { Condition } from '@/components/EngineValue/Condition' @@ -17,6 +19,8 @@ import { Message } from '@/design-system' import { Spacing } from '@/design-system/layout' import { Li, Ul } from '@/design-system/typography/list' import { Body } from '@/design-system/typography/paragraphs' +import { SimpleRuleEvaluation } from '@/domaine/engine/SimpleRuleEvaluation' +import { ajusteLaSituation } from '@/store/actions/actions' import { situationSelector } from '@/store/selectors/simulationSelectors' import EffectifSwitch from './components/EffectifSwitch' @@ -92,6 +96,7 @@ function RéductionGénéraleSimulationGoals({ legend: string }) { const engine = useEngine() + const dispatch = useDispatch() const { t } = useTranslation() const [réductionGénéraleMoisParMoisData, setData] = useState([]) @@ -115,6 +120,22 @@ function RéductionGénéraleSimulationGoals({ ) }, [engine, situation]) + const updateRémunérationBruteAnnuelle = (data: MonthState[]): void => { + const rémunérationBruteAnnuelle = data.reduce( + (total: number, monthState: MonthState) => + total + monthState.rémunérationBrute, + 0 + ) + dispatch( + ajusteLaSituation({ + [rémunérationBruteDottedName]: { + valeur: rémunérationBruteAnnuelle, + unité: '€/an', + } as PublicodesExpression, + } as Record) + ) + } + const onRémunérationChange = ( monthIndex: number, rémunérationBrute: number @@ -129,6 +150,8 @@ function RéductionGénéraleSimulationGoals({ ), } + updateRémunérationBruteAnnuelle(updatedData) + return updatedData }) }