Terms of Service checkbox on the signup form
React · React · beginner · modification
Legal asked for an explicit Terms of Service and Privacy Policy acceptance at signup. `src/signup/SignupForm.jsx` adds an `agreed` state and a checkbox whose label links to both documents (opening in a new tab), includes the box's state in the signup as `acceptedTerms`, and takes it into account when deciding whether Create account is enabled. `src/signup/SignupForm.css` lays the checkbox and its label out side by side. `src/signup/SignupForm.test.jsx` updates the existing tests to tick the box and adds one that checks the payload sent to `onSubmit`.
Marketing-site signup on React 18.3 (Vite, function components). Tests run with `npm test`: Vitest 2 with @testing-library/react 16 in jsdom. Existing and unchanged: `SignupPage.jsx` renders `<SignupForm onSubmit={signup} />`. `signup(values)` POSTs `values` as the JSON body of `/api/signup` and resolves once the API has created the account and emailed a sign-in link (the page then navigates to `/check-email` itself, which can unmount the form); it rejects with an `Error` on any failure, including the API's 400 for an empty or malformed email. The API stores `acceptedTerms` with the request time as the user's consent record and creates the account whatever its value: it does not check the flag (a server-side check is a separate ticket), so the form is the only gate. `/terms` and `/privacy` are static pages of the same site.
Requirements
- The signup form (`SignupForm`) gains a checkbox labelled "I agree to the Terms of Service and the Privacy Policy", with the two names linking to `/terms` and `/privacy` in a new tab (so the email already typed stays in the form). The box starts unticked.
- **Create account** is enabled only when both of these hold: the email field is not empty (surrounding spaces ignored) and the terms box is ticked. Unticking the box or clearing the email disables it again. While a signup request is in flight it stays disabled, as before.
- On submit the form calls `onSubmit({ email, acceptedTerms })` with the trimmed email and the box's state. Legal requires that no account is created without the box ticked, and the form is where that consent is collected.
- Unchanged: the email field (label "Work email", `type="email"`); the button reads "Creating account…" while a request is in flight; when `onSubmit` rejects, the message "We could not create your account. Please try again." appears in the alert below the button and the button is enabled again.
Files touched
- src/signup/SignupForm.jsx
- src/signup/SignupForm.css
- src/signup/SignupForm.test.jsx