"use client"; import { useRouter } from "next/navigation"; import { useState, type FormEvent } from "react"; import { apiFetch, errorMessage } from "@/lib/client-api"; export function AddHolidayForm() { const router = useRouter(); const [day, setDay] = useState(""); const [name, setName] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); async function submit(e: FormEvent) { e.preventDefault(); setBusy(true); setError(""); try { await apiFetch("/holidays", { method: "POST", body: { day, name, source: "manual" } }); setDay(""); setName(""); router.refresh(); } catch (err) { setError(errorMessage(err)); } finally { setBusy(false); } } return (
{error &&

{error}

}
); }