'use client' import { useState } from 'react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { FormRenderer } from '@/components/forms/form-renderer' import { submitForm } from '@/lib/actions' import type { FormField } from '@/lib/forms-schema' export function PublicFormClient({ formId, nextPath, title, description, kind, visibility, legalText, fields, authed, }: { formId: string nextPath: string title: string description: string | null kind: string visibility: string legalText: string | null fields: FormField[] authed: boolean }) { const [values, setValues] = useState>({}) const [email, setEmail] = useState('') const [consent, setConsent] = useState(false) const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) const [done, setDone] = useState(false) const needsSignIn = visibility === 'public_auth' && !authed const isWaiver = kind === 'waiver' const showEmail = visibility === 'public_anon' async function submit() { setError(null) setSubmitting(true) // Submit by formId: form slugs are only unique per space now, so id is // the unambiguous handle. const res = await submitForm({ formId, answers: values, email: showEmail && email ? email : undefined, consent: isWaiver ? consent : undefined, }) setSubmitting(false) if ('error' in res && res.error) { setError(res.error) return } setDone(true) } if (done) { return (

Thank you

Your response has been recorded.

) } return (

{title}

{description &&

{description}

}
{needsSignIn ? (

You need to be signed in to submit this form.

) : ( <> {isWaiver && legalText && (
{legalText}
)} setValues(p => ({ ...p, [k]: v }))} /> {showEmail && (
setEmail(e.target.value)} />

Used to link this to your account if you join later.

)} {isWaiver && ( )} {error &&

{error}

} )}
) }