Contactformulier stuurt het leesbare onderwerp (met hoofdletter) i.p.v. de slug

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 23:00:26 +01:00
co-authored by Claude Sonnet 5.5
parent 811ff94df2
commit 75086362ee
6 changed files with 82 additions and 18 deletions
+32
View File
@@ -0,0 +1,32 @@
import type { SubjectOption } from '../../cms-client/contact';
interface NamedPackage {
slug: string;
title: string;
}
/**
* Subject options of the contact form. The value is the readable label (e.g. "Website"), because
* that is what ends up in the e-mail and in the CMS message list. The slug only stays local, for
* the preselect (see `subjectForSlug`).
*/
export function buildSubjectOptions(
packages: readonly NamedPackage[] | undefined,
otherLabel: string,
): SubjectOption[] {
return [
...(packages ?? []).map((pkg) => ({ value: pkg.title, label: pkg.title })),
{ value: otherLabel, label: otherLabel },
];
}
/** Subject value (label) for a package slug, or null when the slug is unknown. */
export function subjectForSlug(
packages: readonly NamedPackage[] | undefined,
slug: string | null,
): string | null {
if (!slug) {
return null;
}
return packages?.find((pkg) => pkg.slug === slug)?.title ?? null;
}