generated from digitalservicebund/remix-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- inline ResultPage component - extract business logic to separate files
- Loading branch information
Showing
5 changed files
with
285 additions
and
279 deletions.
There are no files selected for viewing
196 changes: 0 additions & 196 deletions
196
packages/dito/app/routes/vorpruefung.ergebnis/ResultPage.tsx
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
packages/dito/app/routes/vorpruefung.ergebnis/buildMailtoRedirectUri.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { preCheck } from "resources/content"; | ||
import { type ResultContent } from "routes/vorpruefung.ergebnis/getContentForResult"; | ||
import { PreCheckResult, ResultType } from "./PreCheckResult"; | ||
|
||
const { emailTemplate } = preCheck.result.form; | ||
|
||
function resolveRecipients(result: PreCheckResult) { | ||
const additionalRecipient = | ||
result.interoperability !== ResultType.NEGATIVE | ||
? `; ${emailTemplate.toDC}` | ||
: ""; | ||
return `${emailTemplate.toNkr}${additionalRecipient}`; | ||
} | ||
|
||
function buildEmailBody( | ||
resultContent: ResultContent, | ||
negativeReasoning?: string, | ||
) { | ||
let resultText: string = `${resultContent.title}\n\n\n`; | ||
|
||
resultContent.reasoningList | ||
.filter((reasoning) => reasoning.reasons.length !== 0) | ||
.forEach(({ intro, reasons }) => { | ||
resultText += `➤ ${intro} \n\n`; | ||
reasons | ||
.sort((reason) => (reason.answer === "yes" ? -1 : 1)) | ||
.forEach((reason) => { | ||
resultText += reason.answer === "yes" ? "+" : ""; | ||
resultText += reason.answer === "no" ? "-" : ""; | ||
resultText += reason.answer === "unsure" ? "?" : ""; | ||
resultText += ` ${reason.text}\n`; | ||
resultText += reason.hint ? `${reason.hint}\n` : ""; | ||
}); | ||
resultText += "\n\n"; | ||
}); | ||
|
||
resultText = resultText.replaceAll("**", ""); | ||
resultText += negativeReasoning | ||
? `${preCheck.result.form.reasonLabel}:\n\n${negativeReasoning}\n\n` | ||
: ""; | ||
|
||
return `${emailTemplate.bodyBefore}\n${resultText}\n\n${emailTemplate.bodyAfter}`; | ||
} | ||
|
||
export default function buildMailtoRedirectUri( | ||
result: PreCheckResult, | ||
resultContent: ResultContent, | ||
policyTitle: string, | ||
userEmail?: string, | ||
negativeReasoning?: string, | ||
) { | ||
const subject = `${emailTemplate.subject}: „${policyTitle}“`; | ||
const cc = userEmail ? `&cc=${userEmail}` : ""; | ||
const recipients = encodeURIComponent(resolveRecipients(result)); | ||
const body = buildEmailBody(resultContent, negativeReasoning); | ||
return `mailto:${recipients}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}${cc}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/dito/app/routes/vorpruefung.ergebnis/getResultForAnswers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { preCheck } from "resources/content"; | ||
import type { PreCheckAnswers } from "routes/vorpruefung.$questionId/route"; | ||
import { PreCheckResult, ResultType } from "./PreCheckResult"; | ||
|
||
const { questions } = preCheck; | ||
|
||
export default function getResultForAnswers( | ||
answers: PreCheckAnswers, | ||
): PreCheckResult { | ||
const digital = getResultForRelevantAnswers(answers, false); | ||
const interoperability = | ||
digital === ResultType.POSITIVE | ||
? getResultForRelevantAnswers(answers, true) | ||
: ResultType.NEGATIVE; | ||
return { digital, interoperability }; | ||
} | ||
|
||
function getResultForRelevantAnswers( | ||
answers: PreCheckAnswers, | ||
interoperability: boolean, | ||
) { | ||
const relevantAnswers = questions | ||
.filter((question) => !!question.interoperability === interoperability) | ||
.map((question) => answers[question.id]); | ||
if (relevantAnswers.includes("yes")) { | ||
return ResultType.POSITIVE; | ||
} | ||
if (relevantAnswers.includes("unsure")) { | ||
return ResultType.UNSURE; | ||
} | ||
return ResultType.NEGATIVE; | ||
} |
Oops, something went wrong.