import { useState, type FormEvent } from "react"; import InlineError from "@/lib/InlineError"; import type { Blocklist, BlocklistInput } from "@/lib/types"; import { buttonClass, focusRing, inputClass, primaryButtonClass } from "@/ui/classes"; interface BlocklistFormProps { initial?: Blocklist; busy: boolean; error: Error | null; onSubmit: (input: BlocklistInput) => Promise; onCancel?: () => void; } export default function BlocklistForm({ initial, busy, error, onSubmit, onCancel }: BlocklistFormProps) { const [url, setUrl] = useState(initial?.url ?? ""); const [name, setName] = useState(initial?.name ?? ""); const [enabled, setEnabled] = useState(initial?.enabled ?? true); async function handleSubmit(event: FormEvent) { event.preventDefault(); try { await onSubmit({ url: url.trim(), name: name.trim(), enabled }); if (initial === undefined) { setUrl(""); setName(""); setEnabled(true); } } catch { // The page renders the mutation error inline below the form. } } return (

{initial === undefined ? "Add source" : `Edit ${initial.name}`}

setUrl(event.target.value)} className={inputClass} />
setName(event.target.value)} className={inputClass} />
{onCancel !== undefined && ( )}
); }