Adds the Contact section to the homepage
Adds the contact form with the live fields, validation and browser-side anti-spam, behind a coming-soon notice with a mail button until the API exists. A "Boek" link on a price card selects its package, tidies the URL and moves focus to the form. The form loads only when it comes near the screen, so the hero does not wait for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
# Code Generation Plan — Unit 5: Contact
|
||||
|
||||
**This plan is the single source of truth for Code Generation of unit 5.**
|
||||
|
||||
## Unit context
|
||||
- **Requirements**: FR-HP-06, FR-HP-07, FR-HP-08, FR-HP-09, NFR-HP-01/02/03/04/05/06
|
||||
- **Functional design**: [contact/functional-design/](../contact/functional-design/) — BR-FORM-01…13, BR-SEND-01…04, BR-SPAM-01…03, BR-GATE-01…03, BR-MAIL-01, BR-PARAM-02/04, BR-FOCUS-01
|
||||
- **Depends on**: unit 1 (`HomeSection`, `SectionHeading`, `Reveal`), unit 3 (`packages`, `visiblePackages`, `packageFromSearch`, `pakket` search), existing `emailAddress`, `linkButton` and `link` recipes
|
||||
- **PBT**: full — all pure helpers plus a stateful test of the form reducer (PBT-06)
|
||||
- Conventions as in units 1–4.
|
||||
|
||||
## Steps
|
||||
|
||||
### Types and content
|
||||
- [x] **Step 1** — `src/contact/types.ts`: `ContactField`, `ContactValues`, `ContactErrors`, `ContactPayload`, `ShootOption`, `CONTACT_LIMITS` (naam 100, email 254, bericht 2000). `content/types.ts`: `HomeContent.contact { title; lead }`, `SiteContent.contactForm { enabled }`. Content: `homeContent.contact`, `siteContent.contactForm = { enabled: false }`.
|
||||
|
||||
### Pure helpers (`src/lib/`, each with example and property tests)
|
||||
- [x] **Step 2** — `shootOptions.ts`: shown packages (`visiblePackages`) + Overig.
|
||||
- [x] **Step 3** — `validateContact.ts`: `validateField` and `validateContact` with the exact messages of BR-FORM-01…07.
|
||||
- [x] **Step 4** — `toContactPayload.ts`: trimmed payload.
|
||||
- [x] **Step 5** — `isLikelySpam.ts`: honeypot or under `MIN_FILL_MS = 3000`.
|
||||
- [x] **Step 6** — `mailLink.ts`: `mailSubject(packageName?)`, `mailtoLink(address, subject)`.
|
||||
- [x] **Step 7** — `contactFormReducer.ts`: state `{ status, values, touched, errors }`, events `edit`, `blur`, `preselect`, `submit`, `resolved`, `rejected` (BR-FORM-10…12, BR-SEND-01…04, BR-SPAM-02). Stateful property test with random event sequences checking the invariants of business-logic-model.md.
|
||||
- [x] **Step 8** — `test/arbitraries.ts`: `contactValues` (valid), `anyContactValues`, `contactEvent`.
|
||||
|
||||
### Adapter
|
||||
- [x] **Step 9** — `src/contact/submitContactForm.ts` (+ test): `async (payload) => { throw new Error(...) }` today, with a comment pointing to `POST /api/contact` and the captcha token; generic, no details shown to visitors.
|
||||
|
||||
### Styling
|
||||
- [x] **Step 10** — `recipes/formControl.ts`: the design's square fields (white, `line` border, 0.95 × 1.1 rem padding, weight 300, `accent` border + soft ring on focus, error border with sufficient contrast), applied to `Input`, `Textarea` and `NativeSelect.Field`; register in `theme.ts`. Add a `panel` shadow token (design `--shadow-md`) for the notice; error colour token if needed (≥ 4.5:1 on paper).
|
||||
|
||||
### Components
|
||||
- [x] **Step 11** — `components/ContactForm/ContactForm.tsx`: reducer, `shownAt`, Chakra `Field` per field (labels in the eyebrow style, `ink.soft`), name + e-mail side by side from `sm`, select with placeholder, textarea, honeypot, empty `data-robot-check` slot, failure status (`role="alert"`, mail link), submit button (accent `linkButton` style, "Versturen…" while sending), thank-you replacing the form (`role="status"`, focused); `preselect` prop applied on change of its key; injectable `submit`.
|
||||
- [x] **Step 12** — `components/ContactForm/ContactFormGate.tsx`: off → dimmed, `inert` wrapper + notice (eyebrow, text with underline mail link, "Stuur een e-mail" button), text only when the address is invalid; on → children.
|
||||
- [x] **Step 13** — `components/home/ContactSection/ContactSection.tsx`: `HomeSection id="contact" width="narrow"`, heading (`tabIndex={-1}`) and lead, gate + form; resolves `pakket`, preselects, removes it from the URL (`navigate` replace, keep `#contact`, no scroll reset) and focuses the heading (BR-PARAM-02, BR-FOCUS-01).
|
||||
- [x] **Step 14** — Tests: `ContactForm.test.tsx` (labels; blur shows errors only after typing; messages per rule; submit focuses first invalid; errors clear while typing; spam → thank-you, `submit` not called; success → thank-you focused; failure → alert with mail link, values kept; double submit ignored; preselect; axe), `ContactFormGate.test.tsx` (inert form, notice, mailto with subject, invalid address → text only, enabled → form only, axe both), `ContactSection.test.tsx` (preselect from `pakket`, URL cleaned with replace, heading focused, unknown value ignored and cleaned, no focus move without `pakket`).
|
||||
|
||||
### Route
|
||||
- [x] **Step 15** — `routes/index.tsx`: render `ContactSection` after `Testimonials` with `homeContent.contact`, `packages`, `siteContent.contactForm.enabled`, `siteContent.email` and `pakket` from `Route.useSearch()`.
|
||||
- [x] **Step 16** — `app.test.tsx`: "Contact" in the page order; `/?pakket=newborn` → shoot "Newborn" selected, URL without `pakket`, focus on the Contact heading.
|
||||
|
||||
### Verification and wrap-up
|
||||
- [x] **Step 17** — `pnpm check`; Lighthouse home mobile compared with a 5-run median against the unit 4 build. **If the form code costs measurable performance** (as the carousel did), load the form (not the heading and notice) when the section comes near the screen, as in unit 4. Visual check at 1440 / 390 (gate on), and with the gate switched on locally for one screenshot of the working form.
|
||||
- [x] **Step 18** — `construction/contact/code/code-summary.md`.
|
||||
- [x] **Step 19** — Commit ("Adds the Contact section to the homepage" + attribution). Not pushed.
|
||||
|
||||
### Fixes during Step 17
|
||||
- [x] **Step 17a** — Lighthouse median 0.83 → 0.80: the form moved to its own chunk, loaded when the section is within 200 px of the screen or at once via "Boek …", and stays once loaded; placeholder of the measured height.
|
||||
- [x] **Step 17b** — Remaining 0.81: a new shared chunk (Chakra's slot-recipe factory) was fetched by the route on load. PriceCard's `List` and TestimonialSlide's `Blockquote` replaced by plain elements with the same styling; median back to 0.83.
|
||||
|
||||
## Requirement / rule traceability
|
||||
| Item | Steps |
|
||||
|---|---|
|
||||
| FR-HP-06 / BR-FORM-* | 1–3, 7, 10, 11, 14 |
|
||||
| FR-HP-07 / BR-GATE-* | 1, 12, 14 |
|
||||
| FR-HP-08 / BR-SPAM-* | 5, 7, 11, 14 |
|
||||
| FR-HP-09 | 11 (slot) |
|
||||
| BR-SEND-* | 4, 7, 9, 11, 14 |
|
||||
| BR-MAIL-01 | 6, 11, 12, 14 |
|
||||
| BR-PARAM-02/04, BR-FOCUS-01 | 13, 14, 16 |
|
||||
| NFR-HP-05 | 17 |
|
||||
|
||||
## Extension compliance (planned)
|
||||
- **Security**: client-side limits/format checks (server-side in the API feature, SECURITY-05); misuse covered by gate + honeypot + time check (SECURITY-11); generic failure text (SECURITY-15); e-mail never literal in HTML or bundle; no new dependencies or external resources; CSP unchanged.
|
||||
- **PBT**: PBT-02 (mailto round-trip), PBT-03 (validation invariants), PBT-04 (payload idempotency), PBT-05 (spam and e-mail oracles), PBT-06 (reducer state machine), PBT-07 (generators), PBT-08/09 (existing), PBT-10 (example tests).
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
# Functional Design — Vervolgvragen Unit 5: Contact
|
||||
|
||||
## Ontbrekend antwoord: Vraag 6 — Versturen mislukt (straks, met de API)
|
||||
Vraag 6 in [contact-fd-questions.md](contact-fd-questions.md) is nog niet beantwoord.
|
||||
|
||||
- A) Een melding boven de knop: "Versturen lukte niet. Probeer het later nog eens of mail naar info@andreaslop.nl", met het adres als mailto-link. Wat de bezoeker typte blijft staan. (aanbevolen)
|
||||
- B) Alleen "Versturen lukte niet. Probeer het later nog eens."
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
[Answer]: A
|
||||
|
||||
## Onduidelijkheid: melding "te lang" bij Vraag 2
|
||||
Je gaf voor "te lang": "Het bericht is te lang". Er gelden ook grenzen voor naam (100 tekens) en e-mail (254 tekens).
|
||||
Let op: de velden krijgen ook een maximum in de browser, zodat je er niet meer in kunt typen of plakken. De melding is dus vooral een vangnet en zal een bezoeker zelden zien.
|
||||
|
||||
- A) Per veld een eigen melding: "De naam is te lang.", "Het e-mailadres is te lang.", "Het bericht is te lang." (aanbevolen)
|
||||
- B) Overal dezelfde melding: "Het bericht is te lang"
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
[Answer]: A
|
||||
@@ -0,0 +1,63 @@
|
||||
# Functional Design Questions — Unit 5: Contact
|
||||
|
||||
Vul per vraag de letter in na `[Answer]:` (of geef ze in de chat, bijv. "1A, 2A, …"). Past geen enkele optie, kies dan de laatste (Anders) en licht toe. Waar ik een voorkeur heb staat **(aanbevolen)**.
|
||||
|
||||
Zolang het formulier achter de overlay zit, merkt een bezoeker van vraag 1–3 nog niets; ze bepalen hoe het werkt zodra je het aanzet (of als je het op test even aanzet om te proberen).
|
||||
|
||||
## Vraag 1: Wanneer verschijnen foutmeldingen?
|
||||
|
||||
- A) Pas bij versturen. Daarna wordt per veld opnieuw gecontroleerd zodra de bezoeker het aanpast, zodat een melding verdwijnt zodra het goed is. Niemand krijgt een fout tijdens het typen van een eerste poging. (aanbevolen)
|
||||
- B) Bij het verlaten van elk veld (tab of klik ergens anders), en bij versturen
|
||||
- C) Alleen bij versturen; meldingen blijven staan tot de volgende poging
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
[Answer]: B
|
||||
|
||||
## Vraag 2: Foutmeldingen
|
||||
Voorstel (uit het ontwerp, aangevuld):
|
||||
- Naam leeg: "Vul je naam in."
|
||||
- E-mail leeg: "Vul je e-mailadres in." · ongeldig: "Dit e-mailadres klopt nog niet."
|
||||
- Shoot niet gekozen: "Kies een soort shoot."
|
||||
- Bericht leeg: "Schrijf hier je vraag."
|
||||
- Te lang (naam 100, e-mail 254, bericht 2000 tekens): "Dit is te lang (maximaal N tekens)."
|
||||
|
||||
- A) Zo overnemen (aanbevolen)
|
||||
- X) Anders (pas hieronder aan na de [Answer]:-tag)
|
||||
|
||||
[Answer]: X — E-mail ongeldig: "Dit e-mailadres is ongeldig." Te lang: "Het bericht is te lang"
|
||||
|
||||
## Vraag 3: Na succesvol versturen
|
||||
|
||||
- A) Het formulier verdwijnt en er komt een bevestiging voor in de plaats: "Bedankt voor je bericht! Andrea reageert binnen 2-3 werkdagen." De focus gaat naar die bevestiging, zodat ook een schermlezer hem hoort. (aanbevolen)
|
||||
- B) Het formulier blijft staan en wordt leeggemaakt; de bevestiging staat eronder
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
Klopt "binnen 2-3 werkdagen"? Pas het anders aan bij je antwoord.
|
||||
|
||||
[Answer]: A, maar het bericht is: "Bedankt voor je bericht! Ik reageer binnen 1-2 werkdagen."
|
||||
|
||||
## Vraag 4: De mailknop in de overlay
|
||||
|
||||
- A) De mail krijgt alvast een onderwerp: "Vraag via andreaslop.nl", en als de bezoeker via "Boek …" kwam het pakket erbij: "Aanvraag fotoshoot: Newborn". Scheelt de bezoeker typen en Andrea ziet meteen waar het over gaat. (aanbevolen)
|
||||
- B) Een gewone mailto zonder onderwerp
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
[Answer]: A
|
||||
|
||||
## Vraag 5: Waar komt de focus na "Boek …"?
|
||||
Na een klik op "Boek Newborn" scrollt de pagina naar Contact. De toetsenbordfocus staat dan nog op de knop bij Prijzen, buiten beeld: wie daarna op Tab drukt, springt terug omhoog.
|
||||
|
||||
- A) De focus gaat naar de kop "Contact" (onzichtbaar, zonder focusring). Toetsenbord- en schermlezergebruikers zitten dan op de juiste plek; de volgende Tab gaat naar het formulier, of nu naar de mailknop. (aanbevolen)
|
||||
- B) De focus gaat direct naar het keuzeveld "In welke shoot …" (of nu naar de mailknop)
|
||||
- C) Niets aan doen
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
[Answer]: A
|
||||
|
||||
## Vraag 6: Versturen mislukt (straks, met de API)
|
||||
|
||||
- A) Een melding boven de knop: "Versturen lukte niet. Probeer het later nog eens of mail naar info@andreaslop.nl", met het adres als mailto-link. Wat de bezoeker typte blijft staan. (aanbevolen)
|
||||
- B) Alleen "Versturen lukte niet. Probeer het later nog eens."
|
||||
- X) Anders (beschrijf hieronder na de [Answer]:-tag)
|
||||
|
||||
[Answer]: A (via contact-fd-clarification-questions.md)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# Functional Design Plan — Unit 5: Contact
|
||||
|
||||
Scope: FR-HP-06 (form), FR-HP-07 (coming-soon gate), FR-HP-08 (anti-spam, browser side), FR-HP-09 (robot-check slot), and BR-PARAM-02…04 from unit 3 (applying and removing `?pakket=`). Questions: [contact-fd-questions.md](contact-fd-questions.md).
|
||||
|
||||
Already fixed by requirements and earlier design (no question): fields Naam, E-mail, "In welke shoot heb je interesse?" (package names + Overig), "Stel hier je vraag"; button "(Aan)vraag versturen"; gate on by default via `siteContent.contactForm.enabled = false`, form dimmed and `inert`, notice "Het contactformulier komt binnenkort. Mail me voor nu op info@andreaslop.nl" with a mail button; address assembled in the browser; honeypot + ±3 s time check, spam gets the normal success and nothing is sent; `submitContactForm` adapter (rejects generically today); Friendly Captcha later; last "Boek" click wins; `?pakket=` removed from the URL once applied.
|
||||
|
||||
- [x] 1. Collect and analyze answers (follow-up questions if needed)
|
||||
- [x] 2. `domain-entities.md` — `ContactValues`, `ContactPayload`, `ContactErrors`, `ShootOption`, field limits, `siteContent.contactForm`
|
||||
- [x] 3. `business-rules.md` — validation rules and messages, when errors appear and disappear, spam rules, submit states (idle, sending, sent, failed), gate on/off, mail link, preselection and URL clean-up, focus after "Boek"; decision flowcharts
|
||||
- [x] 4. `business-logic-model.md` — submit sequence, the form state machine, pure functions (`shootOptions`, `validateContact`, `toContactPayload`, `isLikelySpam`, `mailtoLink`), PBT-01 properties incl. a stateful check of the form states (PBT-06)
|
||||
- [x] 5. `frontend-components.md` — `ContactSection`, `ContactFormGate`, `ContactForm`; props, states, layout, accessibility
|
||||
- [x] 6. Validate against FR-HP-06…09, BR-PARAM-02…04, NFR-HP-01/03/04 and the Security/PBT extensions
|
||||
Reference in New Issue
Block a user