| 1 | /** biome-ignore-all lint/a11y/useValidAriaRole: the role being passed isn't aria-role but user role */ |
| 2 | |
| 3 | import { useRouter } |
| 4 | import { Users, X |
| 5 | import { useAction } |
| 6 | import { toast } |
| 7 | import { Avatar, AvatarFallback |
| 8 | import { Badge } |
| 9 | import { Button } |
| 10 | import { |
| 11 | Empty, |
| 12 | EmptyDescription, |
| 13 | EmptyHeader, |
| 14 | EmptyMedia, |
| 15 | EmptyTitle, |
| 16 | } from '@/components/ui/empty' |
| 17 | import { |
| 18 | Table, |
| 19 | TableBody, |
| 20 | TableCell, |
| 21 | TableHead, |
| 22 | TableHeader, |
| 23 | TableRow, |
| 24 | } from '@/components/ui/table' |
| 25 | import { removeMemberAction } |
| 26 | import type { OrgMember, |
| 27 | import InviteDialog from './invite-dialog |
| 28 | import PendingInvitationsBlock from './pending-invitations |
| 29 | |
| 30 | export default function MembersSection |
| 31 | projectId, |
| 32 | orgSlug, |
| 33 | projectSlug, |
| 34 | organizationId, |
| 35 | projectMembers, |
| 36 | pendingInvitations, |
| 37 | canManage, |
| 38 | showInviteDialog, |
| 39 | onShowInviteDialogChange, |
| 40 | orgMembers, |
| 41 | defaultMemberRate, |
| 42 | defaultCurrency, |
| 43 | }: { |
| 44 | projectId: string |
| 45 | orgSlug: string |
| 46 | projectSlug: string |
| 47 | organizationId: string |
| 48 | projectMembers: ProjectMember |
| 49 | pendingInvitations: PendingInvitation |
| 50 | canManage: boolean |
| 51 | showInviteDialog: boolean |
| 52 | onShowInviteDialogChange: (open |
| 53 | orgMembers: OrgMember |
| 54 | defaultMemberRate: number |
| 55 | defaultCurrency: string |
| 56 | }) { |
| 57 | const router = |
| 58 | |
| 59 | const { execute: |
| 60 | onSuccess() { |
| 61 | toast.success('Member removed from project |
| 62 | router.refresh() |
| 63 | }, |
| 64 | onError({ error |
| 65 | toast.error(error |
| 66 | }, |
| 67 | }) |
| 68 | |
| 69 | if ( |
| 70 | projectMembers.length === 0 |
| 71 | pendingInvitations.length === 0 |
| 72 | !canManage |
| 73 | ) { |
| 74 | return ( |
| 75 | <Empty> |
| 76 | <EmptyHeader> |
| 77 | <EmptyMedia variant=' |
| 78 | <Users /> |
| 79 | </EmptyMedia> |
| 80 | <EmptyTitle>No members assigned</EmptyTitle |
| 81 | <EmptyDescription> |
| 82 | No team members have been added to this project yet. |
| 83 | </EmptyDescription> |
| 84 | </EmptyHeader> |
| 85 | </Empty> |
| 86 | ) |
| 87 | } |
| 88 | |
| 89 | return ( |
| 90 | <> |
| 91 | {canManage && ( |
| 92 | <PendingInvitationsBlock |
| 93 | invitations={pendingInvitations} |
| 94 | organizationId={organizationId} |
| 95 | /> |
| 96 | )} |
| 97 | |
| 98 | {projectMembers.length === |
| 99 | <Empty> |
| 100 | <EmptyHeader> |
| 101 | <EmptyMedia variant=' |
| 102 | <Users /> |
| 103 | </EmptyMedia> |
| 104 | <EmptyTitle>No members yet</EmptyTitle |
| 105 | <EmptyDescription> |
| 106 | Invite team members by email to collaborate on this project. |
| 107 | </EmptyDescription> |
| 108 | </EmptyHeader> |
| 109 | </Empty> |
| 110 | ) : ( |
| 111 | <Table> |
| 112 | <TableHeader> |
| 113 | <TableRow> |
| 114 | <TableHead>Member</TableHead |
| 115 | <TableHead>Project Role</TableHead |
| 116 | <TableHead>Org Role</TableHead |
| 117 | {canManage && <TableHead |
| 118 | </TableRow> |
| 119 | </TableHeader> |
| 120 | <TableBody> |
| 121 | {projectMembers.map(( |
| 122 | <TableRow key={ |
| 123 | <TableCell> |
| 124 | <div className='flex items-center gap-3 |
| 125 | <Avatar className=' |
| 126 | <AvatarImage alt={ |
| 127 | <AvatarFallback> |
| 128 | {m.userName.substring |
| 129 | </AvatarFallback> |
| 130 | </Avatar> |
| 131 | <div> |
| 132 | <div className='flex items-center gap-1.5 |
| 133 | <span className='font-medium text-sm |
| 134 | {m.userName} |
| 135 | </span> |
| 136 | {m.source.startsWith |
| 137 | <Badge |
| 138 | className='capitalize leading-none' |
| 139 | variant='outline' |
| 140 | > |
| 141 | {m.source.replace |
| 142 | </Badge> |
| 143 | )} |
| 144 | {m.source === |
| 145 | <Badge className=' |
| 146 | via {m.teamName} |
| 147 | </Badge> |
| 148 | )} |
| 149 | </div> |
| 150 | <div className='text-muted-foreground text-xs |
| 151 | {m.userEmail} |
| 152 | </div> |
| 153 | </div> |
| 154 | </div> |
| 155 | </TableCell> |
| 156 | <TableCell> |
| 157 | <Badge className=' |
| 158 | {m.projectRole} |
| 159 | </Badge> |
| 160 | </TableCell> |
| 161 | <TableCell> |
| 162 | <Badge className=' |
| 163 | {m.orgRole} |
| 164 | </Badge> |
| 165 | </TableCell> |
| 166 | {canManage && ( |
| 167 | <TableCell> |
| 168 | {m.source === |
| 169 | <Button |
| 170 | onClick={() => |
| 171 | executeRemove({ |
| 172 | assignmentId: m.assignmentId |
| 173 | orgSlug, |
| 174 | projectSlug, |
| 175 | }) |
| 176 | } |
| 177 | variant='ghost' |
| 178 | > |
| 179 | <X className=' |
| 180 | </Button> |
| 181 | )} |
| 182 | </TableCell> |
| 183 | )} |
| 184 | </TableRow> |
| 185 | ))} |
| 186 | </TableBody> |
| 187 | </Table> |
| 188 | )} |
| 189 | |
| 190 | <InviteDialog |
| 191 | defaultCurrency={defaultCurrency} |
| 192 | defaultMemberRate={defaultMemberRate} |
| 193 | label='Member' |
| 194 | onOpenChange={onShowInviteDialogChange} |
| 195 | open={showInviteDialog} |
| 196 | organizationId={organizationId} |
| 197 | orgMembers={orgMembers} |
| 198 | projectId={projectId} |
| 199 | projectMembers={projectMembers} |
| 200 | role='member' |
| 201 | /> |
| 202 | </> |
| 203 | ) |
| 204 | } |