Files
AndreaSlopFotografie/web/src/cms-client/contact/messages.nl.ts
T
SluijsensandClaude Sonnet 5.5 e09459423f Connects the contact form to the CMS API through the cms-client package
Copies the headless cms-client package (SlpSoftware 93fa729) and builds the
form on useContactForm: availability check when the form is in view (no
request while switched off), the readable shoot label as subject, the Friendly
Captcha widget as its own lazy chunk, trackEvent for contact-sent and
contact-failed. Removes the old reducer, validation and submit stub.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 23:21:02 +01:00

62 lines
2.1 KiB
TypeScript

import type { ContactErrorCode, ContactField } from './types';
/** Texts of the contact form; every entry can be overridden per site (default: Dutch). */
export interface ContactMessages {
fieldErrors: Record<ContactField, Partial<Record<ContactErrorCode, string>>>;
fallbackFieldError: string;
rateLimited: (minutes: number) => string;
tooLarge: string;
/** Shown when the captcha has not been solved (or has expired) at submit time. */
captchaRequired: string;
failed: (address: string) => string;
sendingLabel: string;
}
export const messagesNl: ContactMessages = {
fieldErrors: {
name: {
required: 'Vul je naam in.',
tooLong: 'De naam is te lang.',
invalid: 'Deze naam is ongeldig.',
},
email: {
required: 'Vul je e-mailadres in.',
tooLong: 'Het e-mailadres is te lang.',
invalid: 'Dit e-mailadres is ongeldig.',
},
subject: {
required: 'Kies een onderwerp.',
tooLong: 'Dit onderwerp is te lang.',
invalid: 'Kies een onderwerp.',
},
message: {
required: 'Schrijf hier je vraag.',
tooLong: 'Het bericht is te lang.',
invalid: 'Dit bericht bevat ongeldige tekens.',
},
},
fallbackFieldError: 'Controleer dit veld.',
rateLimited: (minutes) =>
`Je hebt net al een bericht gestuurd. Probeer het over ${minutes} ${minutes === 1 ? 'minuut' : 'minuten'} opnieuw.`,
tooLarge: 'Je bericht is te groot.',
captchaRequired: 'Bevestig eerst dat je geen robot bent.',
failed: (address) => `Versturen lukte niet. Probeer het later nog eens of mail naar ${address}.`,
sendingLabel: 'Versturen…',
};
export function fieldErrorMessage(
messages: ContactMessages,
field: ContactField,
code: ContactErrorCode,
): string {
return messages.fieldErrors[field][code] ?? messages.fallbackFieldError;
}
/** Retry-After seconds -> whole minutes, rounded up, at least 1. */
export function retryAfterMinutes(seconds: number | null): number {
if (seconds === null || !Number.isFinite(seconds) || seconds <= 0) {
return 1;
}
return Math.max(1, Math.ceil(seconds / 60));
}