-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mission] Ajout de boutons pour conserver ou non une mission si l'uni…
…té sélectionnée est déjà engagée (#2945) ## Linked issues - Resolve #2925 ---- - [x] Tests E2E (Cypress)
- Loading branch information
Showing
15 changed files
with
250 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
frontend/src/domain/use_cases/mission/cancelCreateAndRedirectToFilteredList.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { missionFormActions } from '@features/Mission/components/MissionForm/slice' | ||
import { missionListActions } from '@features/Mission/components/MissionList/slice' | ||
import { monitorenvMissionApi } from '@features/Mission/monitorenvMissionApi' | ||
import { MissionDateRangeFilter, MissionFilterType } from '@features/SideWindow/MissionList/types' | ||
import { openSideWindowPath } from '@features/SideWindow/useCases/openSideWindowPath' | ||
import { customDayjs, logSoftError } from '@mtes-mct/monitor-ui' | ||
import { Mission } from 'domain/entities/mission/types' | ||
import { SideWindowMenuKey } from 'domain/entities/sideWindow/constants' | ||
|
||
export const cancelCreateAndRedirectToFilteredList = | ||
({ controlUnitName, missionId }: { controlUnitName: string; missionId: number | undefined }) => | ||
async dispatch => { | ||
dispatch(missionFormActions.setEngagedControlUnit(undefined)) | ||
|
||
// update filters to redirect to list with only pending mission with the control unit selected | ||
dispatch(missionListActions.setListFilterValues({})) | ||
|
||
const twoMonthsAgo = customDayjs().subtract(2, 'month').toISOString() | ||
dispatch( | ||
missionListActions.setListFilterValues({ | ||
[MissionFilterType.UNIT]: [controlUnitName], | ||
[MissionFilterType.STATUS]: [Mission.MissionStatus.IN_PROGRESS], | ||
[MissionFilterType.DATE_RANGE]: MissionDateRangeFilter.CUSTOM, | ||
[MissionFilterType.CUSTOM_DATE_RANGE]: [twoMonthsAgo, customDayjs().toISOString()] | ||
}) | ||
) | ||
|
||
await dispatch(openSideWindowPath({ menu: SideWindowMenuKey.MISSION_LIST }, true)) | ||
|
||
if (missionId) { | ||
try { | ||
const response = await dispatch(monitorenvMissionApi.endpoints.deleteMission.initiate(missionId)) | ||
if ('error' in response) { | ||
throw Error('Erreur à la suppression de la mission') | ||
} | ||
} catch (error) { | ||
logSoftError({ | ||
isSideWindowError: true, | ||
message: '`delete()` failed.', | ||
originalError: error, | ||
userMessage: 'Une erreur est survenue pendant la suppression de la mission.' | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...omponents/MissionForm/MainForm/FormikMultiControlUnitPicker/ControlUnitWarningMessage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { useMainAppDispatch } from '@hooks/useMainAppDispatch' | ||
import { useMainAppSelector } from '@hooks/useMainAppSelector' | ||
import { Accent, Button, Level, Message } from '@mtes-mct/monitor-ui' | ||
import { Mission } from 'domain/entities/mission/types' | ||
import { cancelCreateAndRedirectToFilteredList } from 'domain/use_cases/mission/cancelCreateAndRedirectToFilteredList' | ||
import { useField } from 'formik' | ||
import { useMemo } from 'react' | ||
import styled from 'styled-components' | ||
|
||
import { missionFormActions } from '../../slice' | ||
|
||
export function ControlUnitWarningMessage({ | ||
controlUnitIndex, | ||
missionId | ||
}: { | ||
controlUnitIndex: number | ||
missionId: number | undefined | ||
}) { | ||
const dispatch = useMainAppDispatch() | ||
|
||
const [unitField] = useField<number | undefined>(`controlUnits.${controlUnitIndex}.id`) | ||
|
||
const engagedControlUnit = useMainAppSelector(state => state.missionForm.engagedControlUnit) | ||
|
||
const message = useMemo(() => { | ||
if (!engagedControlUnit) { | ||
return '' | ||
} | ||
|
||
if (engagedControlUnit.missionSources.length === 1) { | ||
const source = engagedControlUnit.missionSources[0] | ||
if (!source) { | ||
return '' | ||
} | ||
|
||
return `Une autre mission, ouverte par le ${Mission.MissionSourceLabel[source]}, est en cours avec cette unité.` | ||
} | ||
|
||
if (engagedControlUnit.missionSources.length > 1) { | ||
return `D'autres missions en cours, ouvertes par le ${engagedControlUnit.missionSources | ||
.map(source => Mission.MissionSourceLabel[source]) | ||
.join(' et le ')}, sont en cours avec cette unité.` | ||
} | ||
|
||
return '' | ||
}, [engagedControlUnit]) | ||
|
||
const validate = async () => { | ||
dispatch(missionFormActions.setEngagedControlUnit(undefined)) | ||
} | ||
|
||
const cancel = async () => { | ||
const controlUnitName = engagedControlUnit?.controlUnit?.name | ||
if (controlUnitName) { | ||
dispatch(cancelCreateAndRedirectToFilteredList({ controlUnitName, missionId })) | ||
} | ||
} | ||
|
||
if (!engagedControlUnit || engagedControlUnit?.controlUnit.id !== unitField.value) { | ||
return null | ||
} | ||
|
||
return ( | ||
<StyledMessage level={Level.WARNING}> | ||
<Warning>Attention</Warning> | ||
<div> | ||
<span>{message}</span> | ||
<br /> | ||
<span>Voulez-vous quand même conserver cette mission ?</span> | ||
</div> | ||
|
||
<ButtonsContainer> | ||
<Button accent={Accent.WARNING} onClick={validate}> | ||
Oui, la conserver | ||
</Button> | ||
<Button accent={Accent.WARNING} onClick={cancel}> | ||
Non, l'abandonner | ||
</Button> | ||
</ButtonsContainer> | ||
</StyledMessage> | ||
) | ||
} | ||
|
||
const StyledMessage = styled(Message)` | ||
margin-top: 8px; | ||
` | ||
const Warning = styled.p` | ||
color: ${({ theme }) => theme.color.goldenPoppy}; | ||
font-weight: bold; | ||
` | ||
const ButtonsContainer = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
margin-top: 16px; | ||
` |
Oops, something went wrong.