From 0018c5b1cb316b981b0957b178793d321fd77def Mon Sep 17 00:00:00 2001 From: Merlin Pannewitz Date: Thu, 9 Jan 2025 12:34:03 +0100 Subject: [PATCH] Remove _action attribute from form --- .../vorpruefung.ergebnis/ResultForm.tsx | 2 - .../app/routes/vorpruefung.ergebnis/route.tsx | 38 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/dito/app/routes/vorpruefung.ergebnis/ResultForm.tsx b/packages/dito/app/routes/vorpruefung.ergebnis/ResultForm.tsx index 275f5b03..07502a92 100644 --- a/packages/dito/app/routes/vorpruefung.ergebnis/ResultForm.tsx +++ b/packages/dito/app/routes/vorpruefung.ergebnis/ResultForm.tsx @@ -75,8 +75,6 @@ export default function ResultForm({ buttons={[ { id: "result-email-button", - name: "_action", - value: "email", text: preCheck.result.form.sendEmailButton.text, look: "primary", className: "plausible-event-name=Quicksend+Click", diff --git a/packages/dito/app/routes/vorpruefung.ergebnis/route.tsx b/packages/dito/app/routes/vorpruefung.ergebnis/route.tsx index 2d8fb70b..51d83c76 100644 --- a/packages/dito/app/routes/vorpruefung.ergebnis/route.tsx +++ b/packages/dito/app/routes/vorpruefung.ergebnis/route.tsx @@ -123,31 +123,31 @@ function resolveRecipients(result: PreCheckResult) { export async function action({ request }: ActionFunctionArgs) { const formData = await request.formData(); - const { _action, title, negativeReasoning, ...answers } = - Object.fromEntries(formData); + const { title, negativeReasoning, ...answers } = Object.fromEntries(formData); // server side form validation in case the user has JavaScript disabled const preCheckAnswers = answers as PreCheckAnswers; const validator = getResultValidatorForAnswers(preCheckAnswers); - const result = await validator.validate({ title, negativeReasoning }); - if (result.error) { - return validationError(result.error, result.submittedData); - } - - if (_action === "email") { - const result = getResult(preCheckAnswers); - const subject = `${emailTemplate.subject}: „${formData.get("title") as string}“`; - const email = formData.get("email"); - const cc = email ? `&cc=${email as string}` : ""; - const negativeReasoning = formData.get("negativeReasoning") as string; - const recipients = resolveRecipients(result); - const mailToLink = encodeURI( - `mailto:${recipients}?subject=${subject}&body=${buildEmailBody(preCheckAnswers, result, negativeReasoning)}${cc}`, + const validationResult = await validator.validate({ + title, + negativeReasoning, + }); + if (validationResult.error) { + return validationError( + validationResult.error, + validationResult.submittedData, ); - return redirect(mailToLink); } - // eslint-disable-next-line @typescript-eslint/only-throw-error - throw new Response("Unknown action", { status: 400 }); + + const result = getResult(preCheckAnswers); + const subject = `${emailTemplate.subject}: „${formData.get("title") as string}“`; + const email = formData.get("email"); + const cc = email ? `&cc=${email as string}` : ""; + const recipients = resolveRecipients(result); + const mailToLink = encodeURI( + `mailto:${recipients}?subject=${subject}&body=${buildEmailBody(preCheckAnswers, result, formData.get("negativeReasoning") as string)}${cc}`, + ); + return redirect(mailToLink); } export default function Result() {