Contact form on the Contact page
React · React · beginner · modification
Visitors kept asking for a way to write to us without opening their mail app, so the Contact page gets a form. `src/contact/ContactForm.jsx` (new) collects name, email and message and sends them to [email protected] through MailRelay, with the visitor's address as reply-to so support can answer straight from their inbox. While sending, the form is disabled and a status line under it says what happened. `src/pages/ContactPage.jsx` renders the form under a new "Send us a message" heading; the mailto link and the address stay. `src/contact/ContactForm.test.jsx` (new) tests the sent and failed states.
Marketing site for Acme Scheduling: a React 18.3 single-page app built with Vite 5 (`vite build` writes static files to `dist/`), function components with hooks. Tests run with `npm test`: Vitest 2 with @testing-library/react 16 in jsdom. CI builds the site and deploys `dist/` together with the site's small API server, `server/index.js` (Express 4, CommonJS, Node 22; existing and unchanged), which serves `dist/` and mounts its routes under `/api` behind `express.json()` and a per-IP rate limiter. The API server's environment holds `MAILER_API_KEY`; its newsletter signup route (`server/routes/newsletter.js`, an Express router mounted with `app.use('/api', ...)`) already calls MailRelay with it. MailRelay's send endpoint is `POST https://api.mailrelay.example/v1/messages` with `Authorization: Bearer <key>` and a JSON body `{ from, to, reply_to, subject, text }` (plain text, no HTML); it answers 202 when it accepts a message and allows requests from any origin (CORS). `[email protected]` is a verified sender. The form classes `field`, `field-label` and `button` come from the global `src/styles.css` (unchanged). Spam protection for the form is out of scope for this PR.
Requirements
- The Contact page (`ContactPage`) gets a contact form with Name, Email and Message fields, all three required (HTML `required`; Email is an email input, Name at most 100 characters, Message at most 5000). Submitting sends the message to [email protected] through MailRelay, our mail provider, with the visitor's address as the reply-to, so support can answer from their inbox.
- The MailRelay API key is a full-access server secret: whoever holds it can send mail as any `acme.example` address and read the account's contact lists. It must never reach the browser. It lives only in the API server's environment as `MAILER_API_KEY`, and only server code calls MailRelay with it.
- While the message is sending, the fields and the Send button are disabled and the status line says "Sending…". On success the form is cleared and the status line says "Thanks, your message was sent."; on any failure (a network error or a non-2xx answer) the fields keep what the visitor typed and it says "Sorry, your message could not be sent. Please try again or email [email protected]." The status line is one persistent `role="status"` element.
- Unchanged: the page heading, the `mailto:` link and the office address stay. The form has tests that run with the existing `npm test`.
Files touched
- src/pages/ContactPage.jsx
- src/contact/ContactForm.jsx
- src/contact/ContactForm.test.jsx