Files
SluijsensandClaude Sonnet 5.5 aa843a5675 Contactformulier: cms-client (validatie, reducer, client, hook), formulier in stijl B en beschikbaarheid
Headless pakket src/cms-client met importgrens, formulier dat pas verschijnt als de API antwoordt
(anders blijft de mailto-knop), honeypot, idempotentie, token-vernieuwing en property-based tests.

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

2.9 KiB
Raw Permalink Blame History

Domain Entities — contact-form (U4)

graph TD
    CF[ContactFields] -->|"validated by"| VAL[validateContact]
    VAL -->|"produces"| ERR[FieldErrors code per field]
    CF -->|"sent with"| TOK[ContactToken]
    CF -->|"sent with"| IDK[Idempotency key]
    TOK -->|"from"| API1[GET token]
    CF -->|"posted to"| API2[POST contact-messages]
    ST[FormState] -->|"holds"| CF
    ST -->|"holds"| ERR
    ST -->|"status"| STA[editing sending sent failed]
    PRE[ContactPreselect] -->|"subject"| CF
    AV[Availability] -->|"open closed"| ST
    classDef data fill:#63b3ed,stroke:#2b6cb0,color:#000;
    classDef logic fill:#9ae6b4,stroke:#2f855a,color:#000;
    classDef ext fill:#f6e05e,stroke:#c05621,color:#000;
    class CF,ERR,ST,STA,PRE,AV data;
    class VAL logic;
    class TOK,IDK,API1,API2 ext;

Text alternative: the fields are validated into per-field error codes; submission needs a server token and an idempotency key and posts to the API; the form state holds fields, errors and status; the package preselect fills the subject; availability decides whether the form is shown at all.

ContactFields

Field Type Rules (same as the API)
name string trimmed, 1–100, no control characters
email string trimmed, 1–254, ^[^\s@]+@[^\s@]+\.[^\s@]{2,}$, no control characters
subject string opaque value from the site's options (package slug or other), 1–100
message string trimmed, 1–2000, control characters rejected except line breaks and tabs

Payload to the API: the four fields (trimmed) + hpCheck (always "" unless a bot filled the honeypot) + token + optional captchaToken.

Error codes and messages

Codes required | tooLong | invalid | expired. Messages per field and code (Dutch, equal to the ASF texts where they exist): name required "Vul je naam in.", tooLong "De naam is te lang."; 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."; message required "Schrijf hier je vraag.", tooLong "Het bericht is te lang.". Other texts: rate limit "Je hebt net al een bericht gestuurd. Probeer het over {minuten} minuten opnieuw.", too large "Je bericht is te groot.", server/network "Versturen lukte niet. Probeer het later nog eens of mail naar {adres}.", token expired is retried silently once.

FormState

status: 'editing' | 'sending' | 'sent' | 'failed'; values; touched (per field); errors (shown); attemptKey (Idempotency-Key, one UUID per attempt series; kept on retry, renewed after success or reset).

Availability

unknown (default, shows the mailto panel) → open (token received) | closed (404 on the token route, network error, captcha required or any other non-200) → mailto panel stays.

ContactToken

{ token, minSeconds, captcha: null | { provider, siteKey } }; fetched lazily as described in BR-U4-3.