Skip to content

Commit

Permalink
[Mission] Delete setFieldValue in useEffect - Awareness component
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Jan 23, 2025
1 parent 5379dc4 commit 9429065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormikCheckbox, FormikNumberInput, FormikSelect, Label } from '@mtes-mct/monitor-ui'
import { Checkbox, FormikNumberInput, FormikSelect, Label } from '@mtes-mct/monitor-ui'
import { useField, useFormikContext } from 'formik'
import { useEffect } from 'react'
import styled from 'styled-components'
Expand All @@ -22,21 +22,28 @@ export function Awareness({ awarenessOptions, formPath }: AwarenessProps) {
if (controlPlans.value.length === 1 && isRisingAwareness) {
setFieldValue(`${formPath}.awareness.themeId`, controlPlans.value[0]?.themeId)
}
if (!isRisingAwareness) {
}, [controlPlans.value, formPath, isRisingAwareness, setFieldValue])

const updateIsRisingAwareness = (isChecked: boolean | undefined) => {
if (isChecked) {
setFieldValue(`${formPath}.awareness`, { isRisingAwareness: true })
} else {
setFieldValue(`${formPath}.awareness`, undefined)
}
}, [controlPlans.value, formPath, isRisingAwareness, setFieldValue])
}

return (
<>
<div>
<Label>Prévention</Label>
<FormikCheckbox
<Checkbox
checked={isRisingAwareness}
data-cy="surveillance-awareness"
inline
isLight
label="La surveillance a donné lieu à des actions de prévention"
name={`${formPath}.awareness.isRisingAwareness`}
onChange={updateIsRisingAwareness}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES = [
// `envActions` is included but `reportingIds` is missing
'envActions',
'fishActions',
'hasRapportNavActions'
'hasRapportNavActions',
'observationsByUnit'
]

export const MISSION_EVENT_UNSYNCHRONIZED_PROPERTIES_IN_FORM = [
Expand Down

0 comments on commit 9429065

Please sign in to comment.