Skip to content

Commit

Permalink
fix wrong appellation when contacting by email
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Jul 6, 2023
1 parent 4b96208 commit 962853d
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions front/src/app/components/search/ContactByEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { fr } from "@codegouvfr/react-dsfr";
import Alert from "@codegouvfr/react-dsfr/Alert";
Expand Down Expand Up @@ -66,13 +66,20 @@ export const ContactByEmail = ({
mode: "onTouched",
defaultValues: initialValues,
});

const {
register,
handleSubmit,
formState,
formState: { isSubmitting },
getValues,
reset,
} = methods;

useEffect(() => {
reset({ ...getValues(), appellationCode: initialValues.appellationCode });
}, [appellations]);

const getFieldError = makeFieldError(formState);

const onFormValid = async (values: ContactEstablishmentByMailDto) => {
Expand All @@ -82,6 +89,7 @@ export const ContactByEmail = ({
});
onSuccess();
};

return (
<FormProvider {...methods}>
<form onSubmit={handleSubmit(onFormValid)}>
Expand Down Expand Up @@ -122,17 +130,16 @@ export const ContactByEmail = ({
{...getFieldError("immersionObjective")}
/>

{appellations.length > 1 && (
<Select
label={"Métier sur lequel porte la demande d'immersion *"}
options={appellationListOfOptions}
placeholder={"Sélectionnez un métier"}
nativeSelectProps={{
...register("appellationCode"),
}}
{...getFieldError("appellationCode")}
/>
)}
<Select
disabled={appellations.length === 1}
label={"Métier sur lequel porte la demande d'immersion *"}
options={appellationListOfOptions}
placeholder={"Sélectionnez un métier"}
nativeSelectProps={{
...register("appellationCode"),
}}
{...getFieldError("appellationCode")}
/>

<Input
label="Votre message à l’entreprise *"
Expand Down

0 comments on commit 962853d

Please sign in to comment.