import { useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { RouterOutputs, trpc } from "@calcom/trpc/react";
import { Card, showToast } from "@calcom/ui";
import { FiUserPlus, FiUsers, FiEdit } from "@calcom/ui/components/icon";
import TeamListItem from "./TeamListItem";
interface Props {
teams: RouterOutputs["viewer"]["teams"]["list"];
}
export default function TeamList(props: Props) {
const utils = trpc.useContext();
const { t } = useLocale();
const [hideDropdown, setHideDropdown] = useState(false);
function selectAction(action: string, teamId: number) {
switch (action) {
case "disband":
deleteTeam(teamId);
break;
}
}
const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({
async onSuccess() {
await utils.viewer.teams.list.invalidate();
await utils.viewer.teams.hasTeamPlan.invalidate();
},
async onError(err) {
showToast(err.message, "error");
},
});
function deleteTeam(teamId: number) {
deleteTeamMutation.mutate({ teamId });
}
return (
{props.teams.map((team) => (
selectAction(action, team?.id as number)}
isLoading={deleteTeamMutation.isLoading}
hideDropdown={hideDropdown}
setHideDropdown={setHideDropdown}
/>
))}
{/* only show recommended steps when there is only one team */}
{props.teams.length === 1 && (
<>
{props.teams.map(
(team, i) =>
i === 0 && (
{t("recommended_next_steps")}
}
variant="basic"
title={t("invite_team_member")}
description={t("meetings_are_better_with_the_right")}
actionButton={{
href: "/settings/teams/" + team.id + "/members",
child: t("invite"),
}}
/>
{/* @TODO: uncomment once managed event types is live
}
variant="basic"
title={t("create_a_managed_event")}
description={t("create_a_one_one_template")}
actionButton={{
href:
"/event-types?dialog=new-eventtype&eventPage=team%2F" +
team.slug +
"&teamId=" +
team.id +
"&managed=true",
child: t("create"),
}}
/> */}
}
variant="basic"
title={t("collective_or_roundrobin")}
description={t("book_your_team_members")}
actionButton={{
href:
"/event-types?dialog=new-eventtype&eventPage=team%2F" +
team.slug +
"&teamId=" +
team.id,
child: t("create"),
}}
/>
}
variant="basic"
title={t("appearance")}
description={t("appearance_subtitle")}
actionButton={{
href: "/settings/teams/" + team.id + "/appearance",
child: t("edit"),
}}
/>
)
)}
>
)}
);
}