"use client"; import { useActionState, useId } from "react"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { completeOnboardingAction, type OnboardingState } from "./actions"; const initialOnboardingState: OnboardingState = { attempt: 0 }; export function OnboardingForm() { const [state, formAction, pending] = useActionState( completeOnboardingAction, initialOnboardingState, ); // Bumping the key on each attempt forces uncontrolled inputs to remount with // the echoed defaultValue from the server — otherwise React's
// semantics would wipe them after a failed submit. const attemptKey = state.attempt; const kitaError = state.errors?.kitaName?.[0]; const minError = state.errors?.notdienstMinPerChildPerMonth?.[0]; return ( {/* ----- Schritt 1: Name ----- */}
Schritt 1 · Grunddaten
{kitaError && ( )}
{/* ----- Schritt 2: Module ----- */}
Schritt 2 · Module aktivieren
{/* ----- Schritt 3: Notdienst-Regeln ----- */}
Schritt 3 · Notdienst-Regel
{!minError && (

Wie viele Tage müssen Eltern pro Monat als verfügbar markieren? Diesen Wert kannst du später jederzeit ändern.

)} {minError && ( )}
{state.errors?._form?.[0] && (

{state.errors._form[0]}

)}
); } function ModuleCheckbox({ name, label, description, defaultChecked, }: { name: string; label: string; description: string; defaultChecked?: boolean; }) { const id = useId(); const titleId = `${id}-title`; const descId = `${id}-desc`; return ( // The wrapping