| 1 | "use client"; |
| 2 | |
| 3 | import { UserRound } from |
| 4 | import Link from "next/link |
| 5 | import { useRouter } |
| 6 | import { Fragment, useState |
| 7 | import { toast } |
| 8 | |
| 9 | import { Avatar, AvatarFallback |
| 10 | import { Badge } |
| 11 | import { Button } |
| 12 | import { Card } |
| 13 | import { |
| 14 | Empty, |
| 15 | EmptyDescription, |
| 16 | EmptyHeader, |
| 17 | EmptyMedia, |
| 18 | EmptyTitle, |
| 19 | } from "@/components/ui/empty"; |
| 20 | import { |
| 21 | Item, |
| 22 | ItemActions, |
| 23 | ItemContent, |
| 24 | ItemDescription, |
| 25 | ItemGroup, |
| 26 | ItemMedia, |
| 27 | ItemSeparator, |
| 28 | ItemTitle, |
| 29 | } from "@/components/ui/item"; |
| 30 | import { apiClient, apiErrorMessage |
| 31 | import type { components |
| 32 | import { roleLabels } |
| 33 | |
| 34 | type Collaborator |
| 35 | |
| 36 | /** People with access to the organization's repositories who are not its members, and a way to take them off all of them at once. */ |
| 37 | export function OutsideCollaborators({ |
| 38 | slug, |
| 39 | collaborators, |
| 40 | }: { |
| 41 | slug: string |
| 42 | collaborators: Collaborator |
| 43 | }) { |
| 44 | const router = |
| 45 | const [removing, |
| 46 | |
| 47 | async function remove |
| 48 | setRemoving(username); |
| 49 | const { error |
| 50 | "/api/organizations/{slug}/outside-collaborators/{username}", |
| 51 | { params: { path: |
| 52 | ); |
| 53 | setRemoving(null); |
| 54 | if (error) return |
| 55 | toast.success(`${ |
| 56 | router.refresh(); |
| 57 | } |
| 58 | |
| 59 | return ( |
| 60 | <section> |
| 61 | <h2 className="mb-3 text-sm font-semibold |
| 62 | Outside collaborators |
| 63 | <span className="ml-2 font-normal text-muted-foreground tabular-nums |
| 64 | {collaborators.length} |
| 65 | </span> |
| 66 | </h2> |
| 67 | <Card className=" |
| 68 | {collaborators.length === |
| 69 | <Empty className=" |
| 70 | <EmptyHeader> |
| 71 | <EmptyMedia variant=" |
| 72 | <UserRound /> |
| 73 | </EmptyMedia> |
| 74 | <EmptyTitle>Nobody from outside</EmptyTitle |
| 75 | <EmptyDescription> |
| 76 | People invited to a repository without joining the organization |
| 77 | show up here. |
| 78 | </EmptyDescription> |
| 79 | </EmptyHeader> |
| 80 | </Empty> |
| 81 | ) : ( |
| 82 | <ItemGroup className=" |
| 83 | {collaborators.map(( |
| 84 | <Fragment key={ |
| 85 | {index > 0 |
| 86 | <Item className=" |
| 87 | <ItemMedia> |
| 88 | <Avatar className=" |
| 89 | <AvatarImage |
| 90 | src={collaborator.image |
| 91 | alt="" |
| 92 | /> |
| 93 | <AvatarFallback> |
| 94 | {collaborator.username.slice |
| 95 | </AvatarFallback> |
| 96 | </Avatar> |
| 97 | </ItemMedia> |
| 98 | <ItemContent className=" |
| 99 | <ItemTitle> |
| 100 | <Link |
| 101 | href={`/${collaborator |
| 102 | className="hover:underline" |
| 103 | > |
| 104 | {collaborator.username} |
| 105 | </Link> |
| 106 | </ItemTitle> |
| 107 | <ItemDescription className=" |
| 108 | {collaborator.repositories.map |
| 109 | <Badge |
| 110 | key={repository.slug |
| 111 | variant="outline" |
| 112 | className="font-normal" |
| 113 | > |
| 114 | <Link href={ |
| 115 | {repository.slug} |
| 116 | </Link> |
| 117 | · {roleLabels[repository.role |
| 118 | {repository.pending && |
| 119 | </Badge> |
| 120 | ))} |
| 121 | </ItemDescription> |
| 122 | </ItemContent> |
| 123 | <ItemActions> |
| 124 | <Button |
| 125 | size="sm" |
| 126 | variant="ghost" |
| 127 | disabled={removing !== |
| 128 | onClick={() => |
| 129 | > |
| 130 | Remove from all |
| 131 | </Button> |
| 132 | </ItemActions> |
| 133 | </Item> |
| 134 | </Fragment> |
| 135 | ))} |
| 136 | </ItemGroup> |
| 137 | )} |
| 138 | </Card> |
| 139 | </section> |
| 140 | ); |
| 141 | } |