import { MembershipRole } from "@prisma/client"; import Link from "next/link"; import { useRouter } from "next/router"; import { useState } from "react"; import MemberInvitationModal from "@calcom/ee/teams/components/MemberInvitationModal"; import classNames from "@calcom/lib/classNames"; import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; import { Avatar, Button, ButtonGroup, ConfirmationDialogContent, Dialog, DialogTrigger, Dropdown, DropdownItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, showToast, Tooltip, } from "@calcom/ui"; import { FiMoreHorizontal, FiCheck, FiX, FiLink, FiEdit2, FiExternalLink, FiTrash, FiLogOut, FiGlobe, FiSend, } from "@calcom/ui/components/icon"; import { TeamRole } from "./TeamPill"; interface Props { team: RouterOutputs["viewer"]["teams"]["list"][number]; key: number; onActionSelect: (text: string) => void; isLoading?: boolean; hideDropdown: boolean; setHideDropdown: (value: boolean) => void; } export default function TeamListItem(props: Props) { const { t, i18n } = useLocale(); const utils = trpc.useContext(); const team = props.team; const [openMemberInvitationModal, setOpenMemberInvitationModal] = useState(false); const teamQuery = trpc.viewer.teams.get.useQuery({ teamId: team?.id }); const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation({ async onSuccess() { await utils.viewer.teams.get.invalidate(); setOpenMemberInvitationModal(false); }, onError: (error) => { showToast(error.message, "error"); }, }); const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({ onSuccess: () => { utils.viewer.teams.list.invalidate(); utils.viewer.teams.listInvites.invalidate(); }, }); function acceptOrLeave(accept: boolean) { acceptOrLeaveMutation.mutate({ teamId: team?.id as number, accept, }); } const acceptInvite = () => acceptOrLeave(true); const declineInvite = () => acceptOrLeave(false); const isOwner = props.team.role === MembershipRole.OWNER; const isInvitee = !props.team.accepted; const isAdmin = props.team.role === MembershipRole.OWNER || props.team.role === MembershipRole.ADMIN; const { hideDropdown, setHideDropdown } = props; if (!team) return <>>; const teamInfo = (