203 lines
7.8 KiB
TypeScript
203 lines
7.8 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
|
ADMIN HOME
|
|
|
|
Where login lands. Two columns: the cards are the navigation
|
|
(the header deliberately drops its tab row here so the same links
|
|
aren't drawn twice), and a standing info panel on the right.
|
|
|
|
The cards come from adminNav.ts, the same list the CMS header
|
|
reads, so a new entity shows up here the moment it's registered.
|
|
One block per header group, in the same order: Data, Pages,
|
|
Forms, Tools, and Panel, which only exists for superadmins.
|
|
|
|
It asks for the wide admin column (adminWidth.tsx), like the
|
|
editor, so the cards run three across on a wide screen. The
|
|
blocks alternate between two palette colors (BLOCK_COLORS),
|
|
tinting their cards and drawing their bars, so neighboring groups
|
|
read apart at a glance.
|
|
|
|
The right-hand panel is deliberately inert. Nothing here
|
|
fetches, so the landing page can't be slow or half-broken on
|
|
arrival; anything live (open feedback count, last-edited
|
|
record) wants to be a separate component that fails on its own.
|
|
═══════════════════════════════════════════════════════════════ */
|
|
|
|
import { ArrowRight, ArrowUpRight } from "@phosphor-icons/react";
|
|
import { Link } from "react-router-dom";
|
|
import { useAuth } from "../../lib/auth.tsx";
|
|
import { useWideAdminPage } from "../../lib/adminWidth.tsx";
|
|
import { SITE_VERSION } from "../../lib/version.ts";
|
|
import { ROLE_LABELS, isSuper } from "../../lib/roles.ts";
|
|
import { PALETTE } from "../../lib/color.ts";
|
|
import { DATA_NAV, FORMS_NAV, PAGES_NAV, PANEL_NAV, TOOLS_NAV, target, visibleItems } from "./adminNav.ts";
|
|
|
|
/* One card. The title link is stretched over the whole card with
|
|
`after:absolute`, which makes the card clickable without nesting
|
|
an anchor inside an anchor; the sub-links sit above it on z-10 so
|
|
they stay separately clickable. */
|
|
/* A card's fill: its group's color, faint, over the surface. */
|
|
const tintOf = (color: string) => `color-mix(in srgb, ${color} 12%, var(--color-surface))`;
|
|
|
|
function NavCard({ item, color }) {
|
|
const to = target(item);
|
|
|
|
// Drop the child that just repeats the card's own destination:
|
|
// "All organizations" under Organizations.
|
|
const extras = (item.children ?? []).filter((child) => child.to !== to);
|
|
|
|
return (
|
|
<div
|
|
className="group relative flex flex-col border-l-4 p-5 shadow-sm transition-shadow hover:shadow-md"
|
|
style={{ borderColor: color, background: tintOf(color) }}
|
|
>
|
|
<div className="flex items-baseline gap-3">
|
|
<h3 className="text-base font-bold text-link">
|
|
<Link
|
|
to={to}
|
|
className="after:absolute after:inset-0 after:content-['']"
|
|
>
|
|
{item.label}
|
|
</Link>
|
|
</h3>
|
|
<span
|
|
aria-hidden="true"
|
|
className="ml-auto text-link opacity-0 transition-opacity group-hover:opacity-100"
|
|
>
|
|
<ArrowRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" />
|
|
</span>
|
|
</div>
|
|
|
|
{item.blurb && (
|
|
<p className="mt-1.5 text-sm leading-relaxed text-muted">{item.blurb}</p>
|
|
)}
|
|
|
|
{extras.length > 0 && (
|
|
<div className="relative z-10 mt-4 flex flex-wrap gap-x-4 gap-y-1 border-t border-brand/10 pt-3 text-sm">
|
|
{extras.map((child) => (
|
|
<Link
|
|
key={child.to}
|
|
to={child.to}
|
|
className="text-muted underline-offset-4 transition-colors hover:text-link hover:underline"
|
|
>
|
|
{child.label}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CardBlock({ title, blurb, color, children }) {
|
|
return (
|
|
<div className="mt-10">
|
|
<div className="flex items-baseline gap-3 border-b-4 pb-2" style={{ borderColor: color }}>
|
|
<h2 className="text-lg font-bold text-link">{title}</h2>
|
|
{blurb && <p className="text-sm text-muted">{blurb}</p>}
|
|
</div>
|
|
<div className="mt-4 grid gap-4 sm:grid-cols-2 xl:grid-cols-3">{children}</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PanelSection({ title, children }) {
|
|
return (
|
|
<section className="border-b border-brand/10 px-5 py-4 last:border-b-0">
|
|
<h2 className="text-xs font-bold uppercase tracking-wider text-muted/70">
|
|
{title}
|
|
</h2>
|
|
<div className="mt-2.5 text-sm text-muted">{children}</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
/* The header's groups, in its order, each with its palette color.
|
|
Panel is drawn separately below, since only superadmins get it. */
|
|
const BLOCK_COLORS = [PALETTE.teal[0], PALETTE.green[0]];
|
|
const GROUPS = [DATA_NAV, PAGES_NAV, FORMS_NAV, TOOLS_NAV].map((nav, index) => ({
|
|
nav,
|
|
color: BLOCK_COLORS[index % BLOCK_COLORS.length],
|
|
}));
|
|
const PANEL_COLOR = BLOCK_COLORS[GROUPS.length % BLOCK_COLORS.length];
|
|
|
|
const QUICK_ADD = [
|
|
{ to: "/admin/events/new", label: "New event" },
|
|
{ to: "/admin/people/new", label: "New person" },
|
|
{ to: "/admin/organizations/new", label: "New organization" },
|
|
{ to: "/admin/timeline/new", label: "New timeline entry" },
|
|
];
|
|
|
|
export default function AdminHome() {
|
|
const { user } = useAuth();
|
|
const role = ROLE_LABELS[user?.role] ?? user?.role;
|
|
useWideAdminPage();
|
|
|
|
return (
|
|
<div className="grid gap-8 lg:grid-cols-[1fr_17rem] lg:items-start">
|
|
<div>
|
|
<h1 className="text-2xl font-bold text-link">
|
|
{user?.name ? `Welcome back, ${user.name.split(" ")[0]}.` : "Welcome back."}
|
|
</h1>
|
|
<p className="mt-1 text-muted">Pick a section to work in.</p>
|
|
|
|
{GROUPS.map(({ nav, color }) => (
|
|
<CardBlock key={nav.label} title={nav.label} blurb={nav.blurb} color={color}>
|
|
{visibleItems(nav.children, user).map((item) => (
|
|
<NavCard key={item.to} item={item} color={color} />
|
|
))}
|
|
</CardBlock>
|
|
))}
|
|
|
|
{isSuper(user) && (
|
|
<CardBlock title={PANEL_NAV.label} blurb={PANEL_NAV.blurb} color={PANEL_COLOR}>
|
|
{PANEL_NAV.children.map((item) => (
|
|
<NavCard key={item.to} item={item} color={PANEL_COLOR} />
|
|
))}
|
|
</CardBlock>
|
|
)}
|
|
</div>
|
|
|
|
{/* Sticky so it stays put once the card column outgrows it. */}
|
|
<aside className="divide-y divide-brand/10 border border-brand/20 bg-surface lg:sticky lg:top-6">
|
|
<PanelSection title="Signed in">
|
|
<p className="font-medium text-ink">{user?.name || user?.email}</p>
|
|
{user?.name && user?.email && (
|
|
<p className="mt-0.5 break-all text-xs text-muted/80">{user.email}</p>
|
|
)}
|
|
{role && (
|
|
<span className="mt-2 inline-block bg-tint px-2.5 py-0.5 text-xs font-medium text-link">
|
|
{role}
|
|
</span>
|
|
)}
|
|
</PanelSection>
|
|
|
|
<PanelSection title="Start something">
|
|
<ul className="space-y-1.5">
|
|
{QUICK_ADD.map((link) => (
|
|
<li key={link.to}>
|
|
<Link
|
|
to={link.to}
|
|
className="underline-offset-4 transition-colors hover:text-link hover:underline"
|
|
>
|
|
{link.label}
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</PanelSection>
|
|
|
|
<PanelSection title="Site">
|
|
<p className="font-mono text-xs text-muted/80">{SITE_VERSION}</p>
|
|
<a
|
|
href="/"
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="mt-2 inline-block underline-offset-4 transition-colors hover:text-link hover:underline"
|
|
>
|
|
View the public site <ArrowUpRight size="1em" weight="bold" className="inline align-[-0.125em]" aria-hidden="true" />
|
|
</a>
|
|
</PanelSection>
|
|
</aside>
|
|
</div>
|
|
);
|
|
}
|