import { z } from 'zod' import { useForm } from 'react-hook-form' import { ChevronDownIcon } from '@radix-ui/react-icons' import { zodResolver } from '@hookform/resolvers/zod' import { fonts } from '@/config/fonts' import { cn } from '@/lib/utils' import { showSubmittedData } from '@/utils/show-submitted-data' import { useFont } from '@/context/font-context' import { useTheme } from '@/context/theme-context' import { Button, buttonVariants } from '@/components/ui/button' import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form' import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group' const appearanceFormSchema = z.object({ theme: z.enum(['light', 'dark'], { required_error: 'Please select a theme.', }), font: z.enum(fonts, { invalid_type_error: 'Select a font', required_error: 'Please select a font.', }), }) type AppearanceFormValues = z.infer export function AppearanceForm() { const { font, setFont } = useFont() const { theme, setTheme } = useTheme() // This can come from your database or API. const defaultValues: Partial = { theme: theme as 'light' | 'dark', font, } const form = useForm({ resolver: zodResolver(appearanceFormSchema), defaultValues, }) function onSubmit(data: AppearanceFormValues) { if (data.font != font) setFont(data.font) if (data.theme != theme) setTheme(data.theme) showSubmittedData(data) } return (
( Font
Set the font you want to use in the dashboard.
)} /> ( Theme Select the theme for the dashboard.
Light
Dark )} /> ) }