Files
t5de-hub/apps/web/app/console/console-nav.tsx
T
dhkatzandClaude Opus 5.5 7d708aebdb
Pull request / title (pull_request) Successful in 1s
CI / test (pull_request) Successful in 1m15s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped
feat: IMVU imports on the hub: grants, requests and the importer's job queue
Creators grant a catalog leave to import their IMVU products (whole shop less
exclusions, or listed products) from a linked IMVU account, agreeing to a versioned
consent text; the catalog's team accepts or declines. Requests queue covered
products (or add them to the library when imported already), suggest, or count.
Importers claim jobs with the catalog's importer key, get t5de-import tokens, and
the catalog registers imported revisions as published products owned by the creator.
Narrowing or withdrawing a grant withdraws products; unlinking suspends grants;
an hourly batch rechecks imported products with IMVU daily. Website: /imports and
the console's catalog imports page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 19:46:10 -08:00

81 lines
3.1 KiB
TypeScript

import Link from "next/link";
import { notFound, redirect } from "next/navigation";
import { cache } from "react";
import { NavLink } from "@/components/header-client";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { api, getMe, isModerator, unwrap, type ConsoleData, type Person } from "@/lib/api";
/** The signed-in moderator, or off to sign in; others get not found (these pages aren't for them). */
export async function requireModerator(path: string): Promise<Person> {
const me = await getMe();
if (!me) redirect(`/signin?next=${encodeURIComponent(path)}`);
if (!isModerator(me)) notFound();
return me;
}
/** The console as this person sees it (once per request); undefined if it isn't for them. */
const loadConsole = cache(async (): Promise<ConsoleData | undefined> => {
const answer = await api.console.get();
if (answer.error) return undefined;
return unwrap(answer);
});
/**
* The signed-in person and their console, or off to sign in. People who manage nothing get not found: the console
* is for those controlling a product, catalog or room.
*/
export async function requireConsole(path: string): Promise<{ me: Person; console: ConsoleData }> {
const me = await getMe();
if (!me) redirect(`/signin?next=${encodeURIComponent(path)}`);
const data = await loadConsole();
if (!data) notFound();
return { me, console: data };
}
type Section = ConsoleData["sections"][number];
// Settings are on the overview.
const tabs: { section: Section; href: string; label: string }[] = [
{ section: "overview", href: "/console", label: "Overview" },
{ section: "products", href: "/console/products", label: "Products" },
{ section: "catalogs", href: "/console/catalogs", label: "Catalogs" },
{ section: "cases", href: "/console/cases", label: "Cases" },
{ section: "people", href: "/console/people", label: "People" },
{ section: "blocks", href: "/console/blocks", label: "Blocks" },
{ section: "audit", href: "/console/audit", label: "Audit" },
];
/** The console's sections this person may see, and a reminder when sensitive actions need two-factor sign-in. */
export async function ConsoleNav() {
const data = await loadConsole();
const sections = new Set<Section>(data?.sections ?? ["overview"]);
const needed = data?.twoFactorNeededFor ?? [];
return (
<>
{needed.length > 0 && (
<Alert className="mb-6">
<AlertTitle>Turn on two-factor sign-in</AlertTitle>
<AlertDescription>
<span>
Some of what you can do here needs it ({needed.join(", ")}).{" "}
<Link href="/account" className="text-foreground underline underline-offset-4">
Turn it on in your account
</Link>
.
</span>
</AlertDescription>
</Alert>
)}
<nav className="mb-8 flex gap-1 border-b pb-3 text-sm">
{tabs
.filter((t) => sections.has(t.section))
.map((t) => (
<NavLink key={t.section} href={t.href} exact={t.section === "overview"}>
{t.label}
</NavLink>
))}
</nav>
</>
);
}