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>
This commit is contained in:
2026-11-10 13:13:24 +01:00
co-authored by Claude Sonnet 5.5
parent 9661b64635
commit aa843a5675
45 changed files with 2609 additions and 22 deletions
@@ -0,0 +1,23 @@
# Logical Components — contact-form (U4)
```mermaid
graph TD
UI[ContactFormView and ContactPanel] --> HOOK[useContactForm]
UI --> AVAIL[useContactAvailability]
HOOK --> PURE[validateContact reducer mapApiErrors]
HOOK --> CLIENT[createContactClient]
AVAIL --> CLIENT
CLIENT --> HTTP[http apiUrl fetch with timeout]
HTTP --> API[(CMS API same origin)]
HOOK --> TELE[analytics events without data]
classDef ui fill:#2196F3,stroke:#0d47a1,color:#000;
classDef core fill:#4CAF50,stroke:#2e7d32,color:#000;
classDef io fill:#9C27B0,stroke:#4a148c,color:#000;
classDef ext fill:#F44336,stroke:#b71c1c,color:#000;
class UI ui;
class HOOK,AVAIL,PURE core;
class CLIENT,HTTP,TELE io;
class API ext;
```
Text alternative: the UI uses the headless hook and the availability hook; both rely on the pure core and the client; the client uses the http helper with a timeout towards the same-origin API; telemetry carries no data.
@@ -0,0 +1,20 @@
# NFR Design Patterns — contact-form (U4)
| Pattern | Where | Purpose |
|---|---|---|
| Progressive enhancement | `ContactPanel` + `useContactAvailability` | form only when the API answers 200; mailto otherwise |
| Fail closed to a safe fallback | client/hook | any unexpected response or error ends in the failure state with the mail address |
| Idempotent retry | hook + `Idempotency-Key` | a retry never creates a second message |
| Pure core / thin shell | `validateContact`, reducer, `mapApiErrors` | testable without DOM or network (PBT) |
| Honeypot + server token | hook + API | bots learn nothing; no client clock |
| Request timeout | client | `AbortController` 10 s so the UI never hangs in `sending` |
| Data minimisation in telemetry | analytics calls | events without data; no values in logs |
| Single token refresh | client | `expired` handled once, then generic failure (no loops) |
| Layout reservation | `ContactPanel` | minimum height keeps the page stable when upgrading from mailto to form |
## Misuse / abuse scenarios considered
1. A bot fills every field including the honeypot: silent success on the client, the server drops or stores it as spam.
2. Rapid repeated submits (double click, flaky network): ignored while `sending`; same idempotency key on retry.
3. Visitor tampers with the token: the API answers `expired`; one refresh, then failure.
4. Very large input pasted: client length errors; the API answers 413, message "Je bericht is te groot."
5. API unavailable or deliberately closed (switches): the form never appears or falls back to mailto; no console spam.