From e67ced3d97ade200fdaf938a5fb4700dc18e533a Mon Sep 17 00:00:00 2001 From: Alice Dahan Date: Tue, 15 Oct 2024 16:49:01 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20met=20=C3=A0=20jour=20la=20r=C3=A9mun?= =?UTF-8?q?=C3=A9ration=20totale=20lors=20de=20la=20modification=20mois=20?= =?UTF-8?q?par=20mois?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reduction-generale/RéductionGénérale.tsx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 }) }