diff --git a/targets/frontend/src/components/contributions/answers/Answer.tsx b/targets/frontend/src/components/contributions/answers/Answer.tsx index 056503351..4ca494136 100644 --- a/targets/frontend/src/components/contributions/answers/Answer.tsx +++ b/targets/frontend/src/components/contributions/answers/Answer.tsx @@ -75,7 +75,7 @@ export const ContributionsAnswer = ({ setStatus(answer.status.status); } }, [answer]); - const { control, handleSubmit, watch } = useForm({ + const { control, getValues, trigger, watch } = useForm({ defaultValues: { content: answer?.content ?? "", otherAnswer: answer?.otherAnswer ?? "ANSWER", @@ -91,7 +91,20 @@ export const ContributionsAnswer = ({ }>({ open: false, }); - const onSubmit = async (data: AnswerForm) => { + + const onSubmit = async (newStatus: Status) => { + const isValid = await trigger(); + if (!isValid) { + return setSnack({ + open: true, + severity: "error", + message: "Formulaire invalide", + }); + } + + setStatus(newStatus); + const data = getValues(); + try { if (!answer || !answer.id) { throw new Error("Id non définit"); @@ -101,7 +114,7 @@ export const ContributionsAnswer = ({ content: data.content, id: answer.id, otherAnswer: data.otherAnswer, - status, + status: newStatus, userId: user?.id, kali_references: formatKaliReferences(answer, data), legi_references: formatLegiReferences(answer, data), @@ -140,7 +153,7 @@ export const ContributionsAnswer = ({

{answer?.agreement?.name}

-
+