2023-04-05 18:14:46 +00:00
|
|
|
import { useState } from "react";
|
2022-08-30 19:46:52 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2023-06-08 12:32:17 +00:00
|
|
|
import type { z } from "zod";
|
2022-08-26 00:11:41 +00:00
|
|
|
|
2023-06-06 15:31:43 +00:00
|
|
|
import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSelector";
|
2023-09-28 18:04:51 +00:00
|
|
|
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
|
2023-02-01 18:27:26 +00:00
|
|
|
import ThemeLabel from "@calcom/features/settings/ThemeLabel";
|
2023-01-05 17:00:16 +00:00
|
|
|
import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout";
|
2023-09-28 18:04:51 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
2022-11-30 21:52:56 +00:00
|
|
|
import { APP_NAME } from "@calcom/lib/constants";
|
2023-04-05 18:14:46 +00:00
|
|
|
import { checkWCAGContrastColor } from "@calcom/lib/getBrandColours";
|
2023-01-31 19:10:21 +00:00
|
|
|
import { useHasPaidPlan } from "@calcom/lib/hooks/useHasPaidPlan";
|
2022-08-26 00:11:41 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-06-06 15:31:43 +00:00
|
|
|
import { validateBookerLayouts } from "@calcom/lib/validateBookerLayouts";
|
2023-06-08 12:32:17 +00:00
|
|
|
import type { userMetadata } from "@calcom/prisma/zod-utils";
|
2022-08-26 00:11:41 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-09-28 18:04:51 +00:00
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
2023-04-05 18:14:46 +00:00
|
|
|
Alert,
|
2022-11-23 02:55:25 +00:00
|
|
|
Button,
|
|
|
|
ColorPicker,
|
|
|
|
Form,
|
|
|
|
Meta,
|
|
|
|
showToast,
|
|
|
|
SkeletonButton,
|
|
|
|
SkeletonContainer,
|
|
|
|
SkeletonText,
|
2023-09-28 18:04:51 +00:00
|
|
|
SettingsToggle,
|
2023-01-14 00:48:19 +00:00
|
|
|
UpgradeTeamsBadge,
|
2022-11-23 02:55:25 +00:00
|
|
|
} from "@calcom/ui";
|
2022-08-26 00:11:41 +00:00
|
|
|
|
2023-04-18 18:45:32 +00:00
|
|
|
import PageWrapper from "@components/PageWrapper";
|
|
|
|
|
2022-12-07 20:53:44 +00:00
|
|
|
const SkeletonLoader = ({ title, description }: { title: string; description: string }) => {
|
2022-09-15 09:05:26 +00:00
|
|
|
return (
|
|
|
|
<SkeletonContainer>
|
2023-09-28 18:04:51 +00:00
|
|
|
<Meta title={title} description={description} borderInShellHeader={false} />
|
|
|
|
<div className="border-subtle mt-6 space-y-6 rounded-t-xl border border-b-0 px-4 py-6 sm:px-6">
|
|
|
|
<div className="flex items-center justify-center">
|
2022-09-15 09:05:26 +00:00
|
|
|
<SkeletonButton className="mr-6 h-32 w-48 rounded-md p-5" />
|
|
|
|
<SkeletonButton className="mr-6 h-32 w-48 rounded-md p-5" />
|
|
|
|
<SkeletonButton className="mr-6 h-32 w-48 rounded-md p-5" />
|
|
|
|
</div>
|
|
|
|
<div className="flex justify-between">
|
|
|
|
<SkeletonText className="h-8 w-1/3" />
|
|
|
|
<SkeletonText className="h-8 w-1/3" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<SkeletonText className="h-8 w-full" />
|
2023-09-28 18:04:51 +00:00
|
|
|
</div>
|
|
|
|
<div className="rounded-b-xl">
|
|
|
|
<SectionBottomActions align="end">
|
|
|
|
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
|
|
|
|
</SectionBottomActions>
|
2022-09-15 09:05:26 +00:00
|
|
|
</div>
|
|
|
|
</SkeletonContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
const DEFAULT_LIGHT_BRAND_COLOR = "#292929";
|
|
|
|
const DEFAULT_DARK_BRAND_COLOR = "#fafafa";
|
|
|
|
|
|
|
|
const AppearanceView = ({
|
|
|
|
user,
|
|
|
|
hasPaidPlan,
|
|
|
|
}: {
|
|
|
|
user: RouterOutputs["viewer"]["me"];
|
|
|
|
hasPaidPlan: boolean;
|
|
|
|
}) => {
|
2022-08-26 00:11:41 +00:00
|
|
|
const { t } = useLocale();
|
2022-11-23 23:23:40 +00:00
|
|
|
const utils = trpc.useContext();
|
2023-04-05 18:14:46 +00:00
|
|
|
const [darkModeError, setDarkModeError] = useState(false);
|
2023-04-19 14:39:23 +00:00
|
|
|
const [lightModeError, setLightModeError] = useState(false);
|
2023-09-28 18:04:51 +00:00
|
|
|
const [isCustomBrandColorChecked, setIsCustomBranColorChecked] = useState(
|
|
|
|
user?.brandColor !== DEFAULT_LIGHT_BRAND_COLOR || user?.darkBrandColor !== DEFAULT_DARK_BRAND_COLOR
|
|
|
|
);
|
|
|
|
const [hideBrandingValue, setHideBrandingValue] = useState(user?.hideBranding ?? false);
|
2023-01-23 09:58:41 +00:00
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
const userThemeFormMethods = useForm({
|
|
|
|
defaultValues: {
|
|
|
|
theme: user.theme,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const {
|
|
|
|
formState: { isSubmitting: isUserThemeSubmitting, isDirty: isUserThemeDirty },
|
|
|
|
reset: resetUserThemeReset,
|
|
|
|
} = userThemeFormMethods;
|
|
|
|
|
|
|
|
const bookerLayoutFormMethods = useForm({
|
|
|
|
defaultValues: {
|
|
|
|
metadata: user.metadata as z.infer<typeof userMetadata>,
|
|
|
|
},
|
|
|
|
});
|
2022-11-23 23:23:40 +00:00
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
const {
|
|
|
|
formState: { isSubmitting: isBookerLayoutFormSubmitting, isDirty: isBookerLayoutFormDirty },
|
|
|
|
reset: resetBookerLayoutThemeReset,
|
|
|
|
} = bookerLayoutFormMethods;
|
|
|
|
|
|
|
|
const brandColorsFormMethods = useForm({
|
2022-11-23 23:23:40 +00:00
|
|
|
defaultValues: {
|
2023-09-28 18:04:51 +00:00
|
|
|
brandColor: user.brandColor || DEFAULT_LIGHT_BRAND_COLOR,
|
|
|
|
darkBrandColor: user.darkBrandColor || DEFAULT_DARK_BRAND_COLOR,
|
2022-11-23 23:23:40 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
const {
|
|
|
|
formState: { isSubmitting: isBrandColorsFormSubmitting, isDirty: isBrandColorsFormDirty },
|
|
|
|
reset: resetBrandColorsThemeReset,
|
|
|
|
} = brandColorsFormMethods;
|
|
|
|
|
|
|
|
const selectedTheme = userThemeFormMethods.watch("theme");
|
2023-06-21 15:14:23 +00:00
|
|
|
const selectedThemeIsDark =
|
|
|
|
selectedTheme === "dark" ||
|
|
|
|
(selectedTheme === "" &&
|
|
|
|
typeof document !== "undefined" &&
|
|
|
|
document.documentElement.classList.contains("dark"));
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const mutation = trpc.viewer.updateProfile.useMutation({
|
2023-05-30 14:32:15 +00:00
|
|
|
onSuccess: async (data) => {
|
2022-11-23 23:23:40 +00:00
|
|
|
await utils.viewer.me.invalidate();
|
2022-08-26 00:11:41 +00:00
|
|
|
showToast(t("settings_updated_successfully"), "success");
|
2023-09-28 18:04:51 +00:00
|
|
|
resetBrandColorsThemeReset({ brandColor: data.brandColor, darkBrandColor: data.darkBrandColor });
|
|
|
|
resetBookerLayoutThemeReset({ metadata: data.metadata });
|
|
|
|
resetUserThemeReset({ theme: data.theme });
|
2022-08-26 00:11:41 +00:00
|
|
|
},
|
2023-06-06 15:31:43 +00:00
|
|
|
onError: (error) => {
|
|
|
|
if (error.message) {
|
|
|
|
showToast(error.message, "error");
|
|
|
|
} else {
|
|
|
|
showToast(t("error_updating_settings"), "error");
|
|
|
|
}
|
2022-08-26 00:11:41 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-23 23:23:40 +00:00
|
|
|
return (
|
2023-09-28 18:04:51 +00:00
|
|
|
<div>
|
|
|
|
<Meta title={t("appearance")} description={t("appearance_description")} borderInShellHeader={false} />
|
|
|
|
<div className="border-subtle mt-6 flex items-center rounded-t-xl border p-6 text-sm">
|
2022-11-23 23:23:40 +00:00
|
|
|
<div>
|
2023-09-28 18:04:51 +00:00
|
|
|
<p className="text-default text-base font-semibold">{t("theme")}</p>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default">{t("theme_applies_note")}</p>
|
2022-08-26 00:11:41 +00:00
|
|
|
</div>
|
2022-11-23 23:23:40 +00:00
|
|
|
</div>
|
2023-09-28 18:04:51 +00:00
|
|
|
<Form
|
|
|
|
form={userThemeFormMethods}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
mutation.mutate({
|
|
|
|
// Radio values don't support null as values, therefore we convert an empty string
|
|
|
|
// back to null here.
|
|
|
|
theme: values.theme || null,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
<div className="border-subtle flex flex-col justify-between border-x px-6 py-8 sm:flex-row">
|
|
|
|
<ThemeLabel
|
|
|
|
variant="system"
|
|
|
|
value={null}
|
|
|
|
label={t("theme_system")}
|
|
|
|
defaultChecked={user.theme === null}
|
|
|
|
register={userThemeFormMethods.register}
|
|
|
|
/>
|
|
|
|
<ThemeLabel
|
|
|
|
variant="light"
|
|
|
|
value="light"
|
|
|
|
label={t("light")}
|
|
|
|
defaultChecked={user.theme === "light"}
|
|
|
|
register={userThemeFormMethods.register}
|
|
|
|
/>
|
|
|
|
<ThemeLabel
|
|
|
|
variant="dark"
|
|
|
|
value="dark"
|
|
|
|
label={t("dark")}
|
|
|
|
defaultChecked={user.theme === "dark"}
|
|
|
|
register={userThemeFormMethods.register}
|
|
|
|
/>
|
2022-09-15 09:05:26 +00:00
|
|
|
</div>
|
2023-09-28 18:04:51 +00:00
|
|
|
<SectionBottomActions className="mb-6" align="end">
|
|
|
|
<Button
|
|
|
|
disabled={isUserThemeSubmitting || !isUserThemeDirty}
|
|
|
|
type="submit"
|
|
|
|
data-testid="update-theme-btn"
|
|
|
|
color="primary">
|
|
|
|
{t("update")}
|
|
|
|
</Button>
|
|
|
|
</SectionBottomActions>
|
|
|
|
</Form>
|
2022-11-23 23:23:40 +00:00
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
<Form
|
|
|
|
form={bookerLayoutFormMethods}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
const layoutError = validateBookerLayouts(values?.metadata?.defaultBookerLayouts || null);
|
|
|
|
if (layoutError) {
|
|
|
|
showToast(t(layoutError), "error");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
mutation.mutate(values);
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
<BookerLayoutSelector
|
|
|
|
isDark={selectedThemeIsDark}
|
|
|
|
name="metadata.defaultBookerLayouts"
|
|
|
|
title={t("bookerlayout_user_settings_title")}
|
|
|
|
description={t("bookerlayout_user_settings_description")}
|
|
|
|
isDisabled={isBookerLayoutFormSubmitting || !isBookerLayoutFormDirty}
|
|
|
|
/>
|
|
|
|
</Form>
|
|
|
|
|
|
|
|
<Form
|
|
|
|
form={brandColorsFormMethods}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
mutation.mutate(values);
|
|
|
|
}}>
|
|
|
|
<div className="mt-6">
|
|
|
|
<SettingsToggle
|
|
|
|
toggleSwitchAtTheEnd={true}
|
|
|
|
title={t("custom_brand_colors")}
|
|
|
|
description={t("customize_your_brand_colors")}
|
|
|
|
checked={isCustomBrandColorChecked}
|
|
|
|
onCheckedChange={(checked) => {
|
|
|
|
setIsCustomBranColorChecked(checked);
|
|
|
|
if (!checked) {
|
|
|
|
mutation.mutate({
|
|
|
|
brandColor: DEFAULT_LIGHT_BRAND_COLOR,
|
|
|
|
darkBrandColor: DEFAULT_DARK_BRAND_COLOR,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
childrenClassName="lg:ml-0"
|
|
|
|
switchContainerClassName={classNames(
|
|
|
|
"py-6 px-4 sm:px-6 border-subtle rounded-xl border",
|
|
|
|
isCustomBrandColorChecked && "rounded-b-none"
|
|
|
|
)}>
|
|
|
|
<div className="border-subtle flex flex-col gap-6 border-x p-6">
|
|
|
|
<Controller
|
|
|
|
name="brandColor"
|
|
|
|
control={brandColorsFormMethods.control}
|
2022-11-23 23:23:40 +00:00
|
|
|
defaultValue={user.brandColor}
|
2023-09-28 18:04:51 +00:00
|
|
|
render={() => (
|
|
|
|
<div>
|
|
|
|
<p className="text-default mb-2 block text-sm font-medium">{t("light_brand_color")}</p>
|
|
|
|
<ColorPicker
|
|
|
|
defaultValue={user.brandColor}
|
|
|
|
resetDefaultValue="#292929"
|
|
|
|
onChange={(value) => {
|
|
|
|
try {
|
|
|
|
checkWCAGContrastColor("#ffffff", value);
|
|
|
|
setLightModeError(false);
|
|
|
|
brandColorsFormMethods.setValue("brandColor", value, { shouldDirty: true });
|
|
|
|
} catch (err) {
|
|
|
|
setLightModeError(false);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{lightModeError ? (
|
|
|
|
<div className="mt-4">
|
|
|
|
<Alert
|
|
|
|
severity="warning"
|
|
|
|
message="Light Theme color doesn't pass contrast check. We recommend you change this colour so your buttons will be more visible."
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-23 23:23:40 +00:00
|
|
|
/>
|
2023-09-28 18:04:51 +00:00
|
|
|
|
|
|
|
<Controller
|
|
|
|
name="darkBrandColor"
|
|
|
|
control={brandColorsFormMethods.control}
|
2022-11-23 23:23:40 +00:00
|
|
|
defaultValue={user.darkBrandColor}
|
2023-09-28 18:04:51 +00:00
|
|
|
render={() => (
|
|
|
|
<div className="mt-6 sm:mt-0">
|
|
|
|
<p className="text-default mb-2 block text-sm font-medium">{t("dark_brand_color")}</p>
|
|
|
|
<ColorPicker
|
|
|
|
defaultValue={user.darkBrandColor}
|
|
|
|
resetDefaultValue="#fafafa"
|
|
|
|
onChange={(value) => {
|
|
|
|
try {
|
|
|
|
checkWCAGContrastColor("#101010", value);
|
|
|
|
setDarkModeError(false);
|
|
|
|
brandColorsFormMethods.setValue("darkBrandColor", value, { shouldDirty: true });
|
|
|
|
} catch (err) {
|
|
|
|
setDarkModeError(true);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{darkModeError ? (
|
|
|
|
<div className="mt-4">
|
|
|
|
<Alert
|
|
|
|
severity="warning"
|
|
|
|
message="Dark Theme color doesn't pass contrast check. We recommend you change this colour so your buttons will be more visible."
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-11-23 23:23:40 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-09-28 18:04:51 +00:00
|
|
|
<SectionBottomActions align="end">
|
|
|
|
<Button
|
|
|
|
disabled={isBrandColorsFormSubmitting || !isBrandColorsFormDirty}
|
|
|
|
color="primary"
|
|
|
|
type="submit">
|
|
|
|
{t("update")}
|
|
|
|
</Button>
|
|
|
|
</SectionBottomActions>
|
|
|
|
</SettingsToggle>
|
2023-04-19 14:39:23 +00:00
|
|
|
</div>
|
2023-09-28 18:04:51 +00:00
|
|
|
</Form>
|
|
|
|
|
2022-11-23 23:23:40 +00:00
|
|
|
{/* TODO future PR to preview brandColors */}
|
|
|
|
{/* <Button
|
2022-08-26 00:11:41 +00:00
|
|
|
color="secondary"
|
2023-04-12 15:26:31 +00:00
|
|
|
EndIcon={ExternalLink}
|
2022-08-26 00:11:41 +00:00
|
|
|
className="mt-6"
|
|
|
|
onClick={() => window.open(`${WEBAPP_URL}/${user.username}/${user.eventTypes[0].title}`, "_blank")}>
|
|
|
|
Preview
|
|
|
|
</Button> */}
|
2023-09-28 18:04:51 +00:00
|
|
|
|
|
|
|
<SettingsToggle
|
|
|
|
toggleSwitchAtTheEnd={true}
|
|
|
|
title={t("disable_cal_branding", { appName: APP_NAME })}
|
|
|
|
disabled={!hasPaidPlan || mutation?.isLoading}
|
|
|
|
description={t("removes_cal_branding", { appName: APP_NAME })}
|
|
|
|
checked={hasPaidPlan ? hideBrandingValue : false}
|
|
|
|
Badge={<UpgradeTeamsBadge />}
|
|
|
|
onCheckedChange={(checked) => {
|
|
|
|
setHideBrandingValue(checked);
|
|
|
|
mutation.mutate({ hideBranding: checked });
|
|
|
|
}}
|
|
|
|
switchContainerClassName="border-subtle mt-6 rounded-xl border py-6 px-4 sm:px-6"
|
2022-11-23 23:23:40 +00:00
|
|
|
/>
|
2023-09-28 18:04:51 +00:00
|
|
|
</div>
|
2022-11-23 23:23:40 +00:00
|
|
|
);
|
2022-08-26 00:11:41 +00:00
|
|
|
};
|
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
const AppearanceViewWrapper = () => {
|
|
|
|
const { data: user, isLoading } = trpc.viewer.me.useQuery();
|
|
|
|
const { isLoading: isTeamPlanStatusLoading, hasPaidPlan } = useHasPaidPlan();
|
|
|
|
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
if (isLoading || isTeamPlanStatusLoading || !user)
|
|
|
|
return <SkeletonLoader title={t("appearance")} description={t("appearance_description")} />;
|
|
|
|
|
|
|
|
return <AppearanceView user={user} hasPaidPlan={hasPaidPlan} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
AppearanceViewWrapper.getLayout = getLayout;
|
|
|
|
AppearanceViewWrapper.PageWrapper = PageWrapper;
|
2022-08-26 00:11:41 +00:00
|
|
|
|
2023-09-28 18:04:51 +00:00
|
|
|
export default AppearanceViewWrapper;
|