From aa843a56753d156d4e1026f73b6f26ce07721d5c Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Tue, 10 Nov 2026 13:13:24 +0100 Subject: [PATCH] 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 --- .../redesign-modern-timetravel/aidlc-state.md | 2 +- .../redesign-modern-timetravel/audit.md | 72 +++ .../construction/contact-form/code/summary.md | 30 ++ .../functional-design/business-logic-model.md | 43 ++ .../functional-design/business-rules.md | 66 +++ .../functional-design/domain-entities.md | 46 ++ .../functional-design/frontend-components.md | 58 +++ .../infrastructure-design.md | 29 ++ .../nfr-design/logical-components.md | 23 + .../nfr-design/nfr-design-patterns.md | 20 + .../nfr-requirements/nfr-requirements.md | 31 ++ .../nfr-requirements/tech-stack-decisions.md | 7 + .../contact-form-code-generation-plan.md | 38 ++ .../plans/contact-form-fd-questions.md | 11 + .../contact-form-functional-design-plan.md | 9 + .../plans/contact-form-nfr-and-infra-plan.md | 8 + eslint.config.js | 26 + package.json | 1 + pnpm-lock.yaml | 16 + src/cms-client/README.md | 9 + src/cms-client/__tests__/boundary.test.ts | 47 ++ .../__tests__/contactFormReducer.test.ts | 163 +++++++ .../__tests__/createContactClient.test.ts | 225 +++++++++ .../contact/__tests__/validateContact.test.ts | 112 +++++ src/cms-client/contact/contactFormReducer.ts | 108 +++++ src/cms-client/contact/createContactClient.ts | 117 +++++ src/cms-client/contact/index.ts | 9 + src/cms-client/contact/messages.nl.ts | 58 +++ src/cms-client/contact/types.ts | 40 ++ src/cms-client/contact/useContactForm.ts | 260 ++++++++++ src/cms-client/contact/validateContact.ts | 60 +++ src/cms-client/http/apiUrl.ts | 8 + src/cms-client/http/fetchJson.ts | 44 ++ src/cms-client/http/problem.ts | 45 ++ .../landing/__tests__/ContactForm.test.tsx | 453 ++++++++++++++++++ .../landing/components/ContactFormView.tsx | 164 +++++++ .../landing/components/ContactPanel.tsx | 31 ++ .../landing/components/ContactSection.tsx | 24 +- .../landing/components/MailtoPanel.tsx | 24 + src/features/landing/data/content.ts | 8 + .../landing/hooks/useContactAvailability.ts | 63 +++ src/index.css | 4 + src/shared/analytics/trackEvent.ts | 15 + src/theme/__tests__/contrast.test.ts | 3 + tailwind.config.ts | 1 + 45 files changed, 2609 insertions(+), 22 deletions(-) create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/code/summary.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/functional-design/business-logic-model.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/functional-design/business-rules.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/functional-design/domain-entities.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/functional-design/frontend-components.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/infrastructure-design/infrastructure-design.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/nfr-design/logical-components.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/nfr-design/nfr-design-patterns.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/nfr-requirements/nfr-requirements.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/nfr-requirements/tech-stack-decisions.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/contact-form-code-generation-plan.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/contact-form-fd-questions.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/contact-form-functional-design-plan.md create mode 100644 aidlc-docs/features/redesign-modern-timetravel/construction/plans/contact-form-nfr-and-infra-plan.md create mode 100644 src/cms-client/README.md create mode 100644 src/cms-client/__tests__/boundary.test.ts create mode 100644 src/cms-client/contact/__tests__/contactFormReducer.test.ts create mode 100644 src/cms-client/contact/__tests__/createContactClient.test.ts create mode 100644 src/cms-client/contact/__tests__/validateContact.test.ts create mode 100644 src/cms-client/contact/contactFormReducer.ts create mode 100644 src/cms-client/contact/createContactClient.ts create mode 100644 src/cms-client/contact/index.ts create mode 100644 src/cms-client/contact/messages.nl.ts create mode 100644 src/cms-client/contact/types.ts create mode 100644 src/cms-client/contact/useContactForm.ts create mode 100644 src/cms-client/contact/validateContact.ts create mode 100644 src/cms-client/http/apiUrl.ts create mode 100644 src/cms-client/http/fetchJson.ts create mode 100644 src/cms-client/http/problem.ts create mode 100644 src/features/landing/__tests__/ContactForm.test.tsx create mode 100644 src/features/landing/components/ContactFormView.tsx create mode 100644 src/features/landing/components/ContactPanel.tsx create mode 100644 src/features/landing/components/MailtoPanel.tsx create mode 100644 src/features/landing/hooks/useContactAvailability.ts create mode 100644 src/shared/analytics/trackEvent.ts diff --git a/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md b/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md index ce2aa21..a7f6d6c 100644 --- a/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md +++ b/aidlc-docs/features/redesign-modern-timetravel/aidlc-state.md @@ -5,7 +5,7 @@ - **Feature Slug**: redesign-modern-timetravel - **Project Type**: Brownfield - **Start Date**: 2026-11-09T13:00:00Z -- **Current Stage**: CONSTRUCTION - U3 packages-block Code Generation plan (awaiting approval) +- **Current Stage**: CONSTRUCTION - U4 contact-form Code Generation plan (awaiting approval) - **Branch**: feature/redesign-modern-timetravel ## Workspace State diff --git a/aidlc-docs/features/redesign-modern-timetravel/audit.md b/aidlc-docs/features/redesign-modern-timetravel/audit.md index 314761c..a703878 100644 --- a/aidlc-docs/features/redesign-modern-timetravel/audit.md +++ b/aidlc-docs/features/redesign-modern-timetravel/audit.md @@ -646,3 +646,75 @@ **Context**: Code Generation Part 1 for U3. --- + +## U3 Code Generation Complete + +**Timestamp**: 2026-11-10T15:00:00Z + +**User Input**: "approve plan" + +**AI Response**: "Executed all 7 steps of packages-block-code-generation-plan.md. Tests 13 files/122 tests before, 14 files/154 after, all passed; lint 0 errors (2 pre-existing warnings); build OK. Committed on feature/redesign-modern-timetravel, no push. Summary at construction/packages-block/code/summary.md. Completion message presented." + +**Context**: Code Generation U3 complete; awaiting approval before U4. + +--- + +## U3 Approved; U4 Functional Design Started + +**Timestamp**: 2026-11-10T16:00:00Z + +**User Input**: "ga verder" / (interactive) "Zin met bewaartermijn, zonder link (Recommended)" + +**AI Response**: "U3 approved. Read the CMS phase-1 handoff (routes, limits, error shapes, switches) as input. U4 contact-form Functional Design: privacy sentence = 'Je gegevens gebruik ik alleen om op je bericht te reageren; ik bewaar ze maximaal 12 maanden.' (no link). Decisions taken without asking: progressive enhancement (the panel shows the mailto call-to-action by default and is upgraded to the form once the token endpoint answers 200; 404 = closed = stay on mailto), no build-time flag (the server decides), radio 'aanvraag/vraag' and phone field of the canvas dropped (fixed four fields), captcha slot supported by the hook but no widget in this repo (captcha enabled server-side => mailto fallback), honeypot DOM name free (JSON hpCheck)." + +**Context**: Functional Design U4. + +--- + +## U4 Functional Design Complete + +**Timestamp**: 2026-11-10T16:30:00Z + +**User Input**: "(none)" + +**AI Response**: "Generated contact-form-functional-design-plan.md, contact-form-fd-questions.md and construction/contact-form/functional-design/{domain-entities, business-rules (BR-U4-1..16), business-logic-model, frontend-components}.md. Completion message presented; NFR Requirements, NFR Design and Infrastructure Design for U4 follow as separate stages." + +**Context**: Functional Design U4 awaiting approval. + +--- + +## Production Deploy and ASF Merge in Progress; Builder Released After Completion + +**Timestamp**: 2026-11-10T16:45:00Z + +**User Input**: "Ze zijn nu bezig met deployen naar productie voor SlpSoftware en mergen van changes van ASF in de backend. houdt dat even in de gaten. zodra dat klaar is kan `SLS Software ` ook verder en gaan die changes vanaf master of main (ik weet even niet meer welke van de 2 branchnamen hie rgebruikt wordt) gaan mergen" + +**AI Response**: "Checked the CMS repo read-only: origin/master is still d9cc539, the ASF branch is not merged yet; main branch is master. Told the builder (SLS Software - CMS) that once origin/master contains the ASF branch it may rebase feature/contact-forms-module onto master (no force/push), switch the rate-limit key to ClientPartitionKey, run all tests, and send the rebase result plus plans for CMS-U5/U6/U7. Contact:Enabled stays off; no push/merge/PR/deploy without Bryan. To be re-checked when the ASF session reports or the user asks." + +**Context**: Coordination; this is the explicit go for CMS phase 2 conditional on the ASF merge. + +--- + +## U4 Functional Design Approved; NFR and Infrastructure Docs Written + +**Timestamp**: 2026-11-10T18:00:00Z + +**User Input**: "Functional Design is goed. Ga verder" / (interactive) "SLP software heeft al een api. Die hoeft niet verplaatst te worden toch?" + +**AI Response**: "U4 FD approved. Wrote NFR Requirements (NFR-U4-1..9, Security Baseline summary), tech-stack decisions (no runtime deps, fast-check dev dep), NFR design patterns, logical components and Infrastructure Design. Existing proxy routing and header setup are unconfirmed (CMS and API asked Pi-Main and the CMS session) and are documented as unconfirmed, SECURITY-04 open. Confirmed by CMS and API: the production release now contains no contact routes. Builder told to wait for the merge commit (PR 11, CI run 637); System/capabilities marker commit approved." + +**Context**: Construction U4; combined NFR/Infra completion presented; next Code Generation plan. + +--- + +## U4 NFR and Infrastructure Approved; Code Generation Plan Ready + +**Timestamp**: 2026-11-10T19:00:00Z + +**User Input**: "Ga verder" + +**AI Response**: "NFR Requirements, NFR Design and Infrastructure Design for U4 accepted. Updated the infrastructure doc with confirmed facts from CMS and API (apps on Pi-Main test :5100 prod :5101, CMS host sets security headers, nginx on Pi-Main sets none, production release has no contact routes) and marked the unconfirmed points. Created construction/plans/contact-form-code-generation-plan.md (9 steps). Plan approval prompt presented." + +**Context**: Code Generation Part 1 for U4. + +--- diff --git a/aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/code/summary.md b/aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/code/summary.md new file mode 100644 index 0000000..f8944ab --- /dev/null +++ b/aidlc-docs/features/redesign-modern-timetravel/construction/contact-form/code/summary.md @@ -0,0 +1,30 @@ +# Code Summary — contact-form (U4) + +## What was built +- **Movable package `src/cms-client/`** (no imports from the app; ESLint `no-restricted-imports` plus a boundary test): `http/` (`apiUrl`, `fetchJson` with 10 s timeout, problem+json parsing), `contact/` (`validateContact`, `contactFormReducer`, `createContactClient`, `messages.nl`, `useContactForm`, types), `README.md`. +- **Validation** equal to the API (trim; 100/254/100/2000; email regex; control characters rejected except line breaks in the message; first failing rule per field). **Reducer**: `sent` only leaves through `reset`; edits and a second submit are ignored while `sending`; input is kept on `failed`. +- **Client**: `getToken` (200 → token, 404 → closed, anything else → failed, malformed body → failed) and `submit` (202 ok; 400 → field errors or token expired; 413; 404; 429 with `Retry-After`; 5xx/network → failed). Never throws, never logs. +- **Hook `useContactForm`**: prop getters with ids from `idPrefix`, `aria-invalid`/`aria-describedby`, honeypot props (silent success without a request when filled), one idempotency key per attempt series (reused on retry, renewed after success/reset), a single automatic token refresh on `expired`, preselect with change counter (unknown values ignored), focus on the first invalid field after the render, telemetry only through `onEvent('sent' | 'failed')`. +- **UI**: `ContactPanel` (mailto panel by default, upgrades to the form when `GET …/token` answers 200 without captcha; min height 280px), `MailtoPanel`, `ContactFormView` (design B: panel colours, underline inputs on `bg-field`, brand submit button, errors outside the labels, `role=alert` failure with the mail address, `role=status` success with focus, privacy sentence), hidden honeypot field. `useContactAvailability` starts the token request when the section nears the viewport (IntersectionObserver, `rootMargin 300px`), or on first focus without IntersectionObserver. Subject options = offerings (slug/title) + "Overig". `trackEvent('contact-sent' | 'contact-failed')` without data. +- **Tokens**: new `--color-danger` (error text) in all four sets, contrast-tested against `panel` and `field`. +- **Dependencies**: `fast-check` (dev) for property-based tests; no runtime dependency. + +## Verification (Step 13.5, real output) +- Before this unit (after U3): 14 files / 154 tests. After: **19 files / 239 tests passed**; `pnpm lint` 0 errors (same 2 existing warnings, boundary rule active); `pnpm build` OK (JS 466 kB, CSS 58.8 kB). +- Found and fixed by the tests: (1) field errors inside the `