Skip to content

Commit

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

export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData();
const { title, negativeReasoning, ...answers } = Object.fromEntries(formData);
const { _action, 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 validationResult = await validator.validate({
title,
negativeReasoning,
});
if (validationResult.error) {
return validationError(
validationResult.error,
validationResult.submittedData,
);
const result = await validator.validate({ title, negativeReasoning });
if (result.error) {
return validationError(result.error, result.submittedData);
}

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);
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}`,
);
return redirect(mailToLink);
}
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw new Response("Unknown action", { status: 400 });
}

export default function Result() {
Expand Down

0 comments on commit 3d4554d

Please sign in to comment.