import Link from "next/link"; import { useSearchParams } from "next/navigation"; import { useRouter } from "next/navigation"; import { useState } from "react"; import InviteLinkSettingsModal from "@calcom/ee/teams/components/InviteLinkSettingsModal"; 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 { MembershipRole } from "@calcom/prisma/enums"; 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 { Check, Edit2, ExternalLink, Globe, Link as LinkIcon, LogOut, MoreHorizontal, Send, Trash, X, } from "@calcom/ui/components/icon"; import { useOrgBranding } from "../../organizations/context/provider"; 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 searchParams = useSearchParams(); const { t, i18n } = useLocale(); const utils = trpc.useContext(); const team = props.team; const showDialog = searchParams?.get("inviteModal") === "true"; const [openMemberInvitationModal, setOpenMemberInvitationModal] = useState(showDialog); const [openInviteLinkSettingsModal, setOpenInviteLinkSettingsModal] = useState(false); const teamQuery = trpc.viewer.teams.get.useQuery({ teamId: team?.id }); const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation(); const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({ onSuccess: () => { showToast(t("success"), "success"); utils.viewer.teams.get.invalidate(); utils.viewer.teams.list.invalidate(); utils.viewer.teams.hasTeamPlan.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 orgBranding = useOrgBranding(); 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 = (