2022-09-12 22:04:33 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
|
2022-11-30 21:52:56 +00:00
|
|
|
import { APP_NAME } from "@calcom/lib/constants";
|
2022-09-12 22:04:33 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-02-01 18:27:26 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
ColorPicker,
|
|
|
|
Form,
|
|
|
|
Meta,
|
|
|
|
showToast,
|
|
|
|
SkeletonButton,
|
|
|
|
SkeletonContainer,
|
|
|
|
SkeletonText,
|
|
|
|
Switch,
|
|
|
|
} from "@calcom/ui";
|
2023-01-05 17:00:16 +00:00
|
|
|
|
2023-02-01 18:27:26 +00:00
|
|
|
import ThemeLabel from "../../../settings/ThemeLabel";
|
2023-01-05 17:00:16 +00:00
|
|
|
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
2023-02-01 18:27:26 +00:00
|
|
|
const SkeletonLoader = ({ title, description }: { title: string; description: string }) => {
|
|
|
|
return (
|
|
|
|
<SkeletonContainer>
|
|
|
|
<Meta title={title} description={description} />
|
|
|
|
<div className="mt-6 mb-8 space-y-6 divide-y">
|
|
|
|
<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" />
|
|
|
|
|
|
|
|
<SkeletonButton className="mr-6 h-8 w-20 rounded-md p-5" />
|
|
|
|
</div>
|
|
|
|
</SkeletonContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-09-12 22:04:33 +00:00
|
|
|
interface TeamAppearanceValues {
|
|
|
|
hideBranding: boolean;
|
2023-01-06 10:55:57 +00:00
|
|
|
hideBookATeamMember: boolean;
|
2023-02-01 18:27:26 +00:00
|
|
|
brandColor: string;
|
|
|
|
darkBrandColor: string;
|
|
|
|
theme: string | null | undefined;
|
2022-09-12 22:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ProfileView = () => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const router = useRouter();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const mutation = trpc.viewer.teams.update.useMutation({
|
2022-09-12 22:04:33 +00:00
|
|
|
onError: (err) => {
|
|
|
|
showToast(err.message, "error");
|
|
|
|
},
|
|
|
|
async onSuccess() {
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.teams.get.invalidate();
|
2022-09-12 22:04:33 +00:00
|
|
|
showToast(t("your_team_updated_successfully"), "success");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: team, isLoading } = trpc.viewer.teams.get.useQuery(
|
|
|
|
{ teamId: Number(router.query.id) },
|
|
|
|
{
|
|
|
|
onError: () => {
|
|
|
|
router.push("/settings");
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2022-09-12 22:04:33 +00:00
|
|
|
|
2023-02-01 18:27:26 +00:00
|
|
|
const form = useForm<TeamAppearanceValues>({
|
|
|
|
defaultValues: {
|
|
|
|
theme: team?.theme,
|
|
|
|
brandColor: team?.brandColor,
|
|
|
|
darkBrandColor: team?.darkBrandColor,
|
|
|
|
hideBranding: team?.hideBranding,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-09-12 22:04:33 +00:00
|
|
|
const isAdmin =
|
|
|
|
team && (team.membership.role === MembershipRole.OWNER || team.membership.role === MembershipRole.ADMIN);
|
|
|
|
|
2023-02-01 18:27:26 +00:00
|
|
|
if (isLoading) {
|
|
|
|
return <SkeletonLoader title={t("booking_appearance")} description={t("appearance_team_description")} />;
|
|
|
|
}
|
2022-09-12 22:04:33 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-12-07 20:53:44 +00:00
|
|
|
<Meta title={t("booking_appearance")} description={t("appearance_team_description")} />
|
2023-02-01 18:27:26 +00:00
|
|
|
{isAdmin ? (
|
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
mutation.mutate({
|
|
|
|
id: team.id,
|
|
|
|
...values,
|
|
|
|
theme: values.theme || null,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
<div className="mb-6 flex items-center text-sm">
|
|
|
|
<div>
|
|
|
|
<p className="font-semibold">{t("theme")}</p>
|
|
|
|
<p className="text-gray-600">{t("theme_applies_note")}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col justify-between sm:flex-row">
|
|
|
|
<ThemeLabel
|
|
|
|
variant="system"
|
|
|
|
value={null}
|
|
|
|
label={t("theme_system")}
|
|
|
|
defaultChecked={team.theme === null}
|
|
|
|
register={form.register}
|
|
|
|
/>
|
|
|
|
<ThemeLabel
|
|
|
|
variant="light"
|
|
|
|
value="light"
|
|
|
|
label={t("theme_light")}
|
|
|
|
defaultChecked={team.theme === "light"}
|
|
|
|
register={form.register}
|
|
|
|
/>
|
|
|
|
<ThemeLabel
|
|
|
|
variant="dark"
|
|
|
|
value="dark"
|
|
|
|
label={t("theme_dark")}
|
|
|
|
defaultChecked={team.theme === "dark"}
|
|
|
|
register={form.register}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr className="my-8 border-gray-200" />
|
|
|
|
<div className="mb-6 flex items-center text-sm">
|
|
|
|
<div>
|
|
|
|
<p className="font-semibold">{t("custom_brand_colors")}</p>
|
|
|
|
<p className="mt-0.5 leading-5 text-gray-600">{t("customize_your_brand_colors")}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="block justify-between sm:flex">
|
|
|
|
<Controller
|
|
|
|
name="brandColor"
|
|
|
|
control={form.control}
|
|
|
|
defaultValue={team.brandColor}
|
|
|
|
render={() => (
|
|
|
|
<div>
|
|
|
|
<p className="mb-2 block text-sm font-medium text-gray-900">{t("light_brand_color")}</p>
|
|
|
|
<ColorPicker
|
|
|
|
defaultValue={team.brandColor}
|
|
|
|
onChange={(value) => form.setValue("brandColor", value, { shouldDirty: true })}
|
|
|
|
/>
|
2022-09-12 22:04:33 +00:00
|
|
|
</div>
|
2023-02-01 18:27:26 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Controller
|
|
|
|
name="darkBrandColor"
|
|
|
|
control={form.control}
|
|
|
|
defaultValue={team.darkBrandColor}
|
|
|
|
render={() => (
|
|
|
|
<div className="mt-6 sm:mt-0">
|
|
|
|
<p className="mb-2 block text-sm font-medium text-gray-900">{t("dark_brand_color")}</p>
|
|
|
|
<ColorPicker
|
|
|
|
defaultValue={team.darkBrandColor}
|
|
|
|
onChange={(value) => form.setValue("darkBrandColor", value, { shouldDirty: true })}
|
|
|
|
/>
|
2022-09-12 22:04:33 +00:00
|
|
|
</div>
|
2023-02-01 18:27:26 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<hr className="my-8 border-gray-200" />
|
|
|
|
|
|
|
|
<div className="flex flex-col gap-8">
|
|
|
|
<div className="relative flex items-start">
|
|
|
|
<div className="flex-grow text-sm">
|
|
|
|
<label htmlFor="hide-branding" className="font-medium text-gray-700">
|
|
|
|
{t("disable_cal_branding", { appName: APP_NAME })}
|
|
|
|
</label>
|
|
|
|
<p className="text-gray-500">
|
|
|
|
{t("team_disable_cal_branding_description", { appName: APP_NAME })}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex-none">
|
|
|
|
<Controller
|
|
|
|
control={form.control}
|
|
|
|
defaultValue={team?.hideBranding ?? false}
|
|
|
|
name="hideBranding"
|
|
|
|
render={({ field }) => (
|
|
|
|
<Switch
|
|
|
|
defaultChecked={field.value}
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
form.setValue("hideBranding", isChecked);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="relative flex items-start">
|
|
|
|
<div className="flex-grow text-sm">
|
|
|
|
<label htmlFor="hide-branding" className="font-medium text-gray-700">
|
|
|
|
{t("hide_book_a_team_member")}
|
|
|
|
</label>
|
|
|
|
<p className="text-gray-500">{t("hide_book_a_team_member_description")}</p>
|
|
|
|
</div>
|
|
|
|
<div className="flex-none">
|
|
|
|
<Controller
|
|
|
|
control={form.control}
|
|
|
|
defaultValue={team?.hideBookATeamMember ?? false}
|
|
|
|
name="hideBookATeamMember"
|
|
|
|
render={({ field }) => (
|
|
|
|
<Switch
|
|
|
|
defaultChecked={field.value}
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
form.setValue("hideBookATeamMember", isChecked);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2022-09-12 22:04:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-01 18:27:26 +00:00
|
|
|
</div>
|
|
|
|
<Button color="primary" className="mt-8" type="submit" loading={mutation.isLoading}>
|
|
|
|
{t("update")}
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
) : (
|
|
|
|
<div className="rounded-md border border-gray-200 p-5">
|
|
|
|
<span className="text-sm text-gray-600">{t("only_owner_change")}</span>
|
|
|
|
</div>
|
2022-09-12 22:04:33 +00:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ProfileView.getLayout = getLayout;
|
|
|
|
|
|
|
|
export default ProfileView;
|