Skip to content

Commit

Permalink
Merge pull request #140 from MTES-MCT/events-fixes2
Browse files Browse the repository at this point in the history
fix(mission status): fix for rescue form
  • Loading branch information
lwih authored Apr 30, 2024
2 parents 924b7c2 + f06e71f commit b9f5cd1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 56 deletions.
84 changes: 43 additions & 41 deletions frontend/src/pam/mission/actions/action-rescue-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
TextInput,
THEME
} from '@mtes-mct/monitor-ui'
import Text from '../../../ui/text'
import { Action, ActionRescue } from '../../../types/action-types'
import { Divider, Stack, Toggle } from 'rsuite'
import { useNavigate, useParams } from 'react-router-dom'
Expand Down Expand Up @@ -98,6 +99,12 @@ const ActionRescueForm: React.FC<ActionRescueFormProps> = ({ action }) => {
isVesselRescue: !value,
isPersonRescue: value
}
} else if (field === 'isMigrationRescue' && value === false) {
updatedField = {
[field]: value,
nbAssistedVesselsReturningToShore: undefined,
nbOfVesselsTrackedWithoutIntervention: undefined
}
} else {
updatedField = {
[field]: value
Expand Down Expand Up @@ -233,9 +240,9 @@ const ActionRescueForm: React.FC<ActionRescueFormProps> = ({ action }) => {
/>
</Stack.Item>
<Stack.Item alignSelf="flex-end">
<Label style={{ marginBottom: 0 }}>
<b>Opération suivie (DEFREP)</b>
</Label>
<Text as={'h3'} weight={'medium'}>
Opération suivie (DEFREP)
</Text>
</Stack.Item>
</Stack>
</Stack.Item>
Expand Down Expand Up @@ -346,12 +353,11 @@ const ActionRescueForm: React.FC<ActionRescueFormProps> = ({ action }) => {

{showPersonStack && (
<>
<Stack>
<Stack direction={'column'} spacing={'1rem'} alignItems={'flex-start'}>
<Stack.Item style={{ width: '100%' }}>
<Divider style={{ backgroundColor: THEME.color.charcoal }} />
</Stack.Item>
</Stack>
<Stack style={{ marginBottom: 15 }}>

<Stack.Item style={{ width: '100%' }}>
<Stack direction="row" alignItems="center" spacing={'0.5rem'}>
<Stack.Item>
Expand All @@ -363,47 +369,43 @@ const ActionRescueForm: React.FC<ActionRescueFormProps> = ({ action }) => {
/>
</Stack.Item>
<Stack.Item alignSelf="flex-end">
<Label style={{ marginBottom: 0 }}>
<b>Sauvetage dans le cadre d'un phénomène migratoire</b>
</Label>
<Text as={'h3'} weight={'medium'}>
Sauvetage dans le cadre d'un phénomène migratoire
</Text>
</Stack.Item>
</Stack>
</Stack.Item>

<Stack.Item style={{ width: '50%', maxWidth: '50%' }}>
<NumberInput
label="Nb d'embarcations suivies sans nécessité d'intervention"
name="nbOfVesselsTrackedWithoutIntervention"
placeholder="0"
isLight={true}
value={actionData?.nbOfVesselsTrackedWithoutIntervention}
onChange={async nextValue => {
await onChange('nbOfVesselsTrackedWithoutIntervention', nextValue)
}}
disabled={!actionData?.isMigrationRescue}
/>
</Stack.Item>

<Stack.Item style={{ width: '50%', maxWidth: '50%' }}>
<NumberInput
label="Nb d'embarcations assistées pour un retour à terre"
name="nbAssistedVesselsReturningToShore"
placeholder="0"
isLight={true}
value={actionData?.nbAssistedVesselsReturningToShore}
onChange={async nextValue => {
await onChange('nbAssistedVesselsReturningToShore', nextValue)
}}
disabled={!actionData?.isMigrationRescue}
/>
</Stack.Item>
</Stack>
</>
)}

{showPersonStack && (
<Stack>
<Stack.Item>
<NumberInput
label="Nb d'embarcations suivies sans nécessité d'intervention"
name="nbOfVesselsTrackedWithoutIntervention"
placeholder="0"
style={{ marginRight: '8px' }}
isLight={true}
value={actionData?.nbOfVesselsTrackedWithoutIntervention}
onChange={async nextValue => {
await onChange('nbOfVesselsTrackedWithoutIntervention', nextValue)
}}
disabled={!actionData?.isMigrationRescue}
/>
</Stack.Item>
<Stack.Item>
<NumberInput
label="Nb d'embarcations assistées pour un retour à terre"
name="nbAssistedVesselsReturningToShore"
placeholder="0"
isLight={true}
value={actionData?.nbAssistedVesselsReturningToShore}
onChange={async nextValue => {
await onChange('nbAssistedVesselsReturningToShore', nextValue)
}}
disabled={!actionData?.isMigrationRescue}
/>
</Stack.Item>
</Stack>
)}
</form>
)
}
Expand Down
39 changes: 24 additions & 15 deletions frontend/src/pam/mission/rescues/use-add-update-rescue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@ import { GET_ACTION_BY_ID } from '../actions/use-action-by-id.tsx'

export const MUTATION_ADD_UPDATE_ACTION_RESCUE = gql`
mutation AddOrUpdateRescue($rescueAction: ActionRescueInput!) {
addOrUpdateActionRescue(rescueAction: $rescueAction) {
id
startDateTimeUtc
endDateTimeUtc
isVesselRescue
isPersonRescue
locationDescription
observations
}
}`
addOrUpdateActionRescue(rescueAction: $rescueAction) {
id
startDateTimeUtc
endDateTimeUtc
isVesselRescue
isPersonRescue
locationDescription
observations
longitude
latitude
isVesselNoticed
isVesselTowed
isInSRRorFollowedByCROSSMRCC
numberPersonsRescued
numberOfDeaths
operationFollowsDEFREP
isMigrationRescue
nbAssistedVesselsReturningToShore
nbOfVesselsTrackedWithoutIntervention
}
}
`

const useAddOrUpdateRescue = (): MutationTuple<ActionRescue, Record<string, any>> => {
const {missionId} = useParams()
const { missionId } = useParams()
const mutation = useMutation(MUTATION_ADD_UPDATE_ACTION_RESCUE, {
refetchQueries: [
{query: GET_MISSION_TIMELINE, variables: {missionId}},
GET_ACTION_BY_ID
]
refetchQueries: [{ query: GET_MISSION_TIMELINE, variables: { missionId } }, GET_ACTION_BY_ID]
})

return mutation
Expand Down

0 comments on commit b9f5cd1

Please sign in to comment.