import { z } from 'zod' import { useFieldArray, useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { Link } from '@tanstack/react-router' import { cn } from '@/lib/utils' import { showSubmittedData } from '@/utils/show-submitted-data' import { Button } from '@/components/ui/button' import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form' import { Input } from '@/components/ui/input' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Textarea } from '@/components/ui/textarea' const profileFormSchema = z.object({ username: z .string() .min(2, { message: 'Username must be at least 2 characters.', }) .max(30, { message: 'Username must not be longer than 30 characters.', }), email: z .string({ required_error: 'Please select an email to display.', }) .email(), bio: z.string().max(160).min(4), urls: z .array( z.object({ value: z.string().url({ message: 'Please enter a valid URL.' }), }) ) .optional(), }) type ProfileFormValues = z.infer // This can come from your database or API. const defaultValues: Partial = { bio: 'I own a computer.', urls: [ { value: 'https://shadcn.com' }, { value: 'http://twitter.com/shadcn' }, ], } export default function ProfileForm() { const form = useForm({ resolver: zodResolver(profileFormSchema), defaultValues, mode: 'onChange', }) const { fields, append } = useFieldArray({ name: 'urls', control: form.control, }) return (
showSubmittedData(data))} className='space-y-8' > ( Username This is your public display name. It can be your real name or a pseudonym. You can only change this once every 30 days. )} /> ( Email You can manage verified email addresses in your{' '} email settings. )} /> ( Bio