63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { Link } from "react-router";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import type { SettingsHubVM } from "@hivegrid/view-models";
|
|
|
|
import { PAGE_HEADER_ICON_CLASS, PageHeader, PageShell } from "../shared/PageShell";
|
|
import { Tabs } from "~/ui/components/Tabs";
|
|
|
|
/**
|
|
* AK-SET-01 · shared chrome for every settings hub.
|
|
*
|
|
* Renders the hub header plus a permanently visible tab bar and yields the
|
|
* active tab's route below it. The tab markup follows the settings tab bar
|
|
* already shipped in MembersPage: a <Link> wrapping a <Tabs.Item>, so each tab
|
|
* stays a real navigation target rather than an onClick handler.
|
|
*
|
|
* The inner settings rail (SidebarIconsLayout) is deliberately untouched by
|
|
* this component — it only ever receives a shorter item list.
|
|
*/
|
|
export function SettingsHubShell({
|
|
vm,
|
|
icon,
|
|
children,
|
|
}: {
|
|
vm: SettingsHubVM;
|
|
icon?: ReactNode;
|
|
children: ReactNode;
|
|
}): React.JSX.Element {
|
|
const { t } = useTranslation();
|
|
|
|
// `empty` means the loader handed over a hub without a single reachable tab.
|
|
// It should have thrown a 404 instead, so render the content bare rather than
|
|
// an empty chrome that suggests the user is somewhere they may not be.
|
|
if (vm.status !== "ready") {
|
|
return <PageShell uiId="ui.settings.hub">{children}</PageShell>;
|
|
}
|
|
|
|
const { hubId, titleKey, subtitleKey, tabs } = vm.data;
|
|
|
|
return (
|
|
<PageShell uiId={`ui.settings.hub.${hubId}`} className="bg-surface-neutral-primary">
|
|
<PageHeader
|
|
icon={icon ? <span className={PAGE_HEADER_ICON_CLASS}>{icon}</span> : undefined}
|
|
title={t(titleKey)}
|
|
subtitle={subtitleKey ? t(subtitleKey) : undefined}
|
|
/>
|
|
<div className="flex w-full flex-col px-6 pt-4 mobile:px-4">
|
|
<Tabs>
|
|
{tabs.map((tab) => (
|
|
<Link key={tab.id} to={tab.href} className="contents no-underline" data-ui-id={`ui.settings.hub.${hubId}.tab.${tab.id}`}>
|
|
<Tabs.Item active={tab.active}>{t(tab.labelKey)}</Tabs.Item>
|
|
</Link>
|
|
))}
|
|
</Tabs>
|
|
</div>
|
|
{/* PageShell is items-start, so the tab content would size to its own
|
|
content and leave dead space on the right — this keeps it stretched. */}
|
|
<div className="w-full">{children}</div>
|
|
</PageShell>
|
|
);
|
|
}
|