Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvuGvHpbAQ4syfuLuRvutL
79 lines
3.4 KiB
TypeScript
79 lines
3.4 KiB
TypeScript
import Link from "next/link";
|
|
import { cookies } from "next/headers";
|
|
import "@/styles/admin.css";
|
|
import { can, requireAdmin } from "@/lib/auth";
|
|
import { logout } from "@/lib/auth-actions";
|
|
import { getSettings } from "@/lib/settings";
|
|
import { Icon } from "@/components/Icon";
|
|
import { ThemeToggle } from "@/components/ThemeToggle";
|
|
import { AdminNav } from "@/components/admin/AdminNav";
|
|
import { MobileAdminNav } from "@/components/admin/MobileAdminNav";
|
|
import { ADMIN_NAV } from "@/components/admin/nav";
|
|
import { AdminBadgesProvider } from "@/components/admin/AdminBadges";
|
|
import { SEEN_SECTIONS, getBadges, readSeen } from "@/lib/admin-badges";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
export const metadata = { title: "Admin", robots: { index: false } };
|
|
|
|
export default async function AdminLayout({ children }: { children: React.ReactNode }) {
|
|
const user = await requireAdmin();
|
|
const settings = await getSettings();
|
|
const groups = ADMIN_NAV.map((g) => ({ ...g, items: g.items.filter((i) => can(user, i.permission)) })).filter((g) => g.items.length);
|
|
const badges = await getBadges(user, readSeen(await cookies()));
|
|
const nav = <AdminNav groups={groups} />;
|
|
const foot = (
|
|
<div className="ad-side__foot">
|
|
<p>{[user.firstName, user.lastName].filter(Boolean).join(" ") || user.email}</p>
|
|
<p className="ad-muted">{user.role?.name}</p>
|
|
<div style={{ display: "flex", gap: "var(--space-3)", marginTop: "var(--space-3)", flexWrap: "wrap", alignItems: "center" }}>
|
|
<ThemeToggle className="ad-theme-btn" />
|
|
<Link href="/" target="_blank" className="body-sm" style={{ display: "inline-flex", gap: 4, alignItems: "center" }}>
|
|
<Icon name="external" size="sm" /> Shop ansehen
|
|
</Link>
|
|
<form action={logout}>
|
|
<button type="submit" className="body-sm" style={{ background: "none", border: 0, padding: 0, color: "var(--link)", cursor: "pointer", display: "inline-flex", gap: 4, alignItems: "center" }}>
|
|
<Icon name="logout" size="sm" /> Abmelden
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
const brand = (
|
|
<Link href="/admin" className="ad-side__brand">
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
<img className="sm-logo--ink" src="/brand/bildmarke-ink.png" alt="" />
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
<img className="sm-logo--gold" src="/brand/bildmarke-gold.png" alt="" />
|
|
<span>
|
|
<strong>{settings.general.shopName}.</strong>
|
|
<small>Verwaltung</small>
|
|
</span>
|
|
</Link>
|
|
);
|
|
return (
|
|
<AdminBadgesProvider initial={badges} seenSections={SEEN_SECTIONS}>
|
|
<div className="ad">
|
|
<aside className="ad-side">
|
|
{brand}
|
|
{nav}
|
|
{foot}
|
|
</aside>
|
|
<div style={{ minWidth: 0 }}>
|
|
<div className="ad-top">
|
|
<MobileAdminNav>
|
|
{brand}
|
|
{nav}
|
|
{foot}
|
|
</MobileAdminNav>
|
|
<strong style={{ letterSpacing: "0.24em", fontWeight: 400, textTransform: "uppercase" }}>{settings.general.shopName}.</strong>
|
|
<span style={{ display: "inline-flex" }}>
|
|
<ThemeToggle />
|
|
<Link className="sm-header__btn" href="/" aria-label="Shop ansehen"><Icon name="external" /></Link>
|
|
</span>
|
|
</div>
|
|
<main className="ad-main">{children}</main>
|
|
</div>
|
|
</div>
|
|
</AdminBadgesProvider>
|
|
);
|
|
}
|