import { zodResolver } from "@hookform/resolvers/zod"; import type { ThemeKey } from "@openstatus/theme-store"; import { Button } from "@openstatus/ui/components/ui/button"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@openstatus/ui/components/ui/form"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@openstatus/ui/components/ui/select"; import { isTRPCClientError } from "@trpc/client"; import { ArrowUpRight, Laptop, Moon, Sun } from "lucide-react"; import { useTransition } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { Link } from "@/components/common/link"; import { FormCard, FormCardContent, FormCardDescription, FormCardFooter, FormCardFooterInfo, FormCardHeader, FormCardTitle, } from "@/components/forms/form-card"; import { ThemePickerPopover } from "@/components/forms/status-page/theme-picker"; const schema = z.object({ forceTheme: z.enum(["light", "dark", "system"]), configuration: z.object({ theme: z.string(), }), }); type FormValues = z.infer; export function FormAppearance({ defaultValues, onSubmit, }: { defaultValues?: FormValues; onSubmit: (values: FormValues) => Promise; }) { const [isPending, startTransition] = useTransition(); const form = useForm({ resolver: zodResolver(schema), defaultValues: defaultValues ?? { forceTheme: "system", }, }); function submitAction(values: FormValues) { if (isPending) return; startTransition(async () => { try { const promise = onSubmit(values); toast.promise(promise, { loading: "Saving...", success: "Saved", error: (error) => { if (isTRPCClientError(error)) { return error.message; } return "Failed to save"; }, }); await promise; } catch (error) { console.error(error); } }); } return (
Appearance Forced theme will override the user's preference. ( Mode Override the user's preference. )} /> ( Style Choose a theme to apply. )} /> Your user will still be able to change the mode via the theme toggle.
); }