import type { ReactNode } from "react"; import { Link, Redirect, useLocation } from "wouter"; import { ArrowLeft, Globe, User } from "lucide-react"; import { adminSections, type AdminSection } from "@/lib/adminAccess"; import { t } from "@/lib/i18n"; import { AccountsAdmin } from "./AccountsAdmin"; import { DomainsAdmin } from "./DomainsAdmin"; import { usePermissions } from "./usePermissions"; const SECTIONS: Record ReactNode }> = { accounts: { group: "Directory", label: "Accounts", icon: , render: (id) => }, domains: { group: "Mail", label: "Domains", icon: , render: (id) => }, }; /** * Administration: what the signed-in account's Stalwart role lets it manage. * * Laid out like Settings, because it is the same kind of place -- a list of * sections and the one that is open -- and on a phone it behaves the same way, * the list first and a section on its own. Only the sections the role can read * are listed; a section typed into the address bar that it cannot read opens * the first one it can. */ export function AdminView({ section, id }: { section?: string; id?: string }) { const [, navigate] = useLocation(); const allowed = adminSections(usePermissions()); // Typed in by hand, or a role taken away since the menu was drawn. Stalwart // would refuse every call anyway; this spares the page of refusals. if (!allowed.length) return ; const current = allowed.find((s) => s === section) ?? allowed[0]!; const groups = [...new Set(allowed.map((s) => SECTIONS[s].group))]; return (
{section && ( )} {SECTIONS[current].render(section === current ? id : undefined)}
); }