feat: met à jour la rémunération totale lors de la modification mois par mois

pull/3197/head
Alice Dahan 2024-10-15 16:49:01 +02:00 committed by liliced
parent 4b6d5796d3
commit e67ced3d97
1 changed files with 24 additions and 1 deletions

View File

@ -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<MonthState[]>([])
@ -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<DottedName, SimpleRuleEvaluation>)
)
}
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
})
}