"use client"; import { useActionState, useState } from "react"; import { Plus, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { addFamilyAction, type AddFamilyState } from "./actions"; const initialState: AddFamilyState = {}; // ===================================================================== // AddFamilyDialog · Client Component // --------------------------------------------------------------------- // Verwaltet: // • Dialog-Open/Close-State // • Dynamische Kinderliste (min. 1, max. 10) // • Ein oder zwei Elternteile pro Haushalt // • useActionState → Server-Action-Fehler anzeigen // • Bei Erfolg (state.success) Dialog automatisch schließen // ===================================================================== export function AddFamilyDialog() { const [open, setOpen] = useState(false); const [childCount, setChildCount] = useState(1); const [state, formAction, pending] = useActionState( addFamilyAction, initialState, ); // Dialog schließen, wenn die Action erfolgreich war if (state.success && open) { setOpen(false); } function handleOpenChange(nextOpen: boolean) { setOpen(nextOpen); // State beim Schließen zurücksetzen würde useActionState erfordern — // stattdessen schließen wir einfach und der State bleibt bis zur nächsten // Aktion erhalten (unkritisch). } return ( ); } // ── Hilfskomponente ──────────────────────────────────────────────────── function FormField({ id, name, label, type = "text", autoComplete, placeholder, required = true, error, }: { id: string; name: string; label: string; type?: string; autoComplete?: string; placeholder?: string; required?: boolean; error?: string; }) { return (
{error}
}