diff --git a/front/src/app/components/forms/commons/AgencySelector.tsx b/front/src/app/components/forms/commons/AgencySelector.tsx index ea904027cd..c784b9e1f9 100644 --- a/front/src/app/components/forms/commons/AgencySelector.tsx +++ b/front/src/app/components/forms/commons/AgencySelector.tsx @@ -98,6 +98,11 @@ export const AgencySelector = ({ [agencyDepartmentField.name], ); + const agencyKindFieldName = useMemo( + () => agencyKindField.name as keyof SupportedFormsDto, + [agencyKindField.name], + ); + const agencyDepartment = useWatch({ name: agencyDepartmentFieldName, control, @@ -187,6 +192,7 @@ export const AgencySelector = ({ disabled={agencyKindOptions.length === 0 || shouldLockToPeAgencies} nativeSelectProps={{ ...agencyKindField, + ...register(agencyKindFieldName), onChange: (event) => setAllowedAgencyKinds( event.currentTarget.value === "all" diff --git a/front/src/app/components/forms/convention/ConventionForm.tsx b/front/src/app/components/forms/convention/ConventionForm.tsx index 78cb3bf311..1da45272e8 100644 --- a/front/src/app/components/forms/convention/ConventionForm.tsx +++ b/front/src/app/components/forms/convention/ConventionForm.tsx @@ -62,6 +62,7 @@ import { import { ConventionFeedbackNotification } from "src/app/components/forms/convention/ConventionFeedbackNotification"; import { ConventionPresentation, + conventionPresentationSchema, undefinedIfEmptyString, } from "src/app/components/forms/convention/conventionHelpers"; @@ -163,9 +164,10 @@ export const ConventionForm = ({ useWaitForReduxFormUiReadyBeforeInitialisation(initialValues); const defaultValues = mode === "create" ? initialValues : fetchedConvention || initialValues; - const methods = useForm({ + + const methods = useForm>({ defaultValues, - resolver: zodResolver(conventionSchema), + resolver: zodResolver(conventionPresentationSchema), mode: "onTouched", }); @@ -203,14 +205,22 @@ export const ConventionForm = ({ conventionValues.internshipKind ?? "immersion", ); - const onSubmit: SubmitHandler = (convention) => { + const onSubmit: SubmitHandler> = ( + convention, + ) => { const conventionToSave: ConventionReadDto = { - ...convention, + ...conventionSchema.parse(convention), + agencyKind: convention.agencyKind, + agencyDepartment: convention.agencyDepartment, workConditions: undefinedIfEmptyString(convention.workConditions), establishmentNumberEmployeesRange: establishmentNumberEmployeesRange === "" ? undefined : establishmentNumberEmployeesRange, + agencySiret: "", + agencyName: "", + agencyCounsellorEmails: [], + agencyValidatorEmails: [], }; dispatch( conventionSlice.actions.showSummaryChangeRequested({ @@ -301,7 +311,7 @@ export const ConventionForm = ({ ): Promise> => { const stepFields = formUiSections[step - 1]; const validatedFields = stepFields.map(async (field) => ({ - [field]: await trigger(field as keyof ConventionReadDto), + [field]: await trigger(field as keyof ConventionPresentation), })); const validatedFieldsValue = await Promise.all(validatedFields); const getStepStatus = () => { @@ -312,7 +322,7 @@ export const ConventionForm = ({ ).length; const stepIsTouched = stepFields.filter( (stepField) => - getFieldState(stepField as keyof ConventionReadDto).isTouched, + getFieldState(stepField as keyof ConventionPresentation).isTouched, ).length; if (validatedFieldsValue.every((field) => Object.values(field)[0])) { return "success"; @@ -384,6 +394,10 @@ export const ConventionForm = ({ data-matomo-name={domElementIds.conventionImmersionRoute.form({ mode, })} + onSubmit={handleSubmit(onSubmit, (errors) => { + validateSteps("doNotClear"); + console.error(conventionValues, errors); + })} > <> <> @@ -545,16 +559,10 @@ export const ConventionForm = ({ disabled={shouldSubmitButtonBeDisabled} iconId="fr-icon-checkbox-circle-line" iconPosition="left" - type="button" + type="submit" nativeButtonProps={{ id: domElementIds.conventionImmersionRoute.submitFormButton, }} - onClick={(e) => - handleSubmit(onSubmit, (errors) => { - validateSteps("doNotClear"); - console.error(conventionValues, errors); - })(e) - } > VĂ©rifier la demande @@ -583,12 +591,6 @@ export const ConventionForm = ({