From 75f791819a7f8296d75d561d765516fdddc7c0c6 Mon Sep 17 00:00:00 2001 From: aleckvincent Date: Wed, 4 Dec 2024 17:12:50 +0100 Subject: [PATCH] add isOpenDialog state --- .../use-mission-general-informations-form.tsx | 2 +- .../element/mission-create-dialog.tsx | 57 ++++++++++++------- ...ssion-general-information-initial-form.tsx | 54 ++++++++++++++---- ...sion-general-information-ulam-form-new.tsx | 10 +++- 4 files changed, 88 insertions(+), 35 deletions(-) diff --git a/frontend/src/v2/features/common/hooks/use-mission-general-informations-form.tsx b/frontend/src/v2/features/common/hooks/use-mission-general-informations-form.tsx index 5062d74b..4bcd65c6 100644 --- a/frontend/src/v2/features/common/hooks/use-mission-general-informations-form.tsx +++ b/frontend/src/v2/features/common/hooks/use-mission-general-informations-form.tsx @@ -23,7 +23,7 @@ export function useMissionGeneralInformationsForm( const fromInputToFieldValue = (value: MissionULAMGeneralInfoInitialInput): MissionULAMGeneralInfoInitial => { - const { dates, missionReportType, missionType, reinforcementType } = value + const { dates, missionReportType, missionType, reinforcementType, nbHourAtSea } = value return { startDateTimeUtc: postprocessDateFromPicker(dates[0]), endDateTimeUtc: postprocessDateFromPicker(dates[1]), diff --git a/frontend/src/v2/features/ulam/components/element/mission-create-dialog.tsx b/frontend/src/v2/features/ulam/components/element/mission-create-dialog.tsx index 9a607650..021f5ce9 100644 --- a/frontend/src/v2/features/ulam/components/element/mission-create-dialog.tsx +++ b/frontend/src/v2/features/ulam/components/element/mission-create-dialog.tsx @@ -1,28 +1,45 @@ -import React, { FC } from 'react' -import { Dialog, Button, THEME, Accent } from '@mtes-mct/monitor-ui' +import React, { FC, useEffect, useState } from 'react' +import { Dialog, THEME } from '@mtes-mct/monitor-ui' import { Stack } from 'rsuite' import { MissionTypeEnum } from '@common/types/env-mission-types.ts' import MissionGeneralInformationUlamFormNew from './mission-general-information-ulam-form-new.tsx' -const MissionCreateDialog: FC = () => { +interface MissionCreateDialogProps { + isOpen: boolean + onClose: () => void +} + +const MissionCreateDialog: FC = ({isOpen, onClose}) => { + + const [isDialogOpen, setIsDialogOpen] = useState(isOpen) + + useEffect(() => { + setIsDialogOpen(isOpen) + }, [isOpen]) + + + const handleClose = () => { + setIsDialogOpen(false) + onClose() + } + + return ( - - Création d'un rapport de mission - - - - - - - - - - - + isDialogOpen && ( + + Création d'un rapport de mission + + + + + + + ) ) } diff --git a/frontend/src/v2/features/ulam/components/element/mission-general-information-initial-form.tsx b/frontend/src/v2/features/ulam/components/element/mission-general-information-initial-form.tsx index b06cb16e..d4f8ed18 100644 --- a/frontend/src/v2/features/ulam/components/element/mission-general-information-initial-form.tsx +++ b/frontend/src/v2/features/ulam/components/element/mission-general-information-initial-form.tsx @@ -1,14 +1,19 @@ import React, { FC } from 'react' -import { Stack } from 'rsuite' +import { FlexboxGrid, Stack } from 'rsuite' import { + Accent, + Button, FormikDateRangePicker, FormikMultiCheckbox, - FormikSelect, + FormikNumberInput, + FormikSelect } from '@mtes-mct/monitor-ui' import { MISSION_TYPE_OPTIONS, MissionReportTypeEnum, - MissionULAMGeneralInfoInitial, REINFORCEMENT_TYPE, REPORT_TYPE_OPTIONS + MissionULAMGeneralInfoInitial, + REINFORCEMENT_TYPE, + REPORT_TYPE_OPTIONS } from '@common/types/mission-types.ts' import { useMissionGeneralInformationsForm } from '../../../common/hooks/use-mission-general-informations-form.tsx' import { FieldProps, Formik } from 'formik' @@ -16,20 +21,24 @@ import { FieldProps, Formik } from 'formik' export interface MissionGeneralInformationInitialFormProps { name: string fieldFormik: FieldProps + isCreation?: boolean + onClose?: () => void } -const MissionGeneralInformationInitialForm: FC = ({ name, fieldFormik }) => { +const MissionGeneralInformationInitialForm: FC = ({ name, fieldFormik, isCreation = false, onClose }) => { const { initValue, handleSubmit } = useMissionGeneralInformationsForm(name, fieldFormik) + + return ( <> {initValue && ( {formik => ( - + - {formik.values['reportType'] === MissionReportTypeEnum.EXTERNAL_REINFORCEMENT_TIME_REPORT && ( + {formik.values['missionReportType'] === MissionReportTypeEnum.EXTERNAL_REINFORCEMENT_TIME_REPORT && ( - + + + + + + {!isCreation && ( + + + + )} + + + + {isCreation && ( + + + + + + )} )} diff --git a/frontend/src/v2/features/ulam/components/element/mission-general-information-ulam-form-new.tsx b/frontend/src/v2/features/ulam/components/element/mission-general-information-ulam-form-new.tsx index e916c71b..815e8baf 100644 --- a/frontend/src/v2/features/ulam/components/element/mission-general-information-ulam-form-new.tsx +++ b/frontend/src/v2/features/ulam/components/element/mission-general-information-ulam-form-new.tsx @@ -2,11 +2,12 @@ import React from 'react' import { MissionTypeEnum } from '@common/types/env-mission-types.ts' import { MissionReinforcementTypeEnum, - MissionReportTypeEnum, MissionULAMGeneralInfoInitial + MissionReportTypeEnum, + MissionULAMGeneralInfoInitial } from '@common/types/mission-types.ts' import { Field, FieldProps, Formik } from 'formik' import MissionGeneralInformationInitialForm from './mission-general-information-initial-form.tsx' -import { FormikEffect } from '@mtes-mct/monitor-ui' +import { Accent, Button, Dialog, FormikEffect, THEME } from '@mtes-mct/monitor-ui' type NewMissionUlamGeneralInfoInitial = { missionGeneralInfo: MissionULAMGeneralInfoInitial } @@ -17,9 +18,10 @@ export interface MissionGeneralInformationUlamProps { missionReportType?: MissionReportTypeEnum reinforcementType?: MissionReinforcementTypeEnum nbHourAtSea?: number + onClose?: () => void } -const MissionGeneralInformationUlamFormNew: React.FC = ({ startDateTimeUtc, endDateTimeUtc, missionType, missionReportType, reinforcementType, nbHourAtSea }) => { +const MissionGeneralInformationUlamFormNew: React.FC = ({ startDateTimeUtc, endDateTimeUtc, missionType, missionReportType, reinforcementType, nbHourAtSea, onClose }) => { const initialValues: MissionULAMGeneralInfoInitial = { missionGeneralInfo : { @@ -50,6 +52,8 @@ const MissionGeneralInformationUlamFormNew: React.FC )}