import { useCallback, useEffect, useState } from "react"; import { ApiError, api, type ApprovalTask } from "../api"; export default function ApprovalsTab() { const [tasks, setTasks] = useState([]); const [approver, setApprover] = useState(""); const [note, setNote] = useState(""); const [error, setError] = useState(""); const [busyId, setBusyId] = useState(""); const load = useCallback(async () => { try { setTasks(await api.listApprovals()); } catch (e) { setError(e instanceof ApiError ? `${e.status}: ${e.message}` : String(e)); } }, []); useEffect(() => { void load(); }, [load]); async function decide(taskId: string, decision: "approve" | "reject") { setBusyId(taskId); setError(""); try { const result = await api.decide(taskId, decision, approver, note); setTasks((prev) => prev.map((t) => (t.id === taskId ? result.task : t)), ); } catch (e) { setError(e instanceof ApiError ? `${e.status}: ${e.message}` : String(e)); } finally { setBusyId(""); } } const open = tasks.filter((t) => t.status === "open"); const done = tasks.filter((t) => t.status !== "open"); return (

Freigaben

{error &&

{error}

}
setApprover(e.target.value)} placeholder="Name (Bearbeiter)" /> setNote(e.target.value)} placeholder="Notiz" style={{ flex: 1 }} />

Offen ({open.length})

{open.length === 0 &&

Keine offenen Freigaben.

}

Entschieden ({done.length})

); }