From f03350869c815a36f8fb60ed6adfd63320d7d9fa Mon Sep 17 00:00:00 2001 From: Claire Dagan Date: Tue, 16 Jul 2024 16:45:11 +0200 Subject: [PATCH] [VigilanceArea] open confirm modal when vigilance area form is open an user want to create new one --- .../components/VigilanceAreaForm/index.tsx | 7 ++++++- frontend/src/features/VigilanceArea/slice.ts | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/frontend/src/features/VigilanceArea/components/VigilanceAreaForm/index.tsx b/frontend/src/features/VigilanceArea/components/VigilanceAreaForm/index.tsx index f8be3992d..e78d85c61 100644 --- a/frontend/src/features/VigilanceArea/components/VigilanceAreaForm/index.tsx +++ b/frontend/src/features/VigilanceArea/components/VigilanceAreaForm/index.tsx @@ -57,10 +57,15 @@ export function VigilanceAreaForm({ isOpen, isReadOnly = false, vigilanceAreaId useEffect(() => { if (editingVigilanceAreaId && vigilanceArea && vigilanceArea.id === editingVigilanceAreaId) { - dispatch(vigilanceAreaActions.addRegulatoryAreasToVigilanceArea(vigilanceArea?.linkedRegulatoryAreas ?? [])) + dispatch(vigilanceAreaActions.addRegulatoryAreasToVigilanceArea(vigilanceArea?.linkedRegulatoryAreas)) dispatch(vigilanceAreaActions.addAMPsToVigilanceArea(vigilanceArea?.linkedAMPs)) dispatch(vigilanceAreaActions.setGeometry(vigilanceArea?.geom)) } + if (editingVigilanceAreaId === NEW_VIGILANCE_AREA_ID) { + dispatch(vigilanceAreaActions.addRegulatoryAreasToVigilanceArea([])) + dispatch(vigilanceAreaActions.addAMPsToVigilanceArea([])) + dispatch(vigilanceAreaActions.setGeometry(undefined)) + } // we just want to listen when editingVigilanceAreaId changes // eslint-disable-next-line react-hooks/exhaustive-deps }, [editingVigilanceAreaId]) diff --git a/frontend/src/features/VigilanceArea/slice.ts b/frontend/src/features/VigilanceArea/slice.ts index bb0e57001..ff963ee95 100644 --- a/frontend/src/features/VigilanceArea/slice.ts +++ b/frontend/src/features/VigilanceArea/slice.ts @@ -110,15 +110,24 @@ export const vigilanceAreaSlice = createSlice({ } state.editingVigilanceAreaId = state.vigilanceAreaIdToCancel + state.selectedVigilanceAreaId = state.vigilanceAreaIdToCancel state.vigilanceAreaIdToCancel = undefined state.isCancelModalOpen = false }, createVigilanceArea(state) { - state.selectedVigilanceAreaId = NEW_VIGILANCE_AREA_ID - state.editingVigilanceAreaId = NEW_VIGILANCE_AREA_ID - state.formTypeOpen = VigilanceAreaFormTypeOpen.FORM - state.isGeometryValid = false - state.geometry = undefined + if (!state.editingVigilanceAreaId) { + return { + ...INITIAL_STATE, + editingVigilanceAreaId: NEW_VIGILANCE_AREA_ID, + selectedVigilanceAreaId: NEW_VIGILANCE_AREA_ID + } + } + + return { + ...state, + isCancelModalOpen: true, + vigilanceAreaIdToCancel: NEW_VIGILANCE_AREA_ID + } }, deleteAMPsFromVigilanceArea(state, action: PayloadAction) { state.ampToAdd = state.ampToAdd.filter(id => id !== action.payload)