import { useEffect, useMemo, useRef } from 'react'; import type { ReactNode } from 'react'; import { useContactForm, type ContactClient, type ContactToken, type SubjectOption, type TokenResult, } from '../../cms-client/contact'; import { contactForm, contactInfo } from '../../features/landing/data/content'; import { usePackagesQuery } from '../../features/landing/hooks/usePackagesQuery'; import { trackEvent } from '../../shared/analytics/trackEvent'; import { useContactPreselect } from '../../shared/contact/useContactPreselect'; import { terminalText } from './eraContent'; interface TerminalFormProps { client: ContactClient; token: ContactToken; refreshToken: () => Promise; } function Row({ label, dots, error, errorId, children, }: { label: string; dots: string; error: string | null; errorId: string; children: ReactNode; }) { return (
{error ? ( {error} ) : null}
); } /** The 1989 terminal skin of the contact form, on the same logic as design B (useContactForm). */ export function TerminalForm({ client, token, refreshToken }: TerminalFormProps) { const { data: packages } = usePackagesQuery(); const preselect = useContactPreselect(); const subjectOptions = useMemo( () => [ ...(packages ?? []).map((pkg) => ({ value: pkg.slug, label: pkg.title })), { value: 'other', label: contactForm.otherSubjectLabel }, ], [packages], ); const form = useContactForm({ idPrefix: 'contact', subjectOptions, preselect: { subject: preselect.subject, key: preselect.key }, client, token, refreshToken, fallbackAddress: contactInfo.email, onEvent: (event) => trackEvent(event === 'sent' ? 'contact-sent' : 'contact-failed'), }); const successRef = useRef(null); useEffect(() => { if (form.status === 'sent') { successRef.current?.focus(); } }, [form.status]); if (form.status === 'sent') { return (

{terminalText.sentLine1}

{terminalText.sentLine2}

); } const name = form.getFieldProps('name'); const email = form.getFieldProps('email'); const subject = form.getFieldProps('subject'); const message = form.getFieldProps('message'); const { id: hpId, ...hpProps } = form.honeypotProps; return (