import { useState, FC } from "react"; import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { ChevronDown, XCircle } from "lucide-react"; // hooks import { useMember, useUser } from "hooks/store"; import useToast from "hooks/use-toast"; // components import { ConfirmWorkspaceMemberRemove } from "components/workspace"; // ui import { CustomSelect, Tooltip } from "@plane/ui"; // constants import { EUserWorkspaceRoles, ROLE } from "constants/workspace"; type Props = { invitationId: string; }; export const WorkspaceInvitationsListItem: FC = observer((props) => { const { invitationId } = props; // states const [removeMemberModal, setRemoveMemberModal] = useState(false); // router const router = useRouter(); const { workspaceSlug } = router.query; // store hooks const { membership: { currentWorkspaceMemberInfo, currentWorkspaceRole }, } = useUser(); const { workspace: { updateMemberInvitation, deleteMemberInvitation, getWorkspaceInvitationDetails }, } = useMember(); // toast alert const { setToastAlert } = useToast(); // derived values const invitationDetails = getWorkspaceInvitationDetails(invitationId); const handleRemoveInvitation = async () => { if (!workspaceSlug || !invitationDetails) return; await deleteMemberInvitation(workspaceSlug.toString(), invitationDetails.id) .then(() => { setToastAlert({ type: "success", title: "Success", message: "Invitation removed successfully.", }); }) .catch((err) => setToastAlert({ type: "error", title: "Error", message: err?.error || "Something went wrong. Please try again.", }) ); }; if (!invitationDetails) return null; // is the current logged in user admin const isAdmin = currentWorkspaceRole === EUserWorkspaceRoles.ADMIN; // role change access- // 1. user cannot change their own role // 2. only admin or member can change role // 3. user cannot change role of higher role const hasRoleChangeAccess = currentWorkspaceRole && [EUserWorkspaceRoles.ADMIN, EUserWorkspaceRoles.MEMBER].includes(currentWorkspaceRole); if (!currentWorkspaceMemberInfo) return null; return ( <> setRemoveMemberModal(false)} userDetails={{ id: invitationDetails.id, display_name: `${invitationDetails.email}`, }} onSubmit={handleRemoveInvitation} />
{(invitationDetails.email ?? "?")[0]}

{invitationDetails.email}

Pending

{ROLE[invitationDetails.role]} {hasRoleChangeAccess && ( )}
} value={invitationDetails.role} onChange={(value: EUserWorkspaceRoles) => { if (!workspaceSlug || !value) return; updateMemberInvitation(workspaceSlug.toString(), invitationDetails.id, { role: value, }).catch(() => { setToastAlert({ type: "error", title: "Error!", message: "An error occurred while updating member role. Please try again.", }); }); }} disabled={!hasRoleChangeAccess} placement="bottom-end" > {Object.keys(ROLE).map((key) => { if (currentWorkspaceRole && currentWorkspaceRole !== 20 && currentWorkspaceRole < parseInt(key)) return null; return ( <>{ROLE[parseInt(key) as keyof typeof ROLE]} ); })}
); });