"use client"; import React, { useState } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; const accountFormSchema = z.object({ name: z .string() .min(2, { message: "Name must be at least 2 characters.", }) .max(30, { message: "Name must not be longer than 30 characters.", }), dob: z.date({ required_error: "A date of birth is required.", }), language: z.string({ required_error: "Please select a language.", }), }); type AccountFormValues = z.infer; const defaultValues: Partial = { name: "Your name", dob: new Date("2000-01-01"), language: "en", }; const languages = [ { label: "English", value: "en" }, { label: "French", value: "fr" }, { label: "German", value: "de" }, { label: "Spanish", value: "es" }, { label: "Portuguese", value: "pt" }, { label: "Russian", value: "ru" }, { label: "Japanese", value: "ja" }, { label: "Korean", value: "ko" }, { label: "Chinese", value: "zh" }, ]; export function AccountForm() { const [showDatePicker, setShowDatePicker] = useState(false); const { control, handleSubmit } = useForm({ resolver: zodResolver(accountFormSchema), defaultValues, }); const onSubmit = (data: AccountFormValues) => { console.log(JSON.stringify(data, null, 2)); }; return (
(
onChange(e.target.value)} value={value} placeholder="Your name" />

This is the name that will be displayed on your profile and in emails.

)} /> (
{showDatePicker && ( { setShowDatePicker(false); if (e.target.value) { onChange(new Date(e.target.value)); } }} className="mt-1 p-1 border rounded" /> )}

Your date of birth is used to calculate your age.

)} /> (

This is the language that will be used in the dashboard.

)} />
); }