"use client" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { z } from "zod" import { useTheme } from "next-themes" import { toast } from "@/hooks/use-toast" import { Button } from "@/components/ui/button" import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" import { useMetaColor } from "@/hooks/use-meta-color" import { META_THEME_COLORS } from "@/config/site" import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Check, ChevronsUpDown } from "lucide-react" import { cn } from "@/lib/utils" import { useTranslation } from '@/i18n/client' import { useRouter, useParams, usePathname } from 'next/navigation'; const appearanceFormSchema = z.object({ theme: z.enum(["light", "dark"], { required_error: "Please select a theme.", }), language: z.string({ required_error: "Please select a language.", }), }) type AppearanceFormValues = z.infer // This can come from your database or API. const defaultValues: Partial = { theme: "light", language:'ko' } const languages = [ { label: "English", value: "en" }, { label: "한국어", value: "ko" }, ] as const export function AppearanceForm() { const { setTheme, resolvedTheme } = useTheme() const { setMetaColor } = useMetaColor() const pathname = usePathname(); const router = useRouter(); const params = useParams(); const lng = params.lng as string; const { t, i18n } = useTranslation(lng, 'translation'); const form = useForm({ resolver: zodResolver(appearanceFormSchema), defaultValues, }) function onSubmit(data: AppearanceFormValues) { setTheme(data.theme) setMetaColor( resolvedTheme === "dark" ? META_THEME_COLORS.light : META_THEME_COLORS.dark ) const segments = pathname.split('/'); segments[1] = data.language; router.push(segments.join('/')); toast({ title: "Updated Successfully", // description: ( //
//
{JSON.stringify(data, null, 2)}
//
// ), }) } return (
( Theme Customize the appearance of the app. Automatically switch between day and night themes.
Light
Dark )} /> ( Language No language found. {languages.map((language) => ( { form.setValue("language", language.value) }} > {language.label} ))} This is the language that will be used in the system. )} /> ) }