// SPDX-FileCopyrightText: 2026 Paul Schoeneck // // SPDX-License-Identifier: AGPL-3.0-only AND LicenseRef-KIBU-Additional-Terms "use client"; import { useState, useTransition } from "react"; import { Check, ShieldCheck } from "lucide-react"; import { correctAttendance, saveAloneRules, saveContact } from "@/app/profile-actions"; import type { AloneRule, AttendanceRecord, PickupContact } from "@/lib/profile"; import { displayDay, timeInZone } from "@/lib/time"; import type { ActionResult } from "@/lib/validation"; import { Modal } from "./modal"; export const weekdayNames = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"]; function useSave(onSaved: (message: string) => void) { const [error, setError] = useState(""); const [pending, startTransition] = useTransition(); function run(action: () => Promise, message: string) { setError(""); startTransition(async () => { try { const result = await action(); if (result.error) setError(result.error); else onSaved(message); } catch (error) { console.error("Profil speichern", error); setError("Speichern fehlgeschlagen. Bitte die Verbindung prüfen und erneut versuchen."); } }); } return { error, pending, run }; } function FormFooter({ pending, onClose, label = "Speichern" }: { pending: boolean; onClose: () => void; label?: string; }) { return ; } export function CorrectionForm({ childId, record, timeZone, onClose, onSaved }: { childId: string; record: AttendanceRecord; timeZone: string; onClose: () => void; onSaved: (message: string) => void; }) { const [status, setStatus] = useState(record.status); const { error, pending, run } = useSave(onSaved); return
{ event.preventDefault(); const form = new FormData(event.currentTarget); run(() => correctAttendance({ childId, day: record.day, status, arrival: form.get("arrival") ?? "", pickup: form.get("pickup") ?? "", pickupKind: form.get("pickupKind") ?? "planned", reason: form.get("reason"), expectedVersion: record.version, }), "Anwesenheit korrigiert und im Audit-Log dokumentiert."); }}>
{(status === "arrived" || status === "picked_up") &&
{status === "picked_up" && }
} {status === "picked_up" && }