'use client'; import { z } from "zod" import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" // Shadcn UI components import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Switch } from "@/components/ui/switch" // 1. Schema definition const formSchema = z.object({ email: z.string().email("Invalid email address."), role: z.string().min(1, "Please select a role."), // Rollenbezeichnung status: z.boolean().default(true), // Status (Active/Inactive) password: z.string().min(8, "Password must be at least 8 characters."), }) export type FormValues = z.infer export default function UserForm() { // 2. Initialize the form const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { email: "", role: "user", status: true, password: "", }, }) // 3. Define the submit handler function onSubmit(values: FormValues) { // All comments in code must be in English // Later we will connect this to a Server Action console.log("Form values:", values) } return (
{/* Email Field */} ( Email )} /> {/* Role Select Field */} ( Role (Rollenbezeichnung) )} /> {/* Status Switch Field */} (
Active Status
)} /> {/* Password Field */} ( Password )} /> ) }