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-07-28 19:58:26 +00:00
|
|
|
import { getPlaceholderAvatar } from "@calcom/lib/getPlaceholderAvatar";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Alert, Avatar, Loader, Shell } from "@calcom/ui";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import LicenseRequired from "../../common/components/LicenseRequired";
|
|
|
|
import TeamAvailabilityScreen from "../components/TeamAvailabilityScreen";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
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("");
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data: team, isLoading } = trpc.viewer.teams.get.useQuery(
|
|
|
|
{ teamId: Number(router.query.id) },
|
|
|
|
{
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
onError: (e) => {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2021-12-09 23:51:30 +00:00
|
|
|
|
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}
|
2022-12-08 23:20:24 +00:00
|
|
|
heading={team?.name}
|
2021-12-09 23:51:30 +00:00
|
|
|
flexChildrenContainer
|
2022-12-08 23:20:24 +00:00
|
|
|
subtitle={team && "Your team's availability at a glance"}
|
2021-12-09 23:51:30 +00:00
|
|
|
HeadingLeftIcon={
|
2022-12-08 23:20:24 +00:00
|
|
|
team && (
|
2021-12-09 23:51:30 +00:00
|
|
|
<Avatar
|
2022-07-28 19:58:26 +00:00
|
|
|
size="sm"
|
2021-12-09 23:51:30 +00:00
|
|
|
imageSrc={getPlaceholderAvatar(team?.logo, team?.name as string)}
|
|
|
|
alt="Team Logo"
|
|
|
|
className="mt-1"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}>
|
2022-05-26 17:07:14 +00:00
|
|
|
<LicenseRequired>
|
|
|
|
{!!errorMessage && <Alert className="-mt-24 border" severity="error" title={errorMessage} />}
|
|
|
|
{isLoading && <Loader />}
|
2022-12-08 23:20:24 +00:00
|
|
|
{TeamAvailability}
|
2022-05-26 17:07:14 +00:00
|
|
|
</LicenseRequired>
|
2021-12-09 23:51:30 +00:00
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-17 00:16:59 +00:00
|
|
|
export default TeamAvailabilityPage;
|