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>
2.3 KiB
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.tsper 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): eventschange,blur,submit,sending,succeeded,failed,fieldErrors,reset,preselect; invariants:sentnever reverts exceptreset; input kept onfailed; edits ignored whilesending.mapApiErrors(problem) -> { fields, token, generic }andretryAfterMinutes(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) rendersContactPanel: availabilityunknown/closed→ mailto panel;open→ContactFormView(B skin) usinguseContactForm.- Subject options come from
usePackagesQuery+ "Overig";useContactPreselect(U3) drivespreselect. - Umami events via the existing analytics component's API (no data), Sentry untouched except documented non-logging.