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

View File

@ -1,9 +1,12 @@
import { logout } from "@/app/login/actions"; import { logout } from "@/app/login/actions";
import { Button } from "@/components/ui/Button";
export function LogoutButton() { export function LogoutButton() {
return ( return (
<form action={logout}> <form action={logout}>
<button type="submit">Abmelden</button> <Button type="submit" variant="secondary" fullWidth={false}>
Abmelden
</Button>
</form> </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 Link from "next/link";
import { canManageUsers, type Role } from "@/lib/auth/roles"; 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 ( return (
<nav> <nav className={layoutClass}>
<Link href="/dashboard">Dashboard</Link> <Link href="/dashboard" className="text-asphalt-grey hover:text-performance-blue">
<Link href="/auftraege">Aufträge</Link> Dashboard
{canManageUsers(role) && <Link href="/nutzerverwaltung">Nutzerverwaltung</Link>} </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> </nav>
); );
} }