"use client"; import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { updateDocument, deleteDocument } from "@/app/admin/clients/[id]/actions"; import type { Document } from "@/db/schema"; export function DocumentRow({ doc, clientId, }: { doc: Document; clientId: string; }) { const [editing, setEditing] = useState(false); const [error, setError] = useState(null); const [, startTransition] = useTransition(); const router = useRouter(); function handleSave(fd: FormData) { setError(null); startTransition(async () => { try { await updateDocument(doc.id, clientId, fd); setEditing(false); router.refresh(); } catch (e) { setError(e instanceof Error ? e.message : "Errore nel salvataggio"); } }); } function handleDelete() { startTransition(async () => { await deleteDocument(doc.id, clientId); router.refresh(); }); } if (editing) { return (
{error &&

{error}

}
); } return (
{doc.label}
); }