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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user