'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import Link from 'next/link' import { createPolicy } from '@/lib/actions' export function NewPolicyForm() { const router = useRouter() const [slug, setSlug] = useState('') const [title, setTitle] = useState('') const [sectionRef, setSectionRef] = useState('') const [bodyFormal, setBodyFormal] = useState('') const [bodyPlain, setBodyPlain] = useState('') const [error, setError] = useState('') const [submitting, setSubmitting] = useState(false) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setSubmitting(true) setError('') const result = await createPolicy({ slug, title, section_ref: sectionRef || null, body_formal: bodyFormal, body_plain: bodyPlain || null, }) if ('error' in result && result.error) { setError(result.error) setSubmitting(false) return } router.push(`/policies/${slug}`) } return (
setSlug(e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, ''))} maxLength={80} required pattern="[a-z0-9-]+" className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary" placeholder="bylaws" />
setSectionRef(e.target.value)} maxLength={80} className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary" placeholder="Article III ยง2" />
setTitle(e.target.value)} maxLength={200} required className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary" placeholder="Bylaws" />