Skip to content

Commit

Permalink
[VigilanceArea] open confirm modal when vigilance area form is open a…
Browse files Browse the repository at this point in the history
…n user want to create new one
  • Loading branch information
claire2212 committed Jul 16, 2024
1 parent e98813c commit f033508
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/features/VigilanceArea/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>) {
state.ampToAdd = state.ampToAdd.filter(id => id !== action.payload)
Expand Down

0 comments on commit f033508

Please sign in to comment.