import { Link } from '@tanstack/react-router' import { useParams } from 'common' import { ArrowRightIcon, CheckIcon, ChevronRightIcon, XIcon } from 'lucide-react' import { memo, useMemo } from 'react' import { Badge, cn, HoverCard, HoverCardContent, HoverCardTrigger, ScrollArea, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { isInviteExpired } from '../Organization.utils' import { MemberActions } from './MemberActions' import { MEMBERS_GRID_CLASS } from './MembersList.constants' import { useTeamSettingsData } from './TeamSettingsDataContext' import { type RowComponentBaseProps } from '@/components/ui/InfiniteList' import { InlineLink } from '@/components/ui/InlineLink' import PartnerIcon from '@/components/ui/PartnerIcon' import { ProfileImage } from '@/components/ui/ProfileImage' import { type OrganizationRole } from '@/data/organization-members/organization-roles-query' import { type OrganizationMember } from '@/data/organizations/organization-members-query' import { pluralize } from '@/lib/helpers' import { useProfile } from '@/lib/profile' const MEMBER_ORIGIN_TO_MANAGED_BY = { vercel: 'vercel-marketplace', } as const export const MemberRow = memo(function MemberRow({ item: member, index, style, }: RowComponentBaseProps) { const { slug } = useParams() const { profile } = useProfile() const { roles, isLoadingRoles, totalNumOrgProjects } = useTeamSettingsData() const hasProjectScopedRoles = (roles?.project_scoped_roles ?? []).length > 0 const isInvitedUser = Boolean(member.invited_id) // Use generic avatar for all team members instead of attempting to fetch from GitHub const profileImageUrl = undefined const roleById = useMemo(() => { const map = new Map() for (const role of roles?.org_scoped_roles ?? []) map.set(role.id, role) for (const role of roles?.project_scoped_roles ?? []) map.set(role.id, role) return map }, [roles]) const roleRows = useMemo(() => { return member.role_ids.map((id) => { const role = roleById.get(id) const roleName = (role?.name ?? '').split('_')[0] const appliesToAllProjects = role?.projects.length === 0 const projectsApplied = role?.projects ?? [] return { id, roleName, appliesToAllProjects, projectsApplied } }) }, [member.role_ids, roleById]) const roleBreakdown = useMemo( () => roleRows.flatMap(({ id, roleName, appliesToAllProjects, projectsApplied }) => appliesToAllProjects ? [{ key: `${id}-all`, roleName, label: 'Organization' }] : projectsApplied.map((project) => ({ key: `${id}-${project.ref}`, roleName, label: project.name, })) ), [roleRows] ) const totalProjectsApplied = roleRows.reduce((sum, row) => sum + row.projectsApplied.length, 0) return (
{member.primary_email?.[0]?.toUpperCase()}
} />

{member.primary_email}

{member.gotrue_id === profile?.gotrue_id && You} {isInvitedUser && member.invited_at && ( {isInviteExpired(member.invited_at) ? 'Expired' : 'Invited'} )} {member.is_sso_user && SSO} {Boolean(member.metadata?.origin) && ( )}
{member.mfa_enabled ? ( ) : ( )} {member.mfa_enabled ? ( 'Member has MFA enabled' ) : ( Member does not have MFA enabled. You can enforce MFA from your organization's{' '} security settings, restricting access until members enable it. )}
{isLoadingRoles ? ( ) : roleRows.length > 1 ? (

Multiple roles

{totalProjectsApplied} {pluralize(totalProjectsApplied, 'project')}
5 ? 'h-[130px]' : '')}> {roleBreakdown.map(({ key, roleName, label }) => (
{roleName} {label}
))}
) : ( roleRows.map(({ id, roleName, appliesToAllProjects, projectsApplied }) => (

{roleName}

{hasProjectScopedRoles && ( <> {projectsApplied.length === 1 ? ( {projectsApplied[0].name} ) : ( {appliesToAllProjects ? 'Organization' : `${projectsApplied.length} ${pluralize(projectsApplied.length, 'project')}`} { // If the role is org scoped, don't list all projects appliesToAllProjects ? (

{roleName} role applies to {totalNumOrgProjects}{' '} {pluralize(totalNumOrgProjects, 'project')}

) : ( <>

{roleName} role applies to {projectsApplied.length}{' '} {pluralize(projectsApplied.length, 'project')}

5 ? 'h-[130px]' : '')} > {projectsApplied.map(({ ref, name }) => ( {name} Go to project ))}
) }
)} )}
)) )}
) })