diff --git a/frontend/src/domain/shared_slices/Vessel.ts b/frontend/src/domain/shared_slices/Vessel.ts index 4dc6a7a740..9cca184842 100644 --- a/frontend/src/domain/shared_slices/Vessel.ts +++ b/frontend/src/domain/shared_slices/Vessel.ts @@ -134,7 +134,10 @@ const vesselSlice = createSlice({ } }) - if (Vessel.getVesselFeatureId(state.selectedVesselIdentity) === action.payload.vesselFeatureId) { + if ( + state.selectedVesselIdentity && + Vessel.getVesselFeatureId(state.selectedVesselIdentity) === action.payload.vesselFeatureId + ) { let reportings: ReportingType[] = [] if (state.selectedVessel?.reportings?.length) { diff --git a/frontend/src/features/Reporting/components/ReportingForm/index.tsx b/frontend/src/features/Reporting/components/ReportingForm/index.tsx index 0626ba8902..b339fc6f32 100644 --- a/frontend/src/features/Reporting/components/ReportingForm/index.tsx +++ b/frontend/src/features/Reporting/components/ReportingForm/index.tsx @@ -8,9 +8,9 @@ import { } from '@features/Reporting/components/ReportingForm/utils' import { useMainAppDispatch } from '@hooks/useMainAppDispatch' import { useMainAppSelector } from '@hooks/useMainAppSelector' -import { Accent, Button, FormikSelect, FormikTextarea, FormikTextInput, Legend, Fieldset } from '@mtes-mct/monitor-ui' +import { Accent, Button, Fieldset, FormikSelect, FormikTextarea, FormikTextInput, Legend } from '@mtes-mct/monitor-ui' import { Form, Formik } from 'formik' -import { useCallback, useMemo, useRef } from 'react' +import { useCallback, useMemo } from 'react' import { Radio, RadioGroup } from 'rsuite' import styled from 'styled-components' @@ -25,7 +25,6 @@ import { mapControlUnitsToUniqueSortedIdsAsOptions } from '../VesselReportings/C import type { VesselIdentity } from '../../../../domain/entities/vessel/types' import type { EditableReporting, EditedReporting } from '../../../../domain/types/reporting' import type { Option } from '@mtes-mct/monitor-ui' -import type { MutableRefObject } from 'react' type ReportingFormProps = { closeForm: () => void @@ -44,7 +43,6 @@ export function ReportingForm({ const dispatch = useMainAppDispatch() const infractions = useMainAppSelector(state => state.infraction.infractions) const controlUnitsQuery = useGetLegacyControlUnitsQuery(undefined) - const previousReportingType = useRef() as MutableRefObject const infractionsAsOptions = useMemo( () => @@ -75,7 +73,7 @@ export function ReportingForm({ getOnlyVesselIdentityProperties(editedReporting), editedReporting.id, nextReportingValue, - previousReportingType.current + editedReporting.type ) ).then(() => { closeForm() diff --git a/frontend/src/features/Reporting/useCases/updateReporting.ts b/frontend/src/features/Reporting/useCases/updateReporting.ts index 993abb83e5..6d90028ff7 100644 --- a/frontend/src/features/Reporting/useCases/updateReporting.ts +++ b/frontend/src/features/Reporting/useCases/updateReporting.ts @@ -34,7 +34,7 @@ export const updateReporting = nextReporting.type === ReportingType.OBSERVATION && previousReportingType === ReportingType.INFRACTION_SUSPICION ) { - dispatch(removeCurrentReporting(updatedReporting.id)) + dispatch(removeCurrentReporting(id)) } // We update the reportings of the last positions vessels state