1
0
Fork 0

feat: add mobile drawer navigation and restyle header

This commit is contained in:
Jonny 2026-07-06 11:54:02 +02:00
parent 11c893e1b9
commit c98e4ef28f
4 changed files with 120 additions and 18 deletions

View File

@ -1,8 +1,11 @@
import Image from "next/image";
import Link from "next/link";
import { Inter } from "next/font/google";
import "./globals.css";
import { loadProfile } from "@/lib/auth/profile";
import { NavLinks } from "@/components/NavLinks";
import { LogoutButton } from "@/components/LogoutButton";
import { MobileNav } from "@/components/MobileNav";
const inter = Inter({ subsets: ["latin"], variable: "--font-inter" });
@ -18,10 +21,14 @@ export default async function RootLayout({
if (result.status === "missing-profile") {
return (
<html lang="de" className={inter.variable}>
<body className="font-sans">
<main>
<h1>Profil nicht gefunden</h1>
<p>Für deinen Account existiert kein Profil. Bitte wende dich an einen Admin.</p>
<body className="flex min-h-screen flex-col font-sans">
<main className="flex flex-1 items-center justify-center p-4">
<div>
<h1 className="text-xl font-semibold text-asphalt-grey">Profil nicht gefunden</h1>
<p className="mt-2 text-asphalt-grey">
Für deinen Account existiert kein Profil. Bitte wende dich an einen Admin.
</p>
</div>
</main>
</body>
</html>
@ -30,17 +37,33 @@ export default async function RootLayout({
return (
<html lang="de" className={inter.variable}>
<body className="font-sans">
<body className="flex min-h-screen flex-col font-sans">
{result.status === "ok" && (
<header>
<NavLinks role={result.profile.role} />
<span>
<header className="flex h-16 items-center justify-between border-b border-aluminium-grey px-4 lg:px-8">
<Link href="/dashboard" className="flex items-center">
<Image src="/brand/widmann-logo.svg" alt="Widmann" width={140} height={21} priority />
</Link>
<div className="hidden items-center gap-6 lg:flex">
<NavLinks role={result.profile.role} orientation="horizontal" />
<span className="text-sm text-asphalt-grey">
{result.profile.name} ({result.profile.role})
</span>
<LogoutButton />
</div>
<MobileNav>
<div className="mb-6 text-sm text-asphalt-grey">
{result.profile.name} ({result.profile.role})
</div>
<NavLinks role={result.profile.role} orientation="vertical" />
<div className="mt-6">
<LogoutButton />
</div>
</MobileNav>
</header>
)}
<main>{children}</main>
<main className="flex-1">{children}</main>
</body>
</html>
);

View File

@ -1,9 +1,12 @@
import { logout } from "@/app/login/actions";
import { Button } from "@/components/ui/Button";
export function LogoutButton() {
return (
<form action={logout}>
<button type="submit">Abmelden</button>
<Button type="submit" variant="secondary" fullWidth={false}>
Abmelden
</Button>
</form>
);
}

View File

@ -0,0 +1,60 @@
"use client";
import { useEffect, useState } from "react";
export function MobileNav({ children }: { children: React.ReactNode }) {
const [open, setOpen] = useState(false);
useEffect(() => {
if (!open) return;
function onKeyDown(event: KeyboardEvent) {
if (event.key === "Escape") setOpen(false);
}
window.addEventListener("keydown", onKeyDown);
return () => window.removeEventListener("keydown", onKeyDown);
}, [open]);
return (
<div className="lg:hidden">
<button
type="button"
aria-label={open ? "Menü schließen" : "Menü öffnen"}
aria-expanded={open}
onClick={() => setOpen((value) => !value)}
className="flex min-h-11 min-w-11 items-center justify-center rounded-md text-asphalt-grey focus-visible:outline focus-visible:outline-2 focus-visible:outline-performance-blue"
>
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth={2}>
{open ? (
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
) : (
<path strokeLinecap="round" strokeLinejoin="round" d="M4 6h16M4 12h16M4 18h16" />
)}
</svg>
</button>
{open && (
<div className="fixed inset-0 z-50">
<button
type="button"
aria-label="Menü schließen"
onClick={() => setOpen(false)}
className="absolute inset-0 bg-black/40"
/>
<div className="absolute right-0 top-0 h-full w-72 max-w-[85vw] bg-white p-4 shadow-lg">
<button
type="button"
aria-label="Menü schließen"
onClick={() => setOpen(false)}
className="mb-4 ml-auto flex min-h-11 min-w-11 items-center justify-center rounded-md text-asphalt-grey focus-visible:outline focus-visible:outline-2 focus-visible:outline-performance-blue"
>
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
{children}
</div>
</div>
)}
</div>
);
}

View File

@ -1,12 +1,28 @@
import Link from "next/link";
import { canManageUsers, type Role } from "@/lib/auth/roles";
export function NavLinks({ role }: { role: Role }) {
export function NavLinks({
role,
orientation = "vertical",
}: {
role: Role;
orientation?: "vertical" | "horizontal";
}) {
const layoutClass = orientation === "horizontal" ? "flex flex-row items-center gap-6" : "flex flex-col gap-4";
return (
<nav>
<Link href="/dashboard">Dashboard</Link>
<Link href="/auftraege">Aufträge</Link>
{canManageUsers(role) && <Link href="/nutzerverwaltung">Nutzerverwaltung</Link>}
<nav className={layoutClass}>
<Link href="/dashboard" className="text-asphalt-grey hover:text-performance-blue">
Dashboard
</Link>
<Link href="/auftraege" className="text-asphalt-grey hover:text-performance-blue">
Aufträge
</Link>
{canManageUsers(role) && (
<Link href="/nutzerverwaltung" className="text-asphalt-grey hover:text-performance-blue">
Nutzerverwaltung
</Link>
)}
</nav>
);
}