Issue 230
tech-debt: Split the contact form block into headless hooks (robot check, submission state)
Back to our planOpen
frontendtech-debtpriority: low
Type
tech-debt
Summary
Split the contact form block into smaller parts, as #133 proposed: field rendering, submission state and the robot check.
Problem
src/modules/contact/ui/FormBlock.client.tsx is one component of about 125 lines (conventions.md: aim for functions under 50). It holds the submission state (status, error text, redirect), the four robot-check states (token, reset, blocked, failed) and the markup together. #133 (PR #228) moved it into the contact module as #223 left it, and extracted only the browser client (ui/api.ts); the split was left for this issue.
Proposed fix
- A headless
useRobotCheckhook inui/for the Turnstile token, its reset after a failure, and the blocked, failed and still-running states with their fixed messages. - A headless hook (for example
useFormSubmission) for the status, the fixed error text and the redirect after success, callingpostFormSubmission. FormBlockkeeps only the markup: intro,Form, the fields, the widget and the button.- No behaviour change: keep every #223 behaviour and test (fixed messages only, the token header and its reset after a failure, a body with only the form fields, text typed before hydration kept).
Acceptance criteria
- Not done:
FormBlockrenders only; the robot check and the submission state live in headless hooks insrc/modules/contact/ui/, each with tests. - Not done: Every existing
FormBlock.client.test.tsxcase still passes unchanged. - Not done: No function in the form block is over about 50 lines, and no file over 250.
- Not done:
/contactlooks and behaves the same (visual review at the six widths, light and dark).
Depends on
#133 (PR #228). Part of #127.
Area
frontend
Priority
low
Generated by Claude Code, opens in a new tab