import { Suspense, useState } from "react";
import MemberInvitationModal from "@calcom/features/ee/teams/components/MemberInvitationModal";
import { classNames } from "@calcom/lib";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Icon } from "@calcom/ui";
import { Avatar } from "@calcom/ui/components/avatar";
import { Badge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { SkeletonContainer, SkeletonText } from "@calcom/ui/v2/core/skeleton";
const AddNewTeamMemberSkeleton = () => {
return (
);
};
const AddNewTeamMembers = (props: { teamId: number }) => {
const { t } = useLocale();
const utils = trpc.useContext();
const { data: team, isLoading } = trpc.useQuery(["viewer.teams.get", { teamId: props.teamId }]);
const removeMemberMutation = trpc.useMutation("viewer.teams.removeMember", {
onSuccess() {
utils.invalidateQueries(["viewer.teams.get", { teamId: props.teamId }]);
utils.invalidateQueries(["viewer.teams.list"]);
},
});
const [memberInviteModal, setMemberInviteModal] = useState(false);
if (isLoading) return ;
return (
}>
<>
<>
{team?.members.map((member, index) => (
{member?.name || t("team_member")}
{/* Assume that the first member of the team is the creator */}
{index === 0 &&
{t("you")} }
{!member.accepted &&
{t("pending")} }
{member.role === "MEMBER" &&
{t("member")} }
{member.role === "ADMIN" &&
{t("admin")} }
{member.username ? (
{`${WEBAPP_URL}/${member?.username}`}
) : (
{t("not_on_cal")}
)}
{member.role !== "OWNER" && (
removeMemberMutation.mutate({ teamId: props.teamId, memberId: member.id })}
/>
)}
))}
setMemberInviteModal(true)}
className="mt-6 w-full justify-center">
{t("add_team_member")}
>
{team && (
setMemberInviteModal(false)}
team={team}
currentMember={team?.membership.role}
/>
)}
{t("finish")}
>
);
};
export default AddNewTeamMembers;