| 1 | import { Globe, Mail, MapPin } from "lucide-react"; |
| 2 | import { notFound } |
| 3 | import { Suspense } |
| 4 | |
| 5 | import { CursorPagination } |
| 6 | import { ProfileAvatar } |
| 7 | import { MembershipActions } |
| 8 | import { Badge } |
| 9 | import { buttonVariants } |
| 10 | import { Separator } |
| 11 | import { Skeleton } |
| 12 | import { |
| 13 | RepositoryReadme, |
| 14 | RepositoryReadmeSkeleton, |
| 15 | } from "@/components/repositories/repository-readme"; |
| 16 | import { ContributionGraphSkeleton } |
| 17 | import { |
| 18 | OrganizationTeamList, |
| 19 | OrganizationTeamListSkeleton, |
| 20 | } from "./organization-team-list"; |
| 21 | import { PeopleList, PeopleListSkeleton |
| 22 | import { PinnedRepositories } |
| 23 | import { ProfileContributions } |
| 24 | import { UserOrganizations } |
| 25 | import { createServerClient, getAdminOrganizations |
| 26 | import { plural } |
| 27 | import { cn } |
| 28 | |
| 29 | import { ProfileTabs } |
| 30 | import Link from "next/link |
| 31 | |
| 32 | export async function Profile |
| 33 | username, |
| 34 | viewer, |
| 35 | tab, |
| 36 | query, |
| 37 | cursor, |
| 38 | }: { |
| 39 | username: string |
| 40 | viewer: string |
| 41 | tab?: string |
| 42 | query: string |
| 43 | cursor?: string |
| 44 | }) { |
| 45 | const client = |
| 46 | const [profile, |
| 47 | client.GET("/api/users/{username} |
| 48 | client.GET("/api/organizations/{slug} |
| 49 | params: { path: { |
| 50 | }), |
| 51 | client.GET("/api/repositories/{username} |
| 52 | params: { |
| 53 | path: { username |
| 54 | query: { |
| 55 | limit: 20, |
| 56 | q: query || |
| 57 | cursor, |
| 58 | }, |
| 59 | }, |
| 60 | }), |
| 61 | ]); |
| 62 | |
| 63 | if (response.status |
| 64 | notFound(); |
| 65 | } |
| 66 | |
| 67 | if (error || |
| 68 | throw new Error( |
| 69 | } |
| 70 | |
| 71 | const org = |
| 72 | // May create repositories here: the user themselves, or an admin of the organization. |
| 73 | const isViewer = |
| 74 | ? (await getAdminOrganizations |
| 75 | : viewer === username |
| 76 | |
| 77 | return ( |
| 78 | <main className="mx-auto grid w-full max-w-6xl flex-1 gap-8 px-4 py-8 md:px-6 md:grid-cols-[280px_1fr] |
| 79 | <aside className="flex flex-col gap-4 |
| 80 | <ProfileAvatar |
| 81 | name={username} |
| 82 | image={org ? |
| 83 | className={cn( |
| 84 | "size-40 md:size-64", |
| 85 | org ? "rounded-2xl" |
| 86 | )} |
| 87 | fallbackClassName="text-4xl" |
| 88 | /> |
| 89 | |
| 90 | <div className="flex flex-col gap-1 |
| 91 | <h1 className="text-2xl font-semibold tracking-tight |
| 92 | {org?.name ?? |
| 93 | </h1> |
| 94 | <p className="flex items-center gap-2 text-lg text-muted-foreground |
| 95 | {username} |
| 96 | {org && <Badge |
| 97 | </p> |
| 98 | {org?.description && |
| 99 | <p className="pt-1 text-sm text-balance |
| 100 | )} |
| 101 | </div> |
| 102 | |
| 103 | {org && (org |
| 104 | <ul className="flex flex-col gap-1.5 text-sm text-muted-foreground |
| 105 | {org.location && |
| 106 | <li className="flex items-center gap-2 |
| 107 | <MapPin className=" |
| 108 | {org.location} |
| 109 | </li> |
| 110 | )} |
| 111 | {org.website && |
| 112 | <li className="flex min-w-0 items-center gap-2 |
| 113 | <Globe className=" |
| 114 | <a |
| 115 | href={org.website |
| 116 | rel="nofollow noopener noreferrer" |
| 117 | target="_blank" |
| 118 | className="truncate hover:underline" |
| 119 | > |
| 120 | {org.website.replace |
| 121 | </a> |
| 122 | </li> |
| 123 | )} |
| 124 | {org.email && |
| 125 | <li className="flex min-w-0 items-center gap-2 |
| 126 | <Mail className=" |
| 127 | <a |
| 128 | href={`mailto:${org |
| 129 | className="truncate hover:underline" |
| 130 | > |
| 131 | {org.email} |
| 132 | </a> |
| 133 | </li> |
| 134 | )} |
| 135 | </ul> |
| 136 | )} |
| 137 | |
| 138 | {org?.viewerRole && |
| 139 | <MembershipActions |
| 140 | slug={username} |
| 141 | isPublic={ |
| 142 | org.members.find |
| 143 | ?.public ?? false |
| 144 | } |
| 145 | /> |
| 146 | )} |
| 147 | {org && isViewer |
| 148 | <Link |
| 149 | href={`/${username |
| 150 | className={buttonVariants({ |
| 151 | className: "w-full", |
| 152 | variant: "outline", |
| 153 | })} |
| 154 | > |
| 155 | Settings |
| 156 | </Link> |
| 157 | )} |
| 158 | {!org && isViewer |
| 159 | <Link |
| 160 | href="/settings" |
| 161 | className={buttonVariants({ |
| 162 | className: "w-full", |
| 163 | variant: "outline", |
| 164 | })} |
| 165 | > |
| 166 | Edit profile |
| 167 | </Link> |
| 168 | )} |
| 169 | <Separator /> |
| 170 | |
| 171 | <p className="text-sm text-muted-foreground |
| 172 | {org |
| 173 | ? [ |
| 174 | // Membership is private: only members are told how many there are. |
| 175 | org.viewerRole && |
| 176 | plural( |
| 177 | org.repositoryCount, |
| 178 | "public repository", |
| 179 | "public repositories", |
| 180 | ), |
| 181 | ] |
| 182 | .filter(Boolean) |
| 183 | .join(" · ") |
| 184 | : profile.data |
| 185 | ? `${profile.data |
| 186 | : "No bio yet."} |
| 187 | </p> |
| 188 | </aside> |
| 189 | |
| 190 | <section className="flex flex-col gap-6 |
| 191 | <ProfileTabs |
| 192 | username={username} |
| 193 | isViewer={isViewer} |
| 194 | owners={viewer ? |
| 195 | extraTabs={ |
| 196 | org |
| 197 | ? [ |
| 198 | { |
| 199 | value: "people", |
| 200 | label: "People", |
| 201 | content: ( |
| 202 | <PeopleList |
| 203 | empty={ |
| 204 | org.viewerRole |
| 205 | ? `${username} has no members yet. |
| 206 | : `Nobody in ${username} |
| 207 | } |
| 208 | > |
| 209 | {org.members.map |
| 210 | <PersonCard |
| 211 | key={member.username |
| 212 | handle={member.username |
| 213 | name={member.name |
| 214 | image={member.image |
| 215 | /> |
| 216 | ))} |
| 217 | </PeopleList> |
| 218 | ), |
| 219 | }, |
| 220 | // Teams are for members only. |
| 221 | ...(org.viewerRole |
| 222 | ? [ |
| 223 | { |
| 224 | value: "teams", |
| 225 | label: "Teams", |
| 226 | content: ( |
| 227 | <Suspense |
| 228 | fallback={<OrganizationTeamListSkeleton |
| 229 | > |
| 230 | <OrganizationTeamList slug={ |
| 231 | </Suspense> |
| 232 | ), |
| 233 | }, |
| 234 | ] |
| 235 | : []), |
| 236 | ] |
| 237 | : [ |
| 238 | { |
| 239 | value: "organizations", |
| 240 | label: "Organizations", |
| 241 | content: ( |
| 242 | <Suspense fallback={ |
| 243 | <UserOrganizations |
| 244 | username={username} |
| 245 | isViewer={isViewer} |
| 246 | /> |
| 247 | </Suspense> |
| 248 | ), |
| 249 | }, |
| 250 | ] |
| 251 | } |
| 252 | defaultTab={tab === |
| 253 | repositories={data.repositories |
| 254 | query={query} |
| 255 | pagination={ |
| 256 | <CursorPagination |
| 257 | pathname={`/${username |
| 258 | params={{ tab: |
| 259 | cursor={cursor} |
| 260 | nextCursor={data.nextCursor |
| 261 | /> |
| 262 | } |
| 263 | overview={ |
| 264 | <> |
| 265 | <Suspense fallback={ |
| 266 | {/* The README of user/user is that person's bio; an organization's lives at .ghost/profile/README.md. */ |
| 267 | <RepositoryReadme |
| 268 | owner={username} |
| 269 | slug={org ? |
| 270 | path={org ? |
| 271 | bare |
| 272 | fallback={ |
| 273 | <p className="text-sm text-muted-foreground |
| 274 | {username} hasn' |
| 275 | </p> |
| 276 | } |
| 277 | /> |
| 278 | </Suspense> |
| 279 | {org && org |
| 280 | <PinnedRepositories owner={ |
| 281 | )} |
| 282 | {!org && ( |
| 283 | <Suspense fallback={ |
| 284 | <ProfileContributions username={ |
| 285 | </Suspense> |
| 286 | )} |
| 287 | </> |
| 288 | } |
| 289 | /> |
| 290 | </section> |
| 291 | </main> |
| 292 | ); |
| 293 | } |
| 294 | |
| 295 | export function ProfileSkeleton() |
| 296 | return ( |
| 297 | <main className="mx-auto grid w-full max-w-6xl flex-1 gap-8 px-4 py-8 md:px-6 md:grid-cols-[280px_1fr] |
| 298 | <aside className="flex flex-col gap-4 |
| 299 | <Skeleton className=" |
| 300 | <div className="flex flex-col gap-2 |
| 301 | <Skeleton className=" |
| 302 | <Skeleton className=" |
| 303 | </div> |
| 304 | <Skeleton className=" |
| 305 | </aside> |
| 306 | <section className="flex flex-col gap-6 |
| 307 | <Skeleton className=" |
| 308 | <RepositoryReadmeSkeleton bare /> |
| 309 | </section> |
| 310 | </main> |
| 311 | ); |
| 312 | } |