"use client" import Link from "next/link" import { zodResolver } from "@hookform/resolvers/zod" import { useFieldArray, useForm } from "react-hook-form" import { z } from "zod" import { cn } from "@/lib/utils" import { toast } from "@/hooks/useToast" 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 function ProfileForm() { const form = useForm({ resolver: zodResolver(profileFormSchema), defaultValues, mode: "onChange", }) const { fields, append } = useFieldArray({ name: "urls", control: form.control, }) function onSubmit(data: ProfileFormValues) { toast({ title: "You submitted the following values:", description: (
          {JSON.stringify(data, null, 2)}
        
), }) } return (
( 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