2022-11-10 20:23:56 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { Alert, Button, EmptyScreen, Icon } from "@calcom/ui";
|
2022-11-10 20:23:56 +00:00
|
|
|
|
|
|
|
import SkeletonLoaderTeamList from "./SkeletonloaderTeamList";
|
|
|
|
import TeamList from "./TeamList";
|
|
|
|
|
|
|
|
export function TeamsListing() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const [errorMessage, setErrorMessage] = useState("");
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.teams.list.useQuery(undefined, {
|
2022-11-10 20:23:56 +00:00
|
|
|
onError: (e) => {
|
|
|
|
setErrorMessage(e.message);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const teams = data?.filter((m) => m.accepted) || [];
|
|
|
|
const invites = data?.filter((m) => !m.accepted) || [];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{!!errorMessage && <Alert severity="error" title={errorMessage} />}
|
|
|
|
{invites.length > 0 && (
|
|
|
|
<div className="mb-4">
|
|
|
|
<h1 className="mb-2 text-lg font-medium">{t("open_invitations")}</h1>
|
|
|
|
<TeamList teams={invites} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{isLoading && <SkeletonLoaderTeamList />}
|
|
|
|
{!teams.length && !isLoading && (
|
|
|
|
<EmptyScreen
|
|
|
|
Icon={Icon.FiUsers}
|
|
|
|
headline={t("no_teams")}
|
|
|
|
description={t("no_teams_description")}
|
|
|
|
buttonRaw={
|
|
|
|
<Button color="secondary" href={`${WEBAPP_URL}/settings/teams/new`}>
|
|
|
|
{t("create_team")}
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{teams.length > 0 && <TeamList teams={teams} />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|