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";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Button, Form, getSettingsLayout as getLayout, Meta, showToast, Switch } from "@calcom/ui";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
interface TeamAppearanceValues {
|
|
|
|
hideBranding: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const form = useForm<TeamAppearanceValues>();
|
|
|
|
|
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");
|
|
|
|
},
|
|
|
|
onSuccess: (team) => {
|
|
|
|
if (team) {
|
|
|
|
form.setValue("hideBranding", team.hideBranding);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
const isAdmin =
|
|
|
|
team && (team.membership.role === MembershipRole.OWNER || team.membership.role === MembershipRole.ADMIN);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-12-07 20:53:44 +00:00
|
|
|
<Meta title={t("booking_appearance")} description={t("appearance_team_description")} />
|
2022-09-12 22:04:33 +00:00
|
|
|
{!isLoading && (
|
|
|
|
<>
|
|
|
|
{isAdmin ? (
|
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
handleSubmit={(values) => {
|
|
|
|
if (team) {
|
|
|
|
const hideBranding = form.getValues("hideBranding");
|
|
|
|
if (team.hideBranding !== hideBranding) {
|
|
|
|
mutation.mutate({ id: team.id, hideBranding });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
<div className="relative flex items-start">
|
|
|
|
<div className="flex-grow text-sm">
|
|
|
|
<label htmlFor="hide-branding" className="font-medium text-gray-700">
|
2022-11-30 21:52:56 +00:00
|
|
|
{t("disable_cal_branding", { appName: APP_NAME })}
|
2022-09-12 22:04:33 +00:00
|
|
|
</label>
|
2022-11-30 21:52:56 +00:00
|
|
|
<p className="text-gray-500">
|
|
|
|
{t("team_disable_cal_branding_description", { appName: APP_NAME })}
|
|
|
|
</p>
|
2022-09-12 22:04:33 +00:00
|
|
|
</div>
|
|
|
|
<div className="flex-none">
|
|
|
|
<Controller
|
|
|
|
control={form.control}
|
|
|
|
name="hideBranding"
|
|
|
|
render={({ field }) => (
|
|
|
|
<Switch
|
|
|
|
defaultChecked={field.value}
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
form.setValue("hideBranding", isChecked);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ProfileView.getLayout = getLayout;
|
|
|
|
|
|
|
|
export default ProfileView;
|