Skip to content

Commit

Permalink
Remove _action attribute from form
Browse files Browse the repository at this point in the history
  • Loading branch information
mpanne committed Jan 9, 2025
1 parent 0ecc429 commit cb54965
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 0 additions & 2 deletions packages/dito/app/routes/vorpruefung.ergebnis/ResultForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 22 additions & 19 deletions packages/dito/app/routes/vorpruefung.ergebnis/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,34 @@ 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() {
Expand Down

0 comments on commit cb54965

Please sign in to comment.