Files
Moheeb Zara 73eef7293a feat(forms): obvious publish flow, member Forms surface, templates (P8)
- builder: draft/published/closed status banners; creating a form now
  lands on its edit page so Publish is immediately visible; a
  members-only form shows a "no public link" note instead of a dead URL
- member-facing forms: /my-forms list + /my-forms/[id] fill
  (MemberFillClient), "Forms" sidebar item for all members. Fixes the
  long-standing gap where members-only forms had no fill surface
- starter templates: lib/form-templates.ts + a picker on /forms/new
  (Liability waiver, Membership application, Event RSVP, Photo release,
  Blank) that seeds builder state (no table)
- forms-client relabels members-only forms (was showing a misleading
  /f/<space>/<slug> that always 404s for members-only)
- docs corrected per the audit pass: DATABASE_SCHEMA / DB_SCHEMA_MAP /
  ARCHITECTURE / API_REFERENCE now reflect migrations 014-029, per-space
  slug, /f/[space]/[slug], getPublicForm({space,slug}), invite roles;
  HANDOFF pass-19 added with residual gaps

337 tests; build verified (Compiled successfully, exit 0). No deploy.
2026-05-16 17:41:16 -07:00

65 lines
2.0 KiB
TypeScript

'use client'
import { useState } from 'react'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import { FORM_TEMPLATES, type FormTemplate } from '@/lib/form-templates'
import { FormBuilder } from './form-builder'
// Template chooser shown first on /forms/new. Picking a template just seeds
// builder state (no DB row until the builder saves).
export function NewFormClient({ spaceSlug }: { spaceSlug: string }) {
const [tpl, setTpl] = useState<FormTemplate | null>(null)
if (tpl) {
return (
<div className="space-y-4">
<button
onClick={() => setTpl(null)}
className="text-sm text-muted-foreground hover:text-foreground"
>
← Choose a different template
</button>
<FormBuilder
initial={{
spaceSlug,
slug: '',
title: tpl.id === 'blank' ? '' : tpl.name,
description: '',
kind: tpl.kind,
visibility: 'members',
legal_text: tpl.legal_text,
schema: tpl.schema,
}}
/>
</div>
)
}
return (
<div className="space-y-4">
<p className="text-sm text-muted-foreground">
Start from a template or a blank form. You can change everything afterwards.
</p>
<div className="grid gap-3 sm:grid-cols-2">
{FORM_TEMPLATES.map(t => (
<button
key={t.id}
onClick={() => setTpl(t)}
className="rounded-lg border p-4 text-left transition hover:border-primary"
>
<div className="flex items-center gap-2">
<span className="font-medium">{t.name}</span>
{t.kind === 'waiver' && <Badge variant="secondary">Waiver</Badge>}
</div>
<p className="mt-1 text-sm text-muted-foreground">{t.blurb}</p>
</button>
))}
</div>
<Button variant="ghost" onClick={() => setTpl(FORM_TEMPLATES[0])}>
Skip — start blank
</Button>
</div>
)
}