Skip to documentation

Design system / Sources & standards

Current repository source

consoleShell.tsx

src/components/navigation/instances/consoleShell.tsx

This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.

"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import type { ReactNode } from "react";
import { AppShell } from "../appShell";
import { Footer } from "../footer";
import { TopNav } from "../topNav";
import { AuthButton } from "../authButton";
import { SidebarNav } from "../sidebarNav";
import { SidebarShell } from "../sidebarShell";
import { useSidebarPreferences } from "../useSidebarPreferences";
import { BreadcrumbTrail } from "../breadcrumbTrail";
import { buildConsoleSidebarSections, isConsoleCatalogue, isConsoleReviewTask, isConsoleSubmissionCollection, isFocusedConsoleTask } from "./consoleNavigation";
import { buildConsoleNavItems } from "./consoleNavItems";
import type { BreadcrumbItem } from "../types";
import type { ConsoleRole } from "@/lib/auth/console-tenant-contract";
import type { ConsoleManagementNavigation } from "@/lib/domains/console/submission-programs/navigation";

export type ConsoleShellProps = {
  children: ReactNode;
  tenantSlug?: string;
  tenantName?: string;
  userDisplayName?: string;
  userEmail?: string;
  roles?: readonly ConsoleRole[];
  /** @deprecated Read role assignments through `roles`. */
  roleName?: string | null;
  isAuthenticated?: boolean;
  breadcrumbs?: BreadcrumbItem[];
  managementNavigation?: ConsoleManagementNavigation;
  hasReviewAssignments?: boolean;
  hasSubmissionActivity?: boolean;
};

export function ConsoleShell({
  children,
  tenantSlug,
  tenantName,
  userDisplayName,
  userEmail,
  roles = [],
  roleName,
  isAuthenticated = false,
  breadcrumbs,
  managementNavigation = { mode: "basic", programs: [] },
  hasReviewAssignments = false,
  hasSubmissionActivity = false,
}: ConsoleShellProps) {
  const pathname = usePathname() ?? "";
  const sectionExpansion = useSidebarPreferences(tenantSlug ?? "");
  const focused = isFocusedConsoleTask(pathname, tenantSlug);
  const navItems = buildConsoleNavItems(
    tenantSlug,
    [],
    { isProgramManager: false, isEditionCreator: false, isAnyEditionManager: false, hasReviewAssignments, hasSubmissionActivity },
  ).map((item) => ({ ...item, isCurrent: pathname === item.href }));
  const advanced = Boolean(tenantSlug && managementNavigation.mode === "advanced" && !focused && !isConsoleCatalogue(pathname, tenantSlug));
  const displayName = userDisplayName?.trim() || "Account";
  // The server may use email as a missing-name fallback. Keep that inside the topbar menu.
  const accountDisplayName = !advanced && displayName.toLowerCase() === userEmail?.trim().toLowerCase() ? "Account" : displayName;
  const account = <AuthButton isAuthenticated={isAuthenticated} signInHref="/console/sign-in" signOutHref={tenantSlug ? `/console/${tenantSlug}/logout` : "/console/sign-out"} userDisplayName={accountDisplayName} userEmail={userEmail} presentation={advanced ? "sidebar" : "topbar"} />;

  if (tenantSlug && advanced) {
    const sections = buildConsoleSidebarSections({ tenantSlug, pathname, management: managementNavigation, roles: roles.length ? roles : roleName ?? [], hasReviewAssignments, hasSubmissionActivity });
    const destinations = sections.flatMap((section) => [...section.items.flatMap((item) => [item, ...(item.children ?? [])]), ...(section.action ? [section.action] : [])]);
    const selected = destinations.find((item) => item.isCurrent) ?? destinations.filter((item) => "isAncestor" in item && item.isAncestor).sort((left, right) => (right.href?.length ?? 0) - (left.href?.length ?? 0))[0];
    const currentProgram = managementNavigation.programs.find((program) => {
      const href = `/console/${tenantSlug}/admin/programs/${program.programCode}`;
      return pathname === href || pathname.startsWith(`${href}/`);
    });
    const sectionTitle = sections.find((section) => section.href === pathname)?.label;
    const editionListHref = currentProgram ? `/console/${tenantSlug}/admin/programs/${currentProgram.programCode}/editions` : undefined;
    const inEditionCollection = Boolean(editionListHref && (pathname === editionListHref || pathname.startsWith(`${editionListHref}/`)));
    const trail: BreadcrumbItem[] = breadcrumbs ?? [
      { label: tenantName ?? "Events Console", href: `/console/${tenantSlug}`, isCurrent: pathname === `/console/${tenantSlug}` },
      ...(inEditionCollection && currentProgram ? [{ label: currentProgram.editionLabelPlural, href: editionListHref, isCurrent: pathname === editionListHref }] : currentProgram?.canOpenProgram ? [{ label: currentProgram.title, href: `/console/${tenantSlug}/admin/programs/${currentProgram.programCode}`, isCurrent: pathname === `/console/${tenantSlug}/admin/programs/${currentProgram.programCode}` }] : []),
      ...(selected && selected.id !== "home" && (inEditionCollection || selected.label !== currentProgram?.title) && !(selected.id === "all-programs" && currentProgram) ? [{ label: selected.label }] : []),
      ...(!selected && sectionTitle ? [{ label: sectionTitle }] : []),
    ];
    return (
      <SidebarShell
        persistenceKey={`cxh:drawer:v1:${encodeURIComponent(tenantSlug)}`}
        brand={null}
        navigation={(onNavigate) => <SidebarNav sections={sections} density="compact" sectionExpansion={sectionExpansion} onNavigate={(href) => {
          // Catalogue unmounts the drawer. Dismissal must not overwrite its saved choice.
          if (!isConsoleCatalogue(href, tenantSlug)) onNavigate?.();
        }} />}
        location={<BreadcrumbTrail items={trail} />}
        account={account}
        navigationTitle="Workspace navigation"
        navigationDescription="Browse your workspace, available work, Programs and administration tools."
      >
        {children}
      </SidebarShell>
    );
  }

  return (
    <AppShell
      className={focused ? "console-shell-focused" : "console-shell-basic"}
      contentLayout={focused && !isConsoleReviewTask(pathname, tenantSlug) && !isConsoleSubmissionCollection(pathname, tenantSlug) ? "focused" : "contained"}
      header={
        <TopNav
          brand={
            <Link href={tenantSlug ? `/console/${tenantSlug}` : "/console"} aria-current={pathname === `/console/${tenantSlug}` ? "page" : undefined} className="min-w-0 line-clamp-2 break-words rounded-md text-md font-semibold tracking-tight hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring sm:block sm:truncate">
              {tenantName ?? "Tenant home"}
            </Link>
          }
          items={navItems}
          navigationPlacement="besideBrand"
          breadcrumbs={breadcrumbs}
          rightSlot={account}
        />
      }
      footer={<Footer />}
    >
      {children}
    </AppShell>
  );
}
All sources and standards
Current components and theme tokens. Fictional example data. Source views refresh on deployment; authors maintain contract notes.