"use client"; import { useState, type FormEvent } from "react"; import { useRouter } from "next/navigation"; const fieldClass = "w-full rounded-2xl border border-anouma-taupe/30 bg-white px-5 py-3.5 text-base text-anouma-plum placeholder:text-anouma-plum/50 focus:border-anouma-mauve-dark focus:outline-none"; export function ProfileForm({ id, name, phone }: { id: number; name: string; phone: string }) { const router = useRouter(); const [status, setStatus] = useState<"idle" | "saving" | "saved" | "error">("idle"); async function handleSubmit(e: FormEvent) { e.preventDefault(); setStatus("saving"); const data = new FormData(e.currentTarget); const res = await fetch(`/api/customers/${id}`, { method: "PATCH", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: String(data.get("name") ?? ""), phone: String(data.get("phone") ?? "") || null, }), }); if (res.ok) { setStatus("saved"); router.refresh(); } else { setStatus("error"); } } return (
{status === "saved" &&

Gespeichert.

} {status === "error" &&

Speichern fehlgeschlagen.

}
); }