import { z } from 'zod' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { showSubmittedData } from '@/utils/show-submitted-data' import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/checkbox' import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form' const items = [ { id: 'recents', label: 'Recents', }, { id: 'home', label: 'Home', }, { id: 'applications', label: 'Applications', }, { id: 'desktop', label: 'Desktop', }, { id: 'downloads', label: 'Downloads', }, { id: 'documents', label: 'Documents', }, ] as const const displayFormSchema = z.object({ items: z.array(z.string()).refine((value) => value.some((item) => item), { message: 'You have to select at least one item.', }), }) type DisplayFormValues = z.infer // This can come from your database or API. const defaultValues: Partial = { items: ['recents', 'home'], } export function DisplayForm() { const form = useForm({ resolver: zodResolver(displayFormSchema), defaultValues, }) return (
showSubmittedData(data))} className='space-y-8' > (
Sidebar Select the items you want to display in the sidebar.
{items.map((item) => ( { return ( { return checked ? field.onChange([...field.value, item.id]) : field.onChange( field.value?.filter( (value) => value !== item.id ) ) }} /> {item.label} ) }} /> ))}
)} /> ) }