Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mission status): fix for rescue form #140

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -6,13 +6,14 @@
CoordinatesInput,
DateRangePicker,
Icon,
Label,

Check warning on line 9 in frontend/src/pam/mission/actions/action-rescue-form.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-frontend

'Label' is defined but never used

Check warning on line 9 in frontend/src/pam/mission/actions/action-rescue-form.tsx

View workflow job for this annotation

GitHub Actions / build-and-test-frontend

'Label' is defined but never used
MultiRadio,
NumberInput,
Textarea,
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 @@
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 @@
/>
</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 @@

{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 @@
/>
</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
Loading