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>
4.4 KiB
Business Logic Model — Unit 5: Contact
Submit sequence
sequenceDiagram
box rgba(246,224,94,0.4) Visitor
participant V as Visitor
end
box rgba(99,179,237,0.4) Homepage
participant F as ContactForm
participant L as PureHelpers
participant A as SubmitAdapter
end
V->>F: Clicks the send button
F->>L: validateContact with the values and options
L-->>F: Errors per field, or none
F->>L: isLikelySpam with honeypot and elapsed time
L-->>F: Spam or not
F->>A: submitContactForm with the trimmed payload
A-->>F: Resolved or rejected
F-->>V: Thank-you message, or failure message with mail link
Text alternative: on submit the form validates, checks for spam, sends the trimmed payload through the single adapter, and shows the thank-you or the failure message.
Form state (a pure reducer)
The form's behaviour is a pure reducer contactFormReducer(state, event), so it can be tested as a state machine (PBT-06) independently of React.
graph LR
Editing["editing"] -->|"submit, invalid"| Editing
Editing -->|"submit, spam"| Sent["sent"]
Editing -->|"submit, valid"| Sending["sending"]
Sending -->|"resolved"| Sent
Sending -->|"rejected"| Failed["failed"]
Failed -->|"edit or blur"| Failed
Failed -->|"submit, valid"| Sending
classDef state fill:#63b3ed,stroke:#2b6cb0,stroke-width:1px,color:#000;
classDef final fill:#9ae6b4,stroke:#2f855a,stroke-width:1px,color:#000;
class Editing,Sending,Failed state;
class Sent final;
Text alternative: the form is editing until a submit; an invalid submit stays in editing (with errors), spam goes straight to sent, a valid submit goes to sending, which ends in sent or failed; from failed, a valid submit sends again.
State: { status: 'editing' | 'sending' | 'sent' | 'failed'; values; touched: Set of fields; errors }
Events: edit(field, value), blur(field), preselect(shoot), submit({ now, shownAt, honeypot }), resolved, rejected.
Pure functions (web/src/lib/)
| Function | Purpose | Rules |
|---|---|---|
shootOptions(packages) |
shown packages + Overig | domain-entities.md |
validateField(field, values, options) |
first failing message for one field, or undefined | BR-FORM-01…07 |
validateContact(values, options) |
errors for all fields | BR-FORM-01…07 |
toContactPayload(values) |
trimmed payload | BR-SEND-01 |
isLikelySpam({ honeypot, shownAt, now }) |
honeypot or under 3000 ms | BR-SPAM-01 |
mailSubject(packageName?) |
"Aanvraag fotoshoot: X" or "Vraag via andreaslop.nl" | BR-MAIL-01 |
mailtoLink(address, subject) |
mailto: with encoded subject |
BR-MAIL-01 |
contactFormReducer(state, event) |
the state machine above | BR-FORM-10…12, BR-SEND-01…04, BR-SPAM-02 |
Testable properties (PBT-01)
| Function | Category | Property |
|---|---|---|
shootOptions |
Invariant | Last option is Overig; the others are the packages' ids and names in order |
validateContact |
Oracle | For generated valid values there are no errors |
validateContact |
Invariant | Emptying any one required field gives exactly that field's "required" message |
validateContact |
Invariant | Exceeding a limit gives that field's "te lang" message |
validateContact |
Oracle | E-mail error ⇔ the trimmed value fails the format regex (for non-empty, short values) |
toContactPayload |
Idempotency | Making a payload of a payload changes nothing; no field has outer whitespace |
isLikelySpam |
Oracle | Equals honeypot !== '' || now - shownAt < 3000 |
mailtoLink |
Round-trip | Decoding the subject parameter gives back the subject; the link starts with mailto:<address>? |
mailSubject |
Invariant | Contains the package name when given, otherwise the general subject |
contactFormReducer |
Stateful (PBT-06) | For random event sequences: status only moves along the allowed transitions; sending only after a valid, non-spam submit; values never change while sending; errors never show for an untouched field unless a submit happened; after sent nothing changes |
Generators (PBT-07): valid contactValues (realistic names, e-mails from the existing validEmail, a shoot from the options, messages up to the limit), anyContactValues (empty, whitespace, overlong, bad e-mails), and event sequences for the reducer (fc.commands or a list of events).