import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { membership as membershipLabel } from "@/components/catalogs"; import { ActionForm, SubmitButton } from "@/components/forms"; import { PageHeader, Tag } from "@/components/status"; import { buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { api, getMe, unwrap } from "@/lib/api"; import { membership } from "../../console/catalogs/actions"; export const metadata: Metadata = { title: "Catalog" }; export default async function CatalogPage({ params, searchParams, }: { params: Promise<{ id: string }>; searchParams: Promise<{ invite?: string | string[] }>; }) { const { id } = await params; const raw = (await searchParams).invite; const invite = typeof raw === "string" && /^[a-z0-9]{1,32}$/.test(raw) ? raw : ""; const [me, answer] = await Promise.all([getMe(), api.catalogs({ id }).get()]); if (answer.error) notFound(); const data = unwrap(answer); const c = data.catalog; const manage = data.permissions.includes("audit:read"); return (
This catalog's team banned you from it.
) : data.membership === "member" || data.membership === "requested" ? (Nothing to join: get its products from their pages.
) : c.membership === "invite" && !invite ? (You need an invitation link from its team.
) : (