"use client"; import React, { useEffect, useMemo, useState } from "react"; import { useAuth } from "@/hooks/useAuth"; import { useRouter } from "next/navigation"; import { apiFetch, fetchAllUsers } from "@/lib/api"; import { useDismissingState } from "@/hooks/useDismissingState"; type FormFieldType = 'yes_no' | 'text' | 'date' | 'numeric' | 'statement' | 'paragraph'; type EventFormDef = { isRequired: boolean; fields: { id?: string; type: FormFieldType; label: string; isRequired?: boolean; order?: number; helpText?: string|null; options?: any }[] }; function FormBuilder({ value, onChange }: { value: EventFormDef; onChange: (v: EventFormDef) => void }) { const fields = value.fields || []; const addField = (type: FormFieldType = 'text') => { onChange({ ...value, fields: [...fields, { type, label: '', isRequired: false, helpText: '' }] }); }; const updateField = (idx: number, patch: Partial) => { const copy = fields.slice(); copy[idx] = { ...copy[idx], ...patch }; onChange({ ...value, fields: copy }); }; const removeField = (idx: number) => { const copy = fields.slice(); copy.splice(idx, 1); onChange({ ...value, fields: copy }); }; const moveField = (idx: number, dir: -1 | 1) => { const copy = fields.slice(); const target = idx + dir; if (target < 0 || target >= copy.length) return; [copy[idx], copy[target]] = [copy[target], copy[idx]]; onChange({ ...value, fields: copy }); }; const typeLabel = (type: FormFieldType) => { const labels: Record = { text: 'Text', numeric: 'Number', date: 'Date', yes_no: 'Yes/No', statement: 'Statement', paragraph: 'Heading' }; return labels[type] || type; }; return (
Registration Form Fields
{fields.length === 0 ? (
No fields yet — add questions below.
) : (
    {fields.map((f, idx) => (
  • {typeLabel(f.type)} #{idx + 1}
    {f.type !== 'statement' && f.type !== 'paragraph' && ( )}
    updateField(idx, { label: e.target.value })} /> {f.type === 'paragraph' ? (