A React hook that manages contact form submission state, including loading/success tracking, toast notifications, and post-submission redirect logic. ## Key Components ### `ContactSubmissionOptions` Configuration interface for the hook: - `userId` – Optional authenticated user ID appended to the payload - `successRedirectUrl` – URL to navigate to after successful submission (1.5s delay) - `successToastMessage` – Custom suffix appended to the default success toast - `onSuccess` – Optional callback fired on successful submission ### `ContactFormData` Mirrors the `ContactBaseSchema` on the `POST /api/contact` endpoint. Core fields (`name`, `email`, `helpCategory`, `message`) are required; tracking fields (`rdt_cid`, `utm_*`, `referrer_url`) and future per-form fields pass through via the permissive `[key: string]: unknown` index signature. ### `useContactSubmission(options)` The exported hook. Resolves the endpoint URL via `useRequiredEndpointsRuntime` (throws if no provider is mounted), then exposes: | Return | Type | Description | |---|---|---| | `submit` | `(formData) => Promise` | Sends `POST` with form data; re-throws on error | | `isSubmitting` | `boolean` | True while request is in-flight | | `isSuccess` | `boolean` | True after a successful response | | `setIsSuccess` | `Dispatch` | Allows caller to reset success state | ## Usage Example ```typescript import { useContactSubmission } from './use-contact-submission'; function ContactForm() { const { submit, isSubmitting, isSuccess } = useContactSubmission({ userId: currentUser?.id, successRedirectUrl: '/thank-you', successToastMessage: 'We will get back to you within 24 hours.', onSuccess: () => analytics.track('contact_submitted'), }); const handleSubmit = async (formData: ContactFormData) => { try { await submit({ name: formData.name, email: formData.email, helpCategory: 'support', message: formData.message, // Tracking fields forwarded transparently rdt_cid: getRedditClickId(), }); } catch { // Error toast is shown automatically; handle UI reset here if needed } }; return ; } ``` ## Notes - Redirect uses `window.location.href` for absolute URLs and `router.push` for relative paths - Guards against duplicate submissions via `isSubmitting` check at the top of `submit` - Endpoint URL is injected via context, making the hook compatible with both hub and embedded/proxied deployments **Source:** [`use-contact-submission.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/use-contact-submission.ts)