'use client' import { zodResolver } from '@hookform/resolvers/zod' import { Check } from 'lucide-react' import { useState } from 'react' import { useForm } from 'react-hook-form' import { toast } from 'sonner' import { Button, ComboboxTrigger, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Popover, PopoverContent, PopoverTrigger, } from 'ui' import { z } from 'zod' import { cn } from '@/lib/utils' 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' }, ] as const const FormSchema = z.object({ language: z.string({ required_error: 'Please select a language.', }), }) export default function ComboboxForm() { const [open, setOpen] = useState(false) const form = useForm>({ resolver: zodResolver(FormSchema), }) function onSubmit(data: z.infer) { toast('You submitted the following values:', { description: (
          {JSON.stringify(data, null, 2)}
        
), }) } return (
( Language {field.value ? languages.find((language) => language.value === field.value)?.label : 'Select language'} No language found. {languages.map((language) => ( { form.setValue('language', language.value) setOpen(false) }} > {language.label} ))} This is the language that will be used in the dashboard. )} /> ) }