diff --git a/app/liste/page.tsx b/app/liste/page.tsx index 6da26dc..9cac740 100644 --- a/app/liste/page.tsx +++ b/app/liste/page.tsx @@ -30,6 +30,32 @@ export default function ListePage() { fetchAppointments(); }, []); + // Statuswechsel (erledigt) direkt aus der Liste, mit optimistischem Update. + const toggleDone = async (id: string) => { + const current = appointments.find((a) => a.id === id); + if (!current) return; + const newStatus = !current.erledigt; + setAppointments((prev) => + prev.map((a) => (a.id === id ? { ...a, erledigt: newStatus } : a)) + ); + try { + const res = await fetch(`/api/appointments/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ erledigt: newStatus }), + }); + if (!res.ok) throw new Error('Fehler beim Statuswechsel.'); + } catch (error) { + console.error('Fehler beim Statuswechsel:', error); + // Rückgängig machen bei Fehler + setAppointments((prev) => + prev.map((a) => + a.id === id ? { ...a, erledigt: current.erledigt } : a + ) + ); + } + }; + return (
@@ -37,7 +63,10 @@ export default function ListePage() { {isLoading ? (
Lade Daten...
) : ( - + )}