From 8b630d2265b2dc9ff2b3e069966991a49b759401 Mon Sep 17 00:00:00 2001 From: Alice Dahan Date: Mon, 2 Dec 2024 16:41:48 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20pr=C3=A9-rempli=20les=20heures=20sup=20?= =?UTF-8?q?mois=20par=20mois=20avec=20la=20valeur=20globale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulateurs/reduction-generale/Goals.tsx | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/site/source/pages/simulateurs/reduction-generale/Goals.tsx b/site/source/pages/simulateurs/reduction-generale/Goals.tsx index 4232ebfee..0da8748ac 100644 --- a/site/source/pages/simulateurs/reduction-generale/Goals.tsx +++ b/site/source/pages/simulateurs/reduction-generale/Goals.tsx @@ -1,6 +1,6 @@ import { DottedName } from 'modele-social' import { PublicodesExpression } from 'publicodes' -import { useCallback, useEffect, useState } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { useDispatch, useSelector } from 'react-redux' @@ -13,6 +13,7 @@ import { Message } from '@/design-system' import { Spacing } from '@/design-system/layout' import { Body } from '@/design-system/typography/paragraphs' import { SimpleRuleEvaluation } from '@/domaine/engine/SimpleRuleEvaluation' +import { Situation } from '@/domaine/Situation' import { ajusteLaSituation } from '@/store/actions/actions' import { situationSelector } from '@/store/selectors/simulationSelectors' @@ -22,6 +23,8 @@ import WarningSalaireTrans from './components/WarningSalaireTrans' import RéductionGénéraleMoisParMois from './MoisParMois' import { getInitialRéductionGénéraleMoisParMois, + heuresComplémentairesDottedName, + heuresSupplémentairesDottedName, MonthState, Options, réductionGénéraleDottedName, @@ -30,6 +33,19 @@ import { rémunérationBruteDottedName, } from './utils' +type SituationType = Situation & { + [heuresSupplémentairesDottedName]?: { + explanation: { + nodeValue: number + } + } + [heuresComplémentairesDottedName]?: { + explanation: { + nodeValue: number + } + } +} + export default function RéductionGénéraleSimulationGoals({ monthByMonth, toggles, @@ -46,6 +62,8 @@ export default function RéductionGénéraleSimulationGoals({ const { t } = useTranslation() const [réductionGénéraleMoisParMoisData, setData] = useState([]) const year = useYear() + const situation = useSelector(situationSelector) as SituationType + const previousSituation = useRef(situation) const initializeRéductionGénéraleMoisParMoisData = useCallback(() => { const data = getInitialRéductionGénéraleMoisParMois(year, engine) @@ -61,16 +79,57 @@ export default function RéductionGénéraleSimulationGoals({ réductionGénéraleMoisParMoisData.length, ]) - const situation = useSelector(situationSelector) + const getOptionsFromSituations = ( + previousSituation: SituationType, + newSituation: SituationType + ): Partial => { + const options = {} as Partial + + const previousHeuresSupplémentaires = + previousSituation[heuresSupplémentairesDottedName]?.explanation.nodeValue + const newHeuresSupplémentaires = + newSituation[heuresSupplémentairesDottedName]?.explanation.nodeValue + if (newHeuresSupplémentaires !== previousHeuresSupplémentaires) { + options.heuresSupplémentaires = newHeuresSupplémentaires || 0 + } + + const previousHeuresComplémentaires = + previousSituation[heuresComplémentairesDottedName]?.explanation.nodeValue + const newHeuresComplémentaires = + newSituation[heuresComplémentairesDottedName]?.explanation.nodeValue + if (newHeuresComplémentaires !== previousHeuresComplémentaires) { + options.heuresComplémentaires = newHeuresComplémentaires || 0 + } + + return options + } + useEffect(() => { + const newOptions = getOptionsFromSituations( + previousSituation.current, + situation + ) + setData((previousData) => { + const updatedData = previousData.map((data) => { + return { + ...data, + options: { + ...data.options, + ...newOptions, + }, + } + }, []) + return reevaluateRéductionGénéraleMoisParMois( - previousData, + updatedData, engine, year, régularisationMethod ) }) + + previousSituation.current = situation }, [engine, situation, régularisationMethod, year]) const updateRémunérationBruteAnnuelle = (data: MonthState[]): void => {