2022-02-07 23:35:26 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-02-07 23:35:26 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import SAMLConfiguration from "@calcom/features/ee/common/components/SamlConfiguration";
|
|
|
|
import { getPlaceholderAvatar } from "@calcom/lib/getPlaceholderAvatar";
|
2022-03-16 23:36:43 +00:00
|
|
|
import showToast from "@calcom/lib/notification";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-06-24 22:44:49 +00:00
|
|
|
import { SkeletonAvatar, SkeletonText } from "@calcom/ui";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Alert } from "@calcom/ui/Alert";
|
|
|
|
import { Button } from "@calcom/ui/Button";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-07-28 19:58:26 +00:00
|
|
|
import Shell from "@calcom/ui/Shell";
|
2022-01-13 20:05:23 +00:00
|
|
|
|
2022-06-24 22:44:49 +00:00
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
2022-07-21 17:02:20 +00:00
|
|
|
import useCurrentUserId from "@lib/hooks/useCurrentUserId";
|
2021-12-09 23:51:30 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
|
|
|
|
2022-07-21 17:02:20 +00:00
|
|
|
import DisableTeamImpersonation from "@components/team/DisableTeamImpersonation";
|
2021-12-09 23:51:30 +00:00
|
|
|
import MemberInvitationModal from "@components/team/MemberInvitationModal";
|
|
|
|
import MemberList from "@components/team/MemberList";
|
|
|
|
import TeamSettings from "@components/team/TeamSettings";
|
|
|
|
import TeamSettingsRightSidebar from "@components/team/TeamSettingsRightSidebar";
|
2022-02-07 23:35:26 +00:00
|
|
|
import { UpgradeToFlexibleProModal } from "@components/team/UpgradeToFlexibleProModal";
|
2021-12-09 23:51:30 +00:00
|
|
|
import Avatar from "@components/ui/Avatar";
|
|
|
|
|
|
|
|
export function TeamSettingsPage() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const router = useRouter();
|
2022-07-21 17:02:20 +00:00
|
|
|
const userId = useCurrentUserId();
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-02-07 23:35:26 +00:00
|
|
|
const upgraded = router.query.upgraded as string;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (upgraded) {
|
|
|
|
showToast(t("team_upgraded_successfully"), "success");
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []);
|
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const [showMemberInvitationModal, setShowMemberInvitationModal] = useState(false);
|
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
|
|
|
2022-06-24 22:44:49 +00:00
|
|
|
const query = trpc.useQuery(["viewer.teams.get", { teamId: Number(router.query.id) }], {
|
2021-12-09 23:51:30 +00:00
|
|
|
onError: (e) => {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2022-06-24 22:44:49 +00:00
|
|
|
<QueryCell
|
|
|
|
query={query}
|
|
|
|
loading={() => {
|
|
|
|
return (
|
|
|
|
<Shell
|
|
|
|
backPath={!errorMessage ? `/settings/teams` : undefined}
|
|
|
|
heading={
|
|
|
|
<div className="pt-2">
|
|
|
|
<SkeletonText width="16" height="6" />
|
|
|
|
</div>
|
|
|
|
}
|
2022-09-09 08:22:39 +00:00
|
|
|
subtitle={<SkeletonText className="h-4 w-12" />}
|
|
|
|
HeadingLeftIcon={<SkeletonAvatar className="mt-1 h-12 w-12" />}>
|
2022-06-24 22:44:49 +00:00
|
|
|
<>
|
|
|
|
<div className="block sm:flex md:max-w-5xl">
|
|
|
|
<div className="w-full ltr:mr-2 rtl:ml-2 sm:w-9/12">
|
2022-07-13 21:14:16 +00:00
|
|
|
<div className="-mx-0 h-[531px] rounded-sm border border-neutral-200 bg-white px-4 sm:px-6" />
|
2022-06-24 22:44:49 +00:00
|
|
|
<div className="mb-3 mt-7 flex items-center justify-between">
|
2022-09-09 08:22:39 +00:00
|
|
|
<SkeletonText className="h-4 w-12" />
|
2022-06-24 22:44:49 +00:00
|
|
|
</div>
|
2022-07-13 21:14:16 +00:00
|
|
|
<div className="-mx-0 h-16 rounded-sm border border-neutral-200 bg-white px-4 sm:px-6" />
|
2022-06-24 22:44:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
success={({ data: team }) => {
|
|
|
|
const isAdmin =
|
|
|
|
team &&
|
|
|
|
(team.membership.role === MembershipRole.OWNER || team.membership.role === MembershipRole.ADMIN);
|
|
|
|
return (
|
|
|
|
<Shell
|
|
|
|
backPath={!errorMessage ? `/settings/teams` : undefined}
|
|
|
|
heading={team?.name}
|
|
|
|
subtitle={team && t("manage_this_team")}
|
|
|
|
HeadingLeftIcon={
|
|
|
|
team && (
|
|
|
|
<Avatar
|
|
|
|
size={12}
|
|
|
|
imageSrc={getPlaceholderAvatar(team?.logo, team?.name as string)}
|
|
|
|
alt="Team Logo"
|
|
|
|
className="mt-1"
|
2022-02-07 23:35:26 +00:00
|
|
|
/>
|
2022-06-24 22:44:49 +00:00
|
|
|
)
|
|
|
|
}>
|
|
|
|
{!!errorMessage && <Alert className="-mt-24 border" severity="error" title={errorMessage} />}
|
|
|
|
{team && (
|
|
|
|
<>
|
|
|
|
<div className="block sm:flex md:max-w-5xl">
|
|
|
|
<div className="w-full ltr:mr-2 rtl:ml-2 sm:w-9/12">
|
|
|
|
{team.membership.role === MembershipRole.OWNER &&
|
|
|
|
team.membership.isMissingSeat &&
|
|
|
|
team.requiresUpgrade ? (
|
|
|
|
<Alert
|
|
|
|
severity="warning"
|
|
|
|
title={t("hidden_team_member_title")}
|
|
|
|
message={
|
|
|
|
<>
|
|
|
|
{t("hidden_team_owner_message")} <UpgradeToFlexibleProModal teamId={team.id} />
|
|
|
|
{/* <a href={"https://cal.com/upgrade"} className="underline">
|
|
|
|
{"https://cal.com/upgrade"}
|
|
|
|
</a> */}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
className="mb-4 "
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{team.membership.isMissingSeat && (
|
|
|
|
<Alert
|
|
|
|
severity="warning"
|
|
|
|
title={t("hidden_team_member_title")}
|
|
|
|
message={t("hidden_team_member_message")}
|
|
|
|
className="mb-4 "
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2022-02-07 23:35:26 +00:00
|
|
|
|
2022-06-24 22:44:49 +00:00
|
|
|
<div className="-mx-0 rounded-sm border border-neutral-200 bg-white px-4 sm:px-6">
|
|
|
|
{isAdmin ? (
|
|
|
|
<TeamSettings team={team} />
|
|
|
|
) : (
|
|
|
|
<div className="py-5">
|
|
|
|
<span className="mb-1 font-bold">{t("team_info")}</span>
|
|
|
|
<p className="text-sm text-gray-700">{team.bio}</p>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="mb-3 mt-7 flex items-center justify-between">
|
|
|
|
<h3 className="font-cal text-xl leading-6 text-gray-900">{t("members")}</h3>
|
|
|
|
{isAdmin && (
|
|
|
|
<div className="relative flex items-center">
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
color="secondary"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiPlus}
|
2022-06-24 22:44:49 +00:00
|
|
|
onClick={() => setShowMemberInvitationModal(true)}
|
|
|
|
data-testid="new-member-button">
|
|
|
|
{t("new_member")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<MemberList team={team} members={team.members || []} />
|
|
|
|
{isAdmin && <SAMLConfiguration teamsView={true} teamId={team.id} />}
|
2022-07-21 17:02:20 +00:00
|
|
|
{userId && <DisableTeamImpersonation teamId={team.id} memberId={userId} />}
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
2022-06-24 22:44:49 +00:00
|
|
|
<div className="min-w-32 mt-8 w-full px-2 ltr:ml-2 rtl:mr-2 sm:mt-0 md:w-3/12">
|
|
|
|
<TeamSettingsRightSidebar role={team.membership.role} team={team} />
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
2022-06-24 22:44:49 +00:00
|
|
|
</div>
|
|
|
|
{showMemberInvitationModal && (
|
|
|
|
<MemberInvitationModal
|
|
|
|
isOpen={showMemberInvitationModal}
|
|
|
|
team={team}
|
|
|
|
currentMember={team.membership.role}
|
|
|
|
onExit={() => setShowMemberInvitationModal(false)}
|
|
|
|
/>
|
2021-12-09 23:51:30 +00:00
|
|
|
)}
|
2022-06-24 22:44:49 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Shell>
|
|
|
|
);
|
2022-07-13 21:14:16 +00:00
|
|
|
}}
|
|
|
|
/>
|
2021-12-09 23:51:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TeamSettingsPage;
|