2022-03-22 15:22:20 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
2021-12-09 23:51:30 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import React from "react";
|
|
|
|
|
2022-03-16 23:36:43 +00:00
|
|
|
import showToast from "@calcom/lib/notification";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { TeamWithMembers } from "@calcom/lib/server/queries/teams";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-07-28 19:58:26 +00:00
|
|
|
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Dialog, DialogTrigger } from "@calcom/ui/Dialog";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-03-16 23:36:43 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
|
|
|
|
2022-01-12 09:29:20 +00:00
|
|
|
import CreateEventTypeButton from "@components/eventtype/CreateEventType";
|
2021-12-09 23:51:30 +00:00
|
|
|
import LinkIconButton from "@components/ui/LinkIconButton";
|
|
|
|
|
|
|
|
export default function TeamSettingsRightSidebar(props: { team: TeamWithMembers; role: MembershipRole }) {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const router = useRouter();
|
|
|
|
|
2022-03-26 00:39:38 +00:00
|
|
|
const permalink = `${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${props.team?.slug}`;
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
const deleteTeamMutation = trpc.useMutation("viewer.teams.delete", {
|
|
|
|
async onSuccess() {
|
|
|
|
await utils.invalidateQueries(["viewer.teams.get"]);
|
2022-02-07 23:35:26 +00:00
|
|
|
router.push(`/settings/teams`);
|
2021-12-09 23:51:30 +00:00
|
|
|
showToast(t("your_team_updated_successfully"), "success");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const acceptOrLeaveMutation = trpc.useMutation("viewer.teams.acceptOrLeave", {
|
|
|
|
onSuccess: () => {
|
|
|
|
utils.invalidateQueries(["viewer.teams.list"]);
|
|
|
|
router.push(`/settings/teams`);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function deleteTeam() {
|
|
|
|
if (props.team?.id) deleteTeamMutation.mutate({ teamId: props.team.id });
|
|
|
|
}
|
|
|
|
function leaveTeam() {
|
|
|
|
if (props.team?.id)
|
|
|
|
acceptOrLeaveMutation.mutate({
|
|
|
|
teamId: props.team.id,
|
|
|
|
accept: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="space-y-6 px-2">
|
2022-02-07 23:35:26 +00:00
|
|
|
{(props.role === MembershipRole.OWNER || props.role === MembershipRole.ADMIN) && (
|
|
|
|
<CreateEventTypeButton
|
|
|
|
isIndividualTeam
|
|
|
|
canAddEvents={true}
|
|
|
|
options={[
|
|
|
|
{
|
|
|
|
teamId: props.team?.id,
|
|
|
|
name: props.team?.name,
|
|
|
|
slug: props.team?.slug,
|
|
|
|
image: props.team?.logo,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
<div className="space-y-1">
|
|
|
|
<Link href={permalink} passHref={true}>
|
|
|
|
<a target="_blank">
|
2022-08-03 16:01:29 +00:00
|
|
|
<LinkIconButton Icon={Icon.FiExternalLink}>{t("preview")}</LinkIconButton>
|
2021-12-09 23:51:30 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
<LinkIconButton
|
2022-08-03 16:01:29 +00:00
|
|
|
Icon={Icon.FiLink}
|
2021-12-09 23:51:30 +00:00
|
|
|
onClick={() => {
|
|
|
|
navigator.clipboard.writeText(permalink);
|
|
|
|
showToast("Copied to clipboard", "success");
|
|
|
|
}}>
|
|
|
|
{t("copy_link_team")}
|
|
|
|
</LinkIconButton>
|
|
|
|
{props.role === "OWNER" ? (
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<LinkIconButton
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
2022-08-03 16:01:29 +00:00
|
|
|
Icon={Icon.FiTrash}>
|
2021-12-09 23:51:30 +00:00
|
|
|
{t("disband_team")}
|
|
|
|
</LinkIconButton>
|
|
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("disband_team")}
|
|
|
|
confirmBtnText={t("confirm_disband_team")}
|
|
|
|
onConfirm={deleteTeam}>
|
|
|
|
{t("disband_team_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
) : (
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<LinkIconButton
|
2022-08-03 16:01:29 +00:00
|
|
|
Icon={Icon.FiLogOut}
|
2021-12-09 23:51:30 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}>
|
|
|
|
{t("leave_team")}
|
|
|
|
</LinkIconButton>
|
|
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("leave_team")}
|
|
|
|
confirmBtnText={t("confirm_leave_team")}
|
|
|
|
onConfirm={leaveTeam}>
|
|
|
|
{t("leave_team_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-12-17 00:16:59 +00:00
|
|
|
{props.team?.id && props.role !== MembershipRole.MEMBER && (
|
2021-12-09 23:51:30 +00:00
|
|
|
<Link href={`/settings/teams/${props.team.id}/availability`}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mt-5 hidden space-y-1 sm:block">
|
2022-08-03 16:01:29 +00:00
|
|
|
<LinkIconButton Icon={Icon.FiClock}>View Availability</LinkIconButton>
|
2021-12-09 23:51:30 +00:00
|
|
|
<p className="mt-2 text-sm text-gray-500">See your team members availability at a glance.</p>
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|