2023-08-02 09:35:48 +00:00
|
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
2023-06-06 23:34:14 +00:00
|
|
|
import { useEffect, useMemo, useState } from "react";
|
2022-11-10 20:23:56 +00:00
|
|
|
|
2023-07-07 16:48:51 +00:00
|
|
|
import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-07-10 14:44:22 +00:00
|
|
|
import { Alert, Button, ButtonGroup, EmptyScreen, Label, showToast } from "@calcom/ui";
|
2023-06-06 23:34:14 +00:00
|
|
|
import { EyeOff, Mail, RefreshCcw, UserPlus, Users, Video } from "@calcom/ui/components/icon";
|
2022-11-10 20:23:56 +00:00
|
|
|
|
2023-01-23 09:58:41 +00:00
|
|
|
import { UpgradeTip } from "../../../tips";
|
2022-11-10 20:23:56 +00:00
|
|
|
import SkeletonLoaderTeamList from "./SkeletonloaderTeamList";
|
|
|
|
import TeamList from "./TeamList";
|
|
|
|
|
|
|
|
export function TeamsListing() {
|
2023-08-02 09:35:48 +00:00
|
|
|
const searchParams = useSearchParams();
|
|
|
|
const token = searchParams?.get("token");
|
2022-11-10 20:23:56 +00:00
|
|
|
const { t } = useLocale();
|
2023-06-06 23:34:14 +00:00
|
|
|
const trpcContext = trpc.useContext();
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const [inviteTokenChecked, setInviteTokenChecked] = useState(false);
|
2022-11-10 20:23:56 +00:00
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.teams.list.useQuery(undefined, {
|
2023-06-06 23:34:14 +00:00
|
|
|
enabled: inviteTokenChecked,
|
2022-11-10 20:23:56 +00:00
|
|
|
onError: (e) => {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-07-07 16:48:51 +00:00
|
|
|
const { data: user } = trpc.viewer.me.useQuery();
|
|
|
|
|
2023-06-06 23:34:14 +00:00
|
|
|
const { mutate: inviteMemberByToken } = trpc.viewer.teams.inviteMemberByToken.useMutation({
|
|
|
|
onSuccess: (teamName) => {
|
|
|
|
trpcContext.viewer.teams.list.invalidate();
|
|
|
|
showToast(t("team_invite_received", { teamName }), "success");
|
|
|
|
},
|
|
|
|
onError: (e) => {
|
|
|
|
showToast(e.message, "error");
|
|
|
|
},
|
|
|
|
onSettled: () => {
|
|
|
|
setInviteTokenChecked(true);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-01-24 15:27:05 +00:00
|
|
|
const teams = useMemo(() => data?.filter((m) => m.accepted) || [], [data]);
|
|
|
|
const invites = useMemo(() => data?.filter((m) => !m.accepted) || [], [data]);
|
2022-11-10 20:23:56 +00:00
|
|
|
|
2022-12-05 22:20:33 +00:00
|
|
|
const features = [
|
|
|
|
{
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: <Users className="h-5 w-5 text-red-500" />,
|
2022-12-05 22:20:33 +00:00
|
|
|
title: t("collective_scheduling"),
|
|
|
|
description: t("make_it_easy_to_book"),
|
|
|
|
},
|
|
|
|
{
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: <RefreshCcw className="h-5 w-5 text-blue-500" />,
|
2022-12-05 22:20:33 +00:00
|
|
|
title: t("round_robin"),
|
|
|
|
description: t("find_the_best_person"),
|
|
|
|
},
|
|
|
|
{
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: <UserPlus className="h-5 w-5 text-green-500" />,
|
2022-12-05 22:20:33 +00:00
|
|
|
title: t("fixed_round_robin"),
|
|
|
|
description: t("add_one_fixed_attendee"),
|
|
|
|
},
|
2023-01-15 17:54:52 +00:00
|
|
|
{
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: <Mail className="h-5 w-5 text-orange-500" />,
|
2023-01-15 17:54:52 +00:00
|
|
|
title: t("sms_attendee_action"),
|
|
|
|
description: t("make_it_easy_to_book"),
|
|
|
|
},
|
|
|
|
{
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: <Video className="h-5 w-5 text-purple-500" />,
|
2023-01-15 17:54:52 +00:00
|
|
|
title: "Cal Video" + " " + t("recordings_title"),
|
|
|
|
description: t("upgrade_to_access_recordings_description"),
|
|
|
|
},
|
|
|
|
{
|
2023-04-12 15:26:31 +00:00
|
|
|
icon: <EyeOff className="h-5 w-5 text-indigo-500" />,
|
2023-01-15 17:54:52 +00:00
|
|
|
title: t("disable_cal_branding", { appName: APP_NAME }),
|
|
|
|
description: t("disable_cal_branding_description", { appName: APP_NAME }),
|
|
|
|
},
|
2022-12-05 22:20:33 +00:00
|
|
|
];
|
|
|
|
|
2023-06-06 23:34:14 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!router) return;
|
2023-08-02 09:35:48 +00:00
|
|
|
if (token) inviteMemberByToken({ token });
|
2023-06-06 23:34:14 +00:00
|
|
|
else setInviteTokenChecked(true);
|
2023-08-02 09:35:48 +00:00
|
|
|
}, [router, inviteMemberByToken, setInviteTokenChecked, token]);
|
2023-06-06 23:34:14 +00:00
|
|
|
|
|
|
|
if (isLoading || !inviteTokenChecked) {
|
2023-01-24 15:27:05 +00:00
|
|
|
return <SkeletonLoaderTeamList />;
|
|
|
|
}
|
|
|
|
|
2022-11-10 20:23:56 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{!!errorMessage && <Alert severity="error" title={errorMessage} />}
|
2023-01-24 15:27:05 +00:00
|
|
|
|
2023-04-20 20:56:38 +00:00
|
|
|
{invites.length > 0 && (
|
|
|
|
<div className="bg-subtle mb-6 rounded-md p-5">
|
|
|
|
<Label className=" text-emphasis pb-2 font-semibold">{t("pending_invites")}</Label>
|
|
|
|
<TeamList teams={invites} pending />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2023-01-23 09:58:41 +00:00
|
|
|
<UpgradeTip
|
2023-06-06 11:58:05 +00:00
|
|
|
title={t("calcom_is_better_with_team", { appName: APP_NAME })}
|
2023-01-23 09:58:41 +00:00
|
|
|
description="add_your_team_members"
|
|
|
|
features={features}
|
2023-04-10 21:14:28 +00:00
|
|
|
background="/tips/teams"
|
2023-01-23 09:58:41 +00:00
|
|
|
buttons={
|
2023-07-07 16:48:51 +00:00
|
|
|
!user?.organizationId || user?.organization.isOrgAdmin ? (
|
|
|
|
<div className="space-y-2 rtl:space-x-reverse sm:space-x-2">
|
|
|
|
<ButtonGroup>
|
|
|
|
<Button color="primary" href={`${WEBAPP_URL}/settings/teams/new`}>
|
|
|
|
{t("create_team")}
|
|
|
|
</Button>
|
|
|
|
<Button color="minimal" href="https://go.cal.com/teams-video" target="_blank">
|
|
|
|
{t("learn_more")}
|
|
|
|
</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<p>{t("org_admins_can_create_new_teams")}</p>
|
|
|
|
)
|
2023-01-23 09:58:41 +00:00
|
|
|
}>
|
2023-07-10 14:44:22 +00:00
|
|
|
{teams.length > 0 ? (
|
|
|
|
<TeamList teams={teams} />
|
|
|
|
) : (
|
|
|
|
<EmptyScreen
|
|
|
|
Icon={Users}
|
|
|
|
headline={t("create_team_to_get_started")}
|
|
|
|
description={t("create_first_team_and_invite_others")}
|
|
|
|
buttonRaw={
|
|
|
|
<Button
|
|
|
|
color="secondary"
|
|
|
|
href={`${WEBAPP_URL}/settings/teams/new?returnTo=${WEBAPP_URL}/teams`}>
|
|
|
|
{t(`create_new_team`)}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
2023-01-23 09:58:41 +00:00
|
|
|
</UpgradeTip>
|
2022-11-10 20:23:56 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|