diff --git a/apps/web/pages/settings/my-account/appearance.tsx b/apps/web/pages/settings/my-account/appearance.tsx index 5642b61c00..9da3eed0b2 100644 --- a/apps/web/pages/settings/my-account/appearance.tsx +++ b/apps/web/pages/settings/my-account/appearance.tsx @@ -41,9 +41,25 @@ const SkeletonLoader = () => { const AppearanceView = () => { const { t } = useLocale(); + 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: () => { + onSuccess: async () => { + await utils.viewer.me.invalidate(); showToast(t("settings_updated_successfully"), "success"); }, onError: () => { @@ -51,129 +67,138 @@ const AppearanceView = () => { }, }); - const formMethods = useForm(); - if (isLoading) return ; - if (user) - 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")}

-
-
-
- - - -
+ if (!user) return null; -
-
-
-

{t("custom_brand_colors")}

-

{t("customize_your_brand_colors")}

-
-
+ const isDisabled = isSubmitting || !isDirty; -
- ( -
-

{t("light_brand_color")}

- formMethods.setValue("brandColor", value)} - /> -
- )} - /> - ( -
-

{t("dark_brand_color")}

- formMethods.setValue("darkBrandColor", value)} - /> -
- )} - /> + 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")}

- {/* TODO future PR to preview brandColors */} - {/* */} -
- ( - <> -
-
-
-

{t("disable_cal_branding")}

{" "} - {t("pro")} -
-

{t("removes_cal_branding")}

-
-
- formMethods.setValue("hideBranding", checked)} - checked={value} - /> +
+ ( + <> +
+
+
+

{t("disable_cal_branding")}

+ {t("pro")}
+

{t("removes_cal_branding")}

- - )} - /> - - - ); +
+ + formMethods.setValue("hideBranding", checked, { shouldDirty: true }) + } + checked={value} + /> +
+
+ + )} + /> + + + ); }; AppearanceView.getLayout = getLayout;