- components/forms/form-renderer.tsx: one controlled renderer for all 8 field types, shared by the builder preview and the public page - components/forms/form-builder.tsx: easy builder — label-only field creation (keys auto-derived and de-duped at save), one-click type buttons, up/down reordering, inline options editor, live preview; edit mode adds publish/close/draft/delete and copy-public-link - /forms directory, /forms/new, /forms/[id]/edit, /forms/[id]/results (CSV download). Server-gated by lib/forms-guard.ts (forms.manage via the same RPC the RLS uses; RLS remains the real boundary) - public app/f/[slug] (outside the app group): getPublicForm serves only published public forms — members-only forms are never exposed there; waiver consent, anon email capture, signed-in gate for public_auth, thank-you state - sidebar "Forms & waivers" link; sonner toasts (codebase convention) - ARCHITECTURE + HANDOFF updated 285/285 tests, build clean, all four routes compiled. No deploy.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { notFound } from 'next/navigation'
|
|
import { requireFormsManagerPage } from '@/lib/forms-guard'
|
|
import { PageHeader, PageTitle } from '@/components/ui/page-title'
|
|
import { FormBuilder } from '@/components/forms/form-builder'
|
|
import { parseFormSchema } from '@/lib/forms-schema'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export default async function EditFormPage({ params }: { params: Promise<{ id: string }> }) {
|
|
const { id } = await params
|
|
const { supabase, member } = await requireFormsManagerPage()
|
|
|
|
const { data: form } = await supabase
|
|
.from('forms')
|
|
.select('id, slug, title, description, kind, visibility, status, legal_text, schema, space_id')
|
|
.eq('id', id)
|
|
.eq('space_id', member.space_id)
|
|
.single()
|
|
|
|
if (!form) notFound()
|
|
|
|
return (
|
|
<>
|
|
<PageHeader>
|
|
<PageTitle>Edit form</PageTitle>
|
|
</PageHeader>
|
|
<div className="p-4 md:p-6">
|
|
<FormBuilder
|
|
initial={{
|
|
id: form.id,
|
|
slug: form.slug,
|
|
title: form.title,
|
|
description: form.description ?? '',
|
|
kind: form.kind as 'form' | 'waiver',
|
|
visibility: form.visibility as 'public_anon' | 'public_auth' | 'members',
|
|
legal_text: form.legal_text ?? '',
|
|
status: form.status as 'draft' | 'published' | 'closed',
|
|
schema: parseFormSchema(form.schema),
|
|
}}
|
|
/>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|