-
+
('envActions')
const {
setFieldValue,
values: { envActions }
} = useFormikContext>()
- const envActionIndex = actionsFields.value.findIndex(envAction => envAction.id === String(currentActionIndex))
+ const envActionIndex = actionsFields.value.findIndex(envAction => envAction.id === currentActionId)
const currentAction = envActions[envActionIndex]
const handleRemoveAction = () => {
- setCurrentActionIndex(undefined)
- remove(currentActionIndex)
+ setCurrentActionId(undefined)
+ remove(currentActionId)
}
const duplicateNote = useCallback(() => {
diff --git a/frontend/src/features/missions/MissionForm/ActionForm/ReportingForm/index.tsx b/frontend/src/features/missions/MissionForm/ActionForm/ReportingForm/index.tsx
index 0132e0642..c0a28e419 100644
--- a/frontend/src/features/missions/MissionForm/ActionForm/ReportingForm/index.tsx
+++ b/frontend/src/features/missions/MissionForm/ActionForm/ReportingForm/index.tsx
@@ -24,10 +24,10 @@ const EMPTY_VALUE = '--'
export function ReportingForm({
reportingActionIndex,
- setCurrentActionIndex
+ setCurrentActionId: setCurrentActionIndex
}: {
reportingActionIndex: number
- setCurrentActionIndex: (string) => void
+ setCurrentActionId: (string) => void
}) {
const dispatch = useAppDispatch()
const { subThemes, themes } = useGetControlPlans()
@@ -169,7 +169,7 @@ export function ReportingForm({
/>
Le signalement nécessite un contrôle
-
+
>
diff --git a/frontend/src/features/missions/MissionForm/ActionForm/SurveillanceForm/index.tsx b/frontend/src/features/missions/MissionForm/ActionForm/SurveillanceForm/index.tsx
index d4e0d2316..583a32006 100644
--- a/frontend/src/features/missions/MissionForm/ActionForm/SurveillanceForm/index.tsx
+++ b/frontend/src/features/missions/MissionForm/ActionForm/SurveillanceForm/index.tsx
@@ -50,7 +50,7 @@ import {
} from '../style'
import { SurveillanceThemes } from '../Themes/SurveillanceThemes'
-export function SurveillanceForm({ currentActionIndex, remove, setCurrentActionIndex }) {
+export function SurveillanceForm({ currentActionId, remove, setCurrentActionId }) {
const { newWindowContainerRef } = useNewWindow()
const {
@@ -62,7 +62,7 @@ export function SurveillanceForm({ currentActionIndex, remove, setCurrentActionI
const { actionsMissingFields } = useMissionAndActionsCompletion()
const [actionsFields] = useField('envActions')
- const envActionIndex = actionsFields.value.findIndex(envAction => envAction.id === String(currentActionIndex))
+ const envActionIndex = actionsFields.value.findIndex(envAction => envAction.id === currentActionId)
const currentAction = envActions[envActionIndex]
const actionDate = envActions[envActionIndex]?.actionStartDateTimeUtc ?? startDateTimeUtc ?? new Date().toISOString()
@@ -146,7 +146,7 @@ export function SurveillanceForm({ currentActionIndex, remove, setCurrentActionI
)
const handleRemoveAction = () => {
- setCurrentActionIndex(undefined)
+ setCurrentActionId(undefined)
remove(envActionIndex)
}
@@ -173,16 +173,16 @@ export function SurveillanceForm({ currentActionIndex, remove, setCurrentActionI
}
useEffect(() => {
- if (actionsMissingFields[currentActionIndex] === 0 && currentAction?.completion === CompletionStatus.TO_COMPLETE) {
+ if (actionsMissingFields[currentActionId] === 0 && currentAction?.completion === CompletionStatus.TO_COMPLETE) {
setFieldValue(`envActions[${envActionIndex}].completion`, CompletionStatus.COMPLETED)
return
}
- if (actionsMissingFields[currentActionIndex] > 0 && currentAction?.completion === CompletionStatus.COMPLETED) {
+ if (actionsMissingFields[currentActionId] > 0 && currentAction?.completion === CompletionStatus.COMPLETED) {
setFieldValue(`envActions[${envActionIndex}].completion`, CompletionStatus.TO_COMPLETE)
}
- }, [actionsMissingFields, setFieldValue, currentActionIndex, currentAction?.completion, envActionIndex])
+ }, [actionsMissingFields, setFieldValue, currentActionId, currentAction?.completion, envActionIndex])
return (
<>
@@ -209,10 +209,7 @@ export function SurveillanceForm({ currentActionIndex, remove, setCurrentActionI
-
+
void
+ currentActionId: string | undefined
+ setCurrentActionId: (actionId: string | undefined) => void
}
-export function ActionForm({ currentActionIndex, setCurrentActionIndex }: ActionFormProps) {
+export function ActionForm({ currentActionId, setCurrentActionId }: ActionFormProps) {
const [attachedReportingsField] = useField('attachedReportings')
const reportingActionIndex = (attachedReportingsField.value ?? []).findIndex(
- reporting => String(reporting.id) === currentActionIndex
+ reporting => String(reporting.id) === currentActionId
)
const [reportingField] = useField(`attachedReportings.${reportingActionIndex}`)
const [envActionsField, , envActionsHelper] = useField('envActions')
- const envActionIndex = (envActionsField.value ?? []).findIndex(envAction => envAction.id === currentActionIndex)
+ const envActionIndex = (envActionsField.value ?? []).findIndex(envAction => envAction.id === currentActionId)
const [actionTypeField] = useField(`envActions.${envActionIndex}.actionType`)
const [actionIdField] = useField(`envActions.${envActionIndex}.id`)
@@ -31,10 +31,10 @@ export function ActionForm({ currentActionIndex, setCurrentActionIndex }: Action
actionsToUpdate.splice(envActionIndex, 1)
envActionsHelper.setValue(actionsToUpdate)
- setCurrentActionIndex(undefined)
- }, [envActionIndex, envActionsField, envActionsHelper, setCurrentActionIndex])
+ setCurrentActionId(undefined)
+ }, [envActionIndex, envActionsField, envActionsHelper, setCurrentActionId])
- if (currentActionIndex === undefined) {
+ if (currentActionId === undefined) {
return (
Ajouter ou sélectionner une action
@@ -47,7 +47,7 @@ export function ActionForm({ currentActionIndex, setCurrentActionIndex }: Action
)
@@ -60,9 +60,9 @@ export function ActionForm({ currentActionIndex, setCurrentActionIndex }: Action
)
@@ -71,9 +71,9 @@ export function ActionForm({ currentActionIndex, setCurrentActionIndex }: Action
)
@@ -82,9 +82,9 @@ export function ActionForm({ currentActionIndex, setCurrentActionIndex }: Action
)
diff --git a/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/ReportingCard.tsx b/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/ReportingCard.tsx
index 0259ba5f2..dd2cecdf8 100644
--- a/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/ReportingCard.tsx
+++ b/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/ReportingCard.tsx
@@ -20,10 +20,10 @@ import { Accented, ControlContainer, ReportingDate, SummaryContent, SummaryConte
export function ReportingCard({
action,
- setCurrentActionIndex
+ setCurrentActionId
}: {
action: ReportingForTimeline
- setCurrentActionIndex: (string) => void
+ setCurrentActionId: (actionId: string) => void
}) {
const { themes } = useGetControlPlans()
const { setFieldValue, values } = useFormikContext>()
@@ -103,7 +103,7 @@ export function ReportingCard({
})
setFieldValue('envActions', [newControl, ...(values?.envActions ?? [])])
- setCurrentActionIndex(newControl.id)
+ setCurrentActionId(newControl.id)
const reportingToUpdateIndex = values?.attachedReportings
? values?.attachedReportings?.findIndex(reporting => Number(reporting.id) === Number(action.id))
: -1
diff --git a/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/index.tsx b/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/index.tsx
index 6f5939a31..6816d2b1b 100644
--- a/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/index.tsx
+++ b/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/EnvActions/index.tsx
@@ -30,7 +30,7 @@ type EnvActionsProps = {
hasError: boolean
removeAction: MouseEventHandler
selected: boolean
- setCurrentActionIndex: (string) => void
+ setCurrentActionId: (id: string) => void
}
export function EnvActions({
@@ -39,7 +39,7 @@ export function EnvActions({
hasError,
removeAction,
selected,
- setCurrentActionIndex
+ setCurrentActionId
}: EnvActionsProps) {
return (
<>
@@ -53,7 +53,7 @@ export function EnvActions({
{action.actionType === ActionTypeEnum.SURVEILLANCE && }
{action.actionType === ActionTypeEnum.NOTE && }
{action.actionType === ActionTypeEnum.REPORTING && (
-
+
)}
{action.actionType !== ActionTypeEnum.REPORTING && (
<>
diff --git a/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/index.tsx b/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/index.tsx
index eb80ed01d..71a689469 100644
--- a/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/index.tsx
+++ b/frontend/src/features/missions/MissionForm/ActionsTimeLine/ActionCard/index.tsx
@@ -21,7 +21,7 @@ type ActionCardProps = {
removeAction: MouseEventHandler
selectAction: MouseEventHandler
selected: boolean
- setCurrentActionIndex: (string) => void
+ setCurrentActionId: (actionId: string) => void
}
export function ActionCard({
@@ -31,7 +31,7 @@ export function ActionCard({
removeAction,
selectAction,
selected,
- setCurrentActionIndex
+ setCurrentActionId
}: ActionCardProps) {
const onClickCard = id => {
if (action.actionSource !== ActionSource.MONITORENV) {
@@ -54,7 +54,7 @@ export function ActionCard({
hasError={hasError}
removeAction={removeAction}
selected={selected}
- setCurrentActionIndex={setCurrentActionIndex}
+ setCurrentActionId={setCurrentActionId}
/>
)}
{action.actionSource === ActionSource.MONITORFISH && }
diff --git a/frontend/src/features/missions/MissionForm/ActionsTimeLine/index.tsx b/frontend/src/features/missions/MissionForm/ActionsTimeLine/index.tsx
index cb6011c06..29df57ad0 100644
--- a/frontend/src/features/missions/MissionForm/ActionsTimeLine/index.tsx
+++ b/frontend/src/features/missions/MissionForm/ActionsTimeLine/index.tsx
@@ -19,7 +19,7 @@ import { FormTitle, Separator } from '../style'
import type { DetachedReporting, Reporting } from '../../../../domain/entities/reporting'
import type { FishMissionAction } from '../../fishActions.types'
-export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
+export function ActionsTimeLine({ currentActionId, setCurrentActionId }) {
const actionTimelineRef = useRef(null)
const actionTimelineHeight = Number(actionTimelineRef.current?.clientHeight) - 40 || undefined
const { errors, setFieldValue, values } = useFormikContext>()
@@ -71,11 +71,11 @@ export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
})
})
setFieldValue('envActions', [newSurveillance, ...(envActions || [])])
- setCurrentActionIndex(newSurveillance.id)
+ setCurrentActionId(newSurveillance.id)
}, [
envActions,
isFirstSurveillanceAction,
- setCurrentActionIndex,
+ setCurrentActionId,
setFieldValue,
values?.endDateTimeUtc,
values?.startDateTimeUtc
@@ -84,20 +84,20 @@ export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
const handleAddControlAction = useCallback(() => {
const newControl = actionFactory({ actionType: ActionTypeEnum.CONTROL })
setFieldValue('envActions', [newControl, ...(envActions || [])])
- setCurrentActionIndex(newControl.id)
- }, [envActions, setCurrentActionIndex, setFieldValue])
+ setCurrentActionId(newControl.id)
+ }, [envActions, setCurrentActionId, setFieldValue])
const handleAddNoteAction = useCallback(() => {
const newNote = actionFactory({ actionType: ActionTypeEnum.NOTE })
setFieldValue('envActions', [newNote, ...(envActions || [])])
- setCurrentActionIndex(newNote.id)
- }, [envActions, setCurrentActionIndex, setFieldValue])
+ setCurrentActionId(newNote.id)
+ }, [envActions, setCurrentActionId, setFieldValue])
const handleSelectAction = useCallback(
id => {
- setCurrentActionIndex(actions && Object.keys(actions).find(key => key === String(id)))
+ setCurrentActionId(actions && Object.keys(actions).find(key => key === String(id)))
},
- [actions, setCurrentActionIndex]
+ [actions, setCurrentActionId]
)
const handleRemoveAction = useCallback(
@@ -112,9 +112,9 @@ export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
actionsToUpdate.splice(actionToDeleteIndex, 1)
setFieldValue('envActions', actionsToUpdate)
}
- setCurrentActionIndex(undefined)
+ setCurrentActionId(undefined)
},
- [envActions, setCurrentActionIndex, setFieldValue]
+ [envActions, setCurrentActionId, setFieldValue]
)
const handleDuplicateAction = useCallback(
@@ -124,11 +124,10 @@ export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
if (envAction) {
const duplicatedAction = actionFactory(envAction)
setFieldValue('envActions', [duplicatedAction, ...(envActions || [])])
-
- setCurrentActionIndex(0)
+ setCurrentActionId(undefined)
}
},
- [envActions, setFieldValue, setCurrentActionIndex]
+ [envActions, setFieldValue, setCurrentActionId]
)
return (
@@ -161,7 +160,7 @@ export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
{sortedActions ? (
<>
- {sortedActions.map((action, index) => {
+ {sortedActions.map(action => {
const envActionsIndex = envActions?.findIndex(a => a.id === action.id)
const envActionsErrors =
errors?.envActions &&
@@ -171,15 +170,14 @@ export function ActionsTimeLine({ currentActionIndex, setCurrentActionIndex }) {
return (
handleDuplicateAction(action.id)}
hasError={!!envActionsErrors}
removeAction={() => handleRemoveAction(action.id)}
selectAction={() => handleSelectAction(action.id)}
- selected={String(action.id) === String(currentActionIndex)}
- setCurrentActionIndex={setCurrentActionIndex}
+ selected={String(action.id) === currentActionId}
+ setCurrentActionId={setCurrentActionId}
/>
)
})}
diff --git a/frontend/src/features/missions/MissionForm/MissionForm.tsx b/frontend/src/features/missions/MissionForm/MissionForm.tsx
index 3ac58afbf..ee846a3a1 100644
--- a/frontend/src/features/missions/MissionForm/MissionForm.tsx
+++ b/frontend/src/features/missions/MissionForm/MissionForm.tsx
@@ -55,13 +55,20 @@ enum ModalTypes {
type ModalProps = ModalTypes.ACTIONS | ModalTypes.DELETE
type MissionFormProps = {
+ activeActionId: string | undefined
engagedControlUnit: ControlUnit.EngagedControlUnit | undefined
id: number | string
isNewMission: boolean
selectedMission: AtLeast, 'id'> | Partial | undefined
}
-export function MissionForm({ engagedControlUnit, id, isNewMission, selectedMission }: MissionFormProps) {
+export function MissionForm({
+ activeActionId,
+ engagedControlUnit,
+ id,
+ isNewMission,
+ selectedMission
+}: MissionFormProps) {
const dispatch = useAppDispatch()
const sideWindow = useAppSelector(state => state.sideWindow)
@@ -97,7 +104,6 @@ export function MissionForm({ engagedControlUnit, id, isNewMission, selectedMiss
useUpdateSurveillance()
useUpdateOtherControlTypes()
- const [currentActionIndex, setCurrentActionIndex] = useState(undefined)
const [openModal, setOpenModal] = useState(undefined)
const [actionsSources, setActionsSources] = useState([])
@@ -112,8 +118,8 @@ export function MissionForm({ engagedControlUnit, id, isNewMission, selectedMiss
}
}, [attachedReportingIds, values?.attachedReportingIds?.length, setFieldValue, attachedReportings])
- const handleSetCurrentActionIndex = index => {
- setCurrentActionIndex(index)
+ const handleSetCurrentActionId = (actionId: string | undefined) => {
+ dispatch(missionFormsActions.setActiveActionId(actionId))
}
const returnToEdition = () => {
@@ -258,13 +264,10 @@ export function MissionForm({ engagedControlUnit, id, isNewMission, selectedMiss
-
+
-
+
diff --git a/frontend/src/features/missions/MissionForm/hooks/useSyncFormValuesWithRedux.ts b/frontend/src/features/missions/MissionForm/hooks/useSyncFormValuesWithRedux.ts
index a90693e2f..d69b4b8ed 100644
--- a/frontend/src/features/missions/MissionForm/hooks/useSyncFormValuesWithRedux.ts
+++ b/frontend/src/features/missions/MissionForm/hooks/useSyncFormValuesWithRedux.ts
@@ -1,13 +1,13 @@
+import { useAppDispatch } from '@hooks/useAppDispatch'
+import { useAppSelector } from '@hooks/useAppSelector'
import { useFormikContext } from 'formik'
import { useEffect } from 'react'
import { useDebouncedCallback } from 'use-debounce'
-import { useAppDispatch } from '../../../../hooks/useAppDispatch'
-import { useAppSelector } from '../../../../hooks/useAppSelector'
import { missionFormsActions } from '../slice'
import { getIsMissionFormValid } from '../utils'
-import type { Mission } from '../../../../domain/entities/missions'
+import type { Mission } from 'domain/entities/missions'
export function useSyncFormValuesWithRedux(isAutoSaveEnabled: boolean) {
const dispatch = useAppDispatch()
@@ -19,6 +19,9 @@ export function useSyncFormValuesWithRedux(isAutoSaveEnabled: boolean) {
const engagedControlUnit = useAppSelector(state =>
activeMissionId ? state.missionForms.missions[activeMissionId]?.engagedControlUnit : undefined
)
+ const activeActionId = useAppSelector(state =>
+ activeMissionId ? state.missionForms.missions[activeMissionId]?.activeActionId : undefined
+ )
const dispatchFormUpdate = useDebouncedCallback(async (newValues: Mission) => {
if (!newValues || newValues.id !== activeMissionId) {
@@ -27,7 +30,9 @@ export function useSyncFormValuesWithRedux(isAutoSaveEnabled: boolean) {
const isFormDirty = isMissionFormDirty()
- dispatch(missionFormsActions.setMission({ engagedControlUnit, isFormDirty, missionForm: newValues }))
+ dispatch(
+ missionFormsActions.setMission({ activeActionId, engagedControlUnit, isFormDirty, missionForm: newValues })
+ )
}, 350)
/**
diff --git a/frontend/src/features/missions/MissionForm/index.tsx b/frontend/src/features/missions/MissionForm/index.tsx
index d9c52701a..5c6a6748f 100644
--- a/frontend/src/features/missions/MissionForm/index.tsx
+++ b/frontend/src/features/missions/MissionForm/index.tsx
@@ -14,6 +14,7 @@ import type { Mission as MissionType, NewMission } from '../../../domain/entitie
export function MissionFormWrapper() {
const activeMissionId = useAppSelector(state => state.missionForms.activeMissionId)
+
const selectedMission = useAppSelector(state =>
activeMissionId ? state.missionForms.missions[activeMissionId] : undefined
)
@@ -21,6 +22,10 @@ export function MissionFormWrapper() {
activeMissionId ? state.missionForms.missions[activeMissionId]?.engagedControlUnit : undefined
)
+ const activeActionId = useAppSelector(state =>
+ activeMissionId ? state.missionForms.missions[activeMissionId]?.activeActionId : undefined
+ )
+
const missionIsNewMission = useMemo(() => isNewMission(activeMissionId), [activeMissionId])
const missionValues: Partial = useMemo(() => {
@@ -69,6 +74,7 @@ export function MissionFormWrapper() {
>
+ }
+ onItemRemove={removeTab}
+ onSelect={selectTab}
+ removable
+ >
+ {tabs.map((item, index) => (
+
+ {item.label}
+
+ ))}
+
)
}
@@ -95,6 +88,7 @@ const StyledResponsiveNav = styled(ResponsiveNav)`
display: flex;
box-shadow: 0px 3px 4px #7077854d;
height: 48px;
+ width: 100%;
> .rs-nav-item {
width: 360px;