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.3 KiB

Business Logic Model — contact-form (U4)

Module layout (movable package)

src/cms-client/ is self-contained (an ESLint no-restricted-imports rule forbids imports from outside it):

  • http/ — apiUrl, parseProblem, ApiError.
  • contact/ — validateContact, contactFormReducer + types, messages.nl, createContactClient (getToken, submit), useContactForm.
  • index.ts per subpath (@/cms-client/contact, later /offerings) so a site imports only what it uses.

Submission sequence

sequenceDiagram
    box rgba(99,179,237,0.4) Browser
      participant V as Visitor
      participant H as useContactForm
      participant C as contact client
    end
    box rgba(154,230,180,0.4) CMS API
      participant A as contact-messages
    end
    H->>C: get token when section nears viewport
    C->>A: GET token
    A-->>C: 200 token and minSeconds
    V->>H: fill fields and submit
    H->>H: validate and honeypot check
    H->>C: submit with token and idempotency key
    C->>A: POST contact-messages
    A-->>C: 202 received
    C-->>H: ok
    H-->>V: success state

Text alternative: the hook obtains a token via the client, validates on submit, posts with the token and an idempotency key and shows the success state after a 202.

Pure units (unit- and property-tested)

  • validateContact(values) -> errors: trimming, boundaries 100/254/100/2000 inclusive, control characters, email regex.
  • contactFormReducer(state, event): events change, blur, submit, sending, succeeded, failed, fieldErrors, reset, preselect; invariants: sent never reverts except reset; input kept on failed; edits ignored while sending.
  • mapApiErrors(problem) -> { fields, token, generic } and retryAfterMinutes(headerValue).
  • Request/response serialization round trips (payload shape, problem+json parsing) — property-based (PBT partial per the extension decision).

Integration of the pieces

  • ContactSection (U2 frame) renders ContactPanel: availability unknown/closed → mailto panel; open → ContactFormView (B skin) using useContactForm.
  • Subject options come from usePackagesQuery + "Overig"; useContactPreselect (U3) drives preselect.
  • Umami events via the existing analytics component's API (no data), Sentry untouched except documented non-logging.