"use client"; import { useState, useTransition } from "react"; import { format } from "date-fns"; import { de } from "date-fns/locale"; import { NotdienstPlanStatus } from "@prisma/client"; import { Loader2, Wand2, CheckSquare } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { generatePlanAction, publishPlanAction, updateAssignmentAction, } from "./actions"; interface PlanViewProps { planId?: string; status?: NotdienstPlanStatus; days: { date: string; // ISO assignmentId: string | null; childId: string | null; }[]; allChildren: { id: string; name: string; parentName: string; }[]; } export function PlanView({ planId, status, days, allChildren }: PlanViewProps) { const [isPending, startTransition] = useTransition(); const handleGenerate = () => { startTransition(async () => { const result = await generatePlanAction(); if ("error" in result && result.error) { toast.error(result.error as string); } else { toast.success("Plan erfolgreich generiert."); } }); }; const handlePublish = () => { if (!planId) return; startTransition(async () => { const result = await publishPlanAction(planId); if ("error" in result && result.error) { toast.error(result.error as string); } else { toast.success("Plan veröffentlicht! Er ist nun fix."); } }); }; const handleAssignmentChange = (date: string, newChildId: string) => { if (!planId || status !== "DRAFT") return; const valueToSet = newChildId === "empty" ? null : newChildId; startTransition(async () => { const result = await updateAssignmentAction(planId, date, valueToSet); if ("error" in result && result.error) { toast.error(result.error as string); } else { toast.success("Zuteilung aktualisiert."); } }); }; if (!planId) { return (
Generiere den Plan basierend auf den Verfügbarkeiten der Eltern automatisch.