2021-12-09 23:51:30 +00:00
|
|
|
import { useRouter } from "next/router";
|
2021-12-17 00:16:59 +00:00
|
|
|
import { useMemo, useState } from "react";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Alert } from "@calcom/ui/Alert";
|
2021-12-09 23:51:30 +00:00
|
|
|
import TeamAvailabilityScreen from "@ee/components/team/availability/TeamAvailabilityScreen";
|
|
|
|
|
|
|
|
import { getPlaceholderAvatar } from "@lib/getPlaceholderAvatar";
|
|
|
|
import { trpc } from "@lib/trpc";
|
|
|
|
|
|
|
|
import Loader from "@components/Loader";
|
2021-12-17 00:16:59 +00:00
|
|
|
import Shell, { useMeQuery } from "@components/Shell";
|
2021-12-09 23:51:30 +00:00
|
|
|
import Avatar from "@components/ui/Avatar";
|
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
export function TeamAvailabilityPage() {
|
2021-12-09 23:51:30 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
const me = useMeQuery();
|
|
|
|
const isFreeUser = me.data?.plan === "FREE";
|
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const { data: team, isLoading } = trpc.useQuery(["viewer.teams.get", { teamId: Number(router.query.id) }], {
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
onError: (e) => {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
// prevent unnecessary re-renders due to shell queries
|
|
|
|
const TeamAvailability = useMemo(() => {
|
|
|
|
return <TeamAvailabilityScreen team={team} />;
|
|
|
|
}, [team]);
|
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
return (
|
|
|
|
<Shell
|
2022-01-12 09:29:20 +00:00
|
|
|
backPath={!errorMessage ? `/settings/teams/${team?.id}` : undefined}
|
2021-12-17 00:16:59 +00:00
|
|
|
heading={!isFreeUser && team?.name}
|
2021-12-09 23:51:30 +00:00
|
|
|
flexChildrenContainer
|
2021-12-17 00:16:59 +00:00
|
|
|
subtitle={team && !isFreeUser && "Your team's availability at a glance"}
|
2021-12-09 23:51:30 +00:00
|
|
|
HeadingLeftIcon={
|
2021-12-17 00:16:59 +00:00
|
|
|
team &&
|
|
|
|
!isFreeUser && (
|
2021-12-09 23:51:30 +00:00
|
|
|
<Avatar
|
|
|
|
size={12}
|
|
|
|
imageSrc={getPlaceholderAvatar(team?.logo, team?.name as string)}
|
|
|
|
alt="Team Logo"
|
|
|
|
className="mt-1"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}>
|
|
|
|
{!!errorMessage && <Alert className="-mt-24 border" severity="error" title={errorMessage} />}
|
|
|
|
{isLoading && <Loader />}
|
2021-12-17 00:16:59 +00:00
|
|
|
{isFreeUser ? (
|
|
|
|
<Alert
|
|
|
|
className="-mt-24 border"
|
|
|
|
severity="warning"
|
|
|
|
title="This is a pro feature. Upgrade to pro to see your team's availability."
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
TeamAvailability
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
export default TeamAvailabilityPage;
|