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";
|
2022-08-26 00:11:41 +00:00
|
|
|
|
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";
|
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";
|
|
|
|
import { trpc } 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,
|
|
|
|
Switch,
|
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>
|
2022-12-07 20:53:44 +00:00
|
|
|
<Meta title={title} description={description} />
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="mt-6 mb-8 space-y-6">
|
2022-09-15 09:05:26 +00:00
|
|
|
<div className="flex items-center">
|
|
|
|
<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" />
|
2022-08-26 00:11:41 +00:00
|
|
|
|
2022-09-15 09:05:26 +00:00
|
|
|
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
|
|
|
|
</div>
|
|
|
|
</SkeletonContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const AppearanceView = () => {
|
2022-08-26 00:11:41 +00:00
|
|
|
const { t } = useLocale();
|
2022-11-23 23:23:40 +00:00
|
|
|
const utils = trpc.useContext();
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: user, isLoading } = trpc.viewer.me.useQuery();
|
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-01-23 09:58:41 +00:00
|
|
|
|
2023-01-31 19:10:21 +00:00
|
|
|
const { isLoading: isTeamPlanStatusLoading, hasPaidPlan } = useHasPaidPlan();
|
2022-11-23 23:23:40 +00:00
|
|
|
|
|
|
|
const formMethods = useForm({
|
|
|
|
defaultValues: {
|
|
|
|
theme: user?.theme,
|
|
|
|
brandColor: user?.brandColor || "#292929",
|
|
|
|
darkBrandColor: user?.darkBrandColor || "#fafafa",
|
|
|
|
hideBranding: user?.hideBranding,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const {
|
|
|
|
formState: { isSubmitting, isDirty },
|
2023-05-30 14:32:15 +00:00
|
|
|
reset,
|
2022-11-23 23:23:40 +00:00
|
|
|
} = formMethods;
|
|
|
|
|
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-05-30 14:32:15 +00:00
|
|
|
reset(data);
|
2022-08-26 00:11:41 +00:00
|
|
|
},
|
|
|
|
onError: () => {
|
|
|
|
showToast(t("error_updating_settings"), "error");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-01-23 09:58:41 +00:00
|
|
|
if (isLoading || isTeamPlanStatusLoading)
|
2023-01-14 00:48:19 +00:00
|
|
|
return <SkeletonLoader title={t("appearance")} description={t("appearance_description")} />;
|
2022-09-15 09:05:26 +00:00
|
|
|
|
2022-11-23 23:23:40 +00:00
|
|
|
if (!user) return null;
|
2022-08-26 00:11:41 +00:00
|
|
|
|
2022-11-23 23:23:40 +00:00
|
|
|
const isDisabled = isSubmitting || !isDirty;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
form={formMethods}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}}>
|
2022-12-07 20:53:44 +00:00
|
|
|
<Meta title={t("appearance")} description={t("appearance_description")} />
|
2022-11-23 23:23:40 +00:00
|
|
|
<div className="mb-6 flex items-center text-sm">
|
|
|
|
<div>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default font-semibold">{t("theme")}</p>
|
|
|
|
<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>
|
|
|
|
<div className="flex flex-col justify-between sm:flex-row">
|
|
|
|
<ThemeLabel
|
|
|
|
variant="system"
|
|
|
|
value={null}
|
|
|
|
label={t("theme_system")}
|
|
|
|
defaultChecked={user.theme === null}
|
|
|
|
register={formMethods.register}
|
|
|
|
/>
|
|
|
|
<ThemeLabel
|
|
|
|
variant="light"
|
|
|
|
value="light"
|
|
|
|
label={t("theme_light")}
|
|
|
|
defaultChecked={user.theme === "light"}
|
|
|
|
register={formMethods.register}
|
|
|
|
/>
|
|
|
|
<ThemeLabel
|
|
|
|
variant="dark"
|
|
|
|
value="dark"
|
|
|
|
label={t("theme_dark")}
|
|
|
|
defaultChecked={user.theme === "dark"}
|
|
|
|
register={formMethods.register}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-08-26 00:11:41 +00:00
|
|
|
|
2023-04-05 18:14:46 +00:00
|
|
|
<hr className="border-subtle my-8 border" />
|
2022-11-23 23:23:40 +00:00
|
|
|
<div className="mb-6 flex items-center text-sm">
|
|
|
|
<div>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default font-semibold">{t("custom_brand_colors")}</p>
|
|
|
|
<p className="text-default mt-0.5 leading-5">{t("customize_your_brand_colors")}</p>
|
2022-09-15 09:05:26 +00:00
|
|
|
</div>
|
2022-11-23 23:23:40 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="block justify-between sm:flex">
|
|
|
|
<Controller
|
|
|
|
name="brandColor"
|
|
|
|
control={formMethods.control}
|
|
|
|
defaultValue={user.brandColor}
|
|
|
|
render={() => (
|
|
|
|
<div>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default mb-2 block text-sm font-medium">{t("light_brand_color")}</p>
|
2022-11-23 23:23:40 +00:00
|
|
|
<ColorPicker
|
|
|
|
defaultValue={user.brandColor}
|
2023-05-05 12:25:18 +00:00
|
|
|
resetDefaultValue="#292929"
|
2023-04-19 14:39:23 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
if (!checkWCAGContrastColor("#ffffff", value)) {
|
|
|
|
setLightModeError(true);
|
|
|
|
} else {
|
|
|
|
setLightModeError(false);
|
|
|
|
}
|
|
|
|
formMethods.setValue("brandColor", value, { shouldDirty: true });
|
|
|
|
}}
|
2022-11-23 23:23:40 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Controller
|
|
|
|
name="darkBrandColor"
|
|
|
|
control={formMethods.control}
|
|
|
|
defaultValue={user.darkBrandColor}
|
|
|
|
render={() => (
|
|
|
|
<div className="mt-6 sm:mt-0">
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default mb-2 block text-sm font-medium">{t("dark_brand_color")}</p>
|
2022-11-23 23:23:40 +00:00
|
|
|
<ColorPicker
|
|
|
|
defaultValue={user.darkBrandColor}
|
2023-05-05 12:25:18 +00:00
|
|
|
resetDefaultValue="#fafafa"
|
2023-04-05 18:14:46 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
if (!checkWCAGContrastColor("#101010", value)) {
|
|
|
|
setDarkModeError(true);
|
|
|
|
} else {
|
|
|
|
setDarkModeError(false);
|
|
|
|
}
|
|
|
|
formMethods.setValue("darkBrandColor", value, { shouldDirty: true });
|
|
|
|
}}
|
2022-11-23 23:23:40 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-04-05 18:14:46 +00:00
|
|
|
{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}
|
2023-04-19 14:39:23 +00:00
|
|
|
{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}
|
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-04-05 18:14:46 +00:00
|
|
|
<hr className="border-subtle my-8 border" />
|
2022-11-23 23:23:40 +00:00
|
|
|
<Controller
|
|
|
|
name="hideBranding"
|
|
|
|
control={formMethods.control}
|
|
|
|
defaultValue={user.hideBranding}
|
|
|
|
render={({ field: { value } }) => (
|
|
|
|
<>
|
|
|
|
<div className="flex w-full text-sm">
|
|
|
|
<div className="mr-1 flex-grow">
|
|
|
|
<div className="flex items-center">
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default font-semibold ltr:mr-2 rtl:ml-2">
|
2023-01-04 07:38:45 +00:00
|
|
|
{t("disable_cal_branding", { appName: APP_NAME })}
|
|
|
|
</p>
|
2023-01-23 09:58:41 +00:00
|
|
|
<UpgradeTeamsBadge />
|
2022-08-26 00:11:41 +00:00
|
|
|
</div>
|
2023-04-05 18:14:46 +00:00
|
|
|
<p className="text-default mt-0.5">{t("removes_cal_branding", { appName: APP_NAME })}</p>
|
2022-08-26 00:11:41 +00:00
|
|
|
</div>
|
2022-11-23 23:23:40 +00:00
|
|
|
<div className="flex-none">
|
|
|
|
<Switch
|
|
|
|
id="hideBranding"
|
2023-01-31 19:10:21 +00:00
|
|
|
disabled={!hasPaidPlan}
|
2022-11-23 23:23:40 +00:00
|
|
|
onCheckedChange={(checked) =>
|
|
|
|
formMethods.setValue("hideBranding", checked, { shouldDirty: true })
|
|
|
|
}
|
2023-01-31 19:10:21 +00:00
|
|
|
checked={hasPaidPlan ? value : false}
|
2022-11-23 23:23:40 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
disabled={isDisabled}
|
|
|
|
type="submit"
|
|
|
|
loading={mutation.isLoading}
|
|
|
|
color="primary"
|
|
|
|
className="mt-8">
|
|
|
|
{t("update")}
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
);
|
2022-08-26 00:11:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AppearanceView.getLayout = getLayout;
|
2023-04-18 18:45:32 +00:00
|
|
|
AppearanceView.PageWrapper = PageWrapper;
|
2022-08-26 00:11:41 +00:00
|
|
|
|
|
|
|
export default AppearanceView;
|