import { GetServerSidePropsContext } from "next"; import { useSession } from "next-auth/react"; import { Controller, useForm } from "react-hook-form"; import { APP_NAME } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Badge, Button, ColorPicker, Form, getSettingsLayout as getLayout, Meta, showToast, SkeletonButton, SkeletonContainer, SkeletonText, Switch, } from "@calcom/ui"; import { ssrInit } from "@server/lib/ssr"; const SkeletonLoader = ({ title, description }: { title: string; description: string }) => { return (
); }; const AppearanceView = () => { const { t } = useLocale(); const session = useSession(); const utils = trpc.useContext(); const { data: user, isLoading } = trpc.viewer.me.useQuery(); const formMethods = useForm({ defaultValues: { theme: user?.theme, brandColor: user?.brandColor || "#292929", darkBrandColor: user?.darkBrandColor || "#fafafa", hideBranding: user?.hideBranding, }, }); const { formState: { isSubmitting, isDirty }, } = formMethods; const mutation = trpc.viewer.updateProfile.useMutation({ onSuccess: async () => { await utils.viewer.me.invalidate(); showToast(t("settings_updated_successfully"), "success"); }, onError: () => { showToast(t("error_updating_settings"), "error"); }, }); if (isLoading) return ; if (!user) return null; const isDisabled = isSubmitting || !isDirty; return (
{ mutation.mutate({ ...values, // Radio values don't support null as values, therefore we convert an empty string // back to null here. theme: values.theme || null, }); }}>

{t("theme")}

{t("theme_applies_note")}


{t("custom_brand_colors")}

{t("customize_your_brand_colors")}

(

{t("light_brand_color")}

formMethods.setValue("brandColor", value, { shouldDirty: true })} />
)} /> (

{t("dark_brand_color")}

formMethods.setValue("darkBrandColor", value, { shouldDirty: true })} />
)} />
{/* TODO future PR to preview brandColors */} {/* */}
( <>

{t("disable_cal_branding", { appName: APP_NAME })}

{t("pro")}

{t("removes_cal_branding", { appName: APP_NAME })}

formMethods.setValue("hideBranding", checked, { shouldDirty: true }) } checked={!session.data?.user.belongsToActiveTeam ? false : value} />
)} /> ); }; AppearanceView.getLayout = getLayout; export const getServerSideProps = async (context: GetServerSidePropsContext) => { const ssr = await ssrInit(context); return { props: { trpcState: ssr.dehydrate(), }, }; }; export default AppearanceView; interface ThemeLabelProps { variant: "light" | "dark" | "system"; value?: "light" | "dark" | null; label: string; defaultChecked?: boolean; register: any; } const ThemeLabel = ({ variant, label, value, defaultChecked, register }: ThemeLabelProps) => { return ( ); };