"use client"; import { useActionState } 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 { registerAction, type RegisterState } from "./actions"; const initialRegisterState: RegisterState = { attempt: 0 }; export function RegisterForm() { const [state, formAction, pending] = useActionState( registerAction, initialRegisterState, ); // Bumping the key on each attempt forces uncontrolled inputs to remount with // the echoed defaultValue from the server — otherwise React's
); } function FormField({ id, name, label, type = "text", required, autoComplete, helperText, defaultValue, error, }: { id: string; name: string; label: string; type?: string; required?: boolean; autoComplete?: string; helperText?: string; defaultValue?: string; error?: string; }) { const errorId = error ? `${id}-error` : undefined; const helperId = !error && helperText ? `${id}-helper` : undefined; return ({error}
) : helperText ? ({helperText}
) : null}