funktechnik-schubert-website/components/admin/AdminShell.tsx
2026-07-03 22:25:04 +02:00

48 lines
1.5 KiB
TypeScript

"use client";
import Image from "next/image";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import type { ReactNode } from "react";
const navItems = [
["Dashboard", "/admin"],
["Kontaktanfragen", "/admin/kontaktanfragen"],
["Reparaturanfragen", "/admin/reparaturanfragen"],
["Website-Inhalte", "/admin/website"],
["Medien", "/admin/medien"],
["Einstellungen", "/admin/einstellungen"],
["SMTP", "/admin/smtp"],
["SEO", "/admin/seo"],
["System", "/admin/system"],
] as const;
export default function AdminShell({ children }: { children: ReactNode }) {
const pathname = usePathname();
const router = useRouter();
async function logout() {
await fetch("/api/admin/logout", { method: "POST" });
router.push("/admin/login");
router.refresh();
}
return (
<div className="admin-shell">
<aside className="admin-sidebar">
<Link className="admin-logo" href="/admin">
<Image src="/funktechnik_schubert_logo.jpg" alt="Funktechnik Schubert" width={1672} height={941} />
</Link>
<nav className="admin-nav" aria-label="Administration">
{navItems.map(([label, href]) => (
<Link key={href} href={href} aria-current={pathname === href ? "page" : undefined}>
{label}
</Link>
))}
</nav>
<button className="admin-logout" type="button" onClick={logout}>Abmelden</button>
</aside>
<div className="admin-main">{children}</div>
</div>
);
}