1
0
Fork 0

feat: Untere Navigationsleiste am Handy, gruppierte Navigation mit aktivem Link, Rollenbezeichnung und Startseite je Rolle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonny 2026-11-02 17:19:27 +01:00
parent a322320c99
commit e490bc6142
7 changed files with 152 additions and 117 deletions

View File

@ -1,4 +1,7 @@
import Link from "next/link"; import Link from "next/link";
import { navigationFuer } from "@/lib/navigation";
import { rollenBezeichnung } from "@/lib/auth/roles";
import { UntereLeiste } from "@/components/navigation/UntereLeiste";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { Inter } from "next/font/google"; import { Inter } from "next/font/google";
import "./globals.css"; import "./globals.css";
@ -56,6 +59,8 @@ export default async function RootLayout({
); );
} }
const untereLeiste = result.status === "ok" ? navigationFuer(result.profile.role).unten : [];
return ( return (
<html lang="de" className={inter.variable} style={themeStyle}> <html lang="de" className={inter.variable} style={themeStyle}>
<body className="flex min-h-screen flex-col font-sans"> <body className="flex min-h-screen flex-col font-sans">
@ -64,21 +69,21 @@ export default async function RootLayout({
<OfflineBalken /> <OfflineBalken />
{result.status === "ok" && ( {result.status === "ok" && (
<header className="flex h-16 items-center justify-between border-b border-aluminium-grey px-4 lg:px-8"> <header className="flex h-16 items-center justify-between border-b border-aluminium-grey px-4 lg:px-8">
<Link href={result.profile.role === "superadmin" ? "/plattform" : "/dashboard"} className="flex items-center"> <Link href={navigationFuer(result.profile.role).start} className="flex items-center">
<FirmenLogo firma={firma} /> <FirmenLogo firma={firma} />
</Link> </Link>
<div className="hidden items-center gap-6 lg:flex"> <div className="hidden items-center gap-6 lg:flex">
<NavLinks role={result.profile.role} orientation="horizontal" /> <NavLinks role={result.profile.role} orientation="horizontal" />
<span className="text-sm text-asphalt-grey"> <span className="text-sm text-asphalt-grey">
{result.profile.name} ({result.profile.role}) {result.profile.name} · {rollenBezeichnung(result.profile.role)}
</span> </span>
<LogoutButton /> <LogoutButton />
</div> </div>
<MobileNav> <MobileNav>
<div className="mb-6 text-sm text-asphalt-grey"> <div className="mb-6 text-sm text-asphalt-grey">
{result.profile.name} ({result.profile.role}) {result.profile.name} · {rollenBezeichnung(result.profile.role)}
</div> </div>
<NavLinks role={result.profile.role} orientation="vertical" /> <NavLinks role={result.profile.role} orientation="vertical" />
<div className="mt-6"> <div className="mt-6">
@ -87,7 +92,8 @@ export default async function RootLayout({
</MobileNav> </MobileNav>
</header> </header>
)} )}
<main className="flex-1">{children}</main> <main className={`flex-1 ${untereLeiste.length > 0 ? "pb-20 lg:pb-0" : ""}`}>{children}</main>
{untereLeiste.length > 0 && <UntereLeiste ziele={untereLeiste} />}
</body> </body>
</html> </html>
); );

View File

@ -1,8 +1,8 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { loadProfile } from "@/lib/auth/profile"; import { loadProfile } from "@/lib/auth/profile";
import { navigationFuer } from "@/lib/navigation";
export default async function Home() { export default async function Home() {
const result = await loadProfile(); const result = await loadProfile();
if (result.status === "ok" && result.profile.role === "superadmin") redirect("/plattform"); redirect(result.status === "ok" ? navigationFuer(result.profile.role).start : "/dashboard");
redirect("/dashboard");
} }

View File

@ -1,9 +1,27 @@
"use client"; "use client";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { usePathname } from "next/navigation";
import { MENUE_OEFFNEN } from "@/components/navigation/UntereLeiste";
export function MobileNav({ children }: { children: React.ReactNode }) { export function MobileNav({ children }: { children: React.ReactNode }) {
const [open, setOpen] = useState(false); const pfad = usePathname();
// Das Menue merkt sich die Seite, auf der es geoeffnet wurde: nach einem
// Seitenwechsel ueber einen Menue-Link gilt es damit automatisch als geschlossen.
const [offenAuf, setOffenAuf] = useState<string | null>(null);
const open = offenAuf !== null && offenAuf === pfad;
const setOpen = (wert: boolean | ((alt: boolean) => boolean)) =>
setOffenAuf((alt) => {
const war = alt !== null && alt === pfad;
return (typeof wert === "function" ? wert(war) : wert) ? pfad : null;
});
// "Mehr" in der unteren Leiste oeffnet dieses Menue.
useEffect(() => {
const oeffnen = () => setOffenAuf(pfad);
window.addEventListener(MENUE_OEFFNEN, oeffnen);
return () => window.removeEventListener(MENUE_OEFFNEN, oeffnen);
}, [pfad]);
useEffect(() => { useEffect(() => {
if (!open) return; if (!open) return;
@ -40,7 +58,7 @@ export function MobileNav({ children }: { children: React.ReactNode }) {
onClick={() => setOpen(false)} onClick={() => setOpen(false)}
className="absolute inset-0 bg-black/40" 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"> <div className="absolute right-0 top-0 h-full w-72 max-w-[85vw] overflow-y-auto bg-white p-4 shadow-lg">
<button <button
type="button" type="button"
aria-label="Menü schließen" aria-label="Menü schließen"

View File

@ -1,5 +1,18 @@
import Link from "next/link"; import type { Role } from "@/lib/auth/roles";
import { canManageUsers, istSuperadmin, kannAuditLogSehen, kannFirmaVerwalten, kannAuslastungSehen, kannFahrerdetailsSehen, kannKalenderSehen, kannReportsSehen, kannStammdatenPflegen, kannZeiterfassungNutzen, type Role } from "@/lib/auth/roles"; import { navigationFuer, PROFIL_ZIEL, type NavZiel } from "@/lib/navigation";
import { AktiverLink } from "@/components/navigation/AktiverLink";
const LINK =
"flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue";
const AKTIV = "font-semibold text-performance-blue";
function Links({ ziele }: { ziele: NavZiel[] }) {
return ziele.map((ziel) => (
<AktiverLink key={ziel.href} href={ziel.href} className={LINK} aktivClassName={AKTIV}>
{ziel.label}
</AktiverLink>
));
}
export function NavLinks({ export function NavLinks({
role, role,
@ -8,121 +21,42 @@ export function NavLinks({
role: Role; role: Role;
orientation?: "vertical" | "horizontal"; orientation?: "vertical" | "horizontal";
}) { }) {
const layoutClass = orientation === "horizontal" ? "flex flex-row items-center gap-6" : "flex flex-col gap-4"; const { haupt, verwaltung } = navigationFuer(role);
const linkClass = if (orientation === "horizontal") {
"flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue";
if (istSuperadmin(role)) {
return ( return (
<nav className={layoutClass}> <nav aria-label="Hauptnavigation" className="flex flex-row items-center gap-6">
<Link href="/plattform" className={linkClass}> <Links ziele={haupt} />
Plattform {verwaltung.length > 0 && (
</Link> <details className="relative">
<Link href="/audit-log" className={linkClass}> <summary className={`${LINK} cursor-pointer list-none`}>Verwaltung ▾</summary>
Audit-Log <div className="absolute right-0 z-50 mt-2 flex w-56 flex-col gap-1 rounded-md border border-aluminium-grey bg-white p-3 shadow-lg">
</Link> <Links ziele={verwaltung} />
<Link href="/profil" className={linkClass}> </div>
Mein Profil </details>
</Link> )}
<Links ziele={[PROFIL_ZIEL]} />
</nav> </nav>
); );
} }
return ( return (
<nav className={layoutClass}> <nav aria-label="Hauptnavigation" className="flex flex-col gap-6">
<Link <section>
href="/dashboard" <h2 className="mb-1 text-xs font-semibold uppercase tracking-wide text-status-neutral">Navigation</h2>
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue" <div className="flex flex-col gap-1">
> <Links ziele={haupt} />
Dashboard </div>
</Link> </section>
<Link {verwaltung.length > 0 && (
href="/auftraege" <section>
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue" <h2 className="mb-1 text-xs font-semibold uppercase tracking-wide text-status-neutral">Verwaltung</h2>
> <div className="flex flex-col gap-1">
Aufträge <Links ziele={verwaltung} />
</Link> </div>
{kannAuslastungSehen(role) && ( </section>
<Link
href="/auslastung"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Auslastung
</Link>
)} )}
{kannKalenderSehen(role) && ( <Links ziele={[PROFIL_ZIEL]} />
<Link
href="/kalender"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Kalender
</Link>
)}
{kannReportsSehen(role) && (
<Link
href="/reports"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Reports
</Link>
)}
{kannFahrerdetailsSehen(role) && (
<Link
href="/fahrer"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Fahrer
</Link>
)}
{kannZeiterfassungNutzen(role) && (
<Link
href="/zeiterfassung"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Zeiterfassung
</Link>
)}
{kannStammdatenPflegen(role) && (
<Link
href="/standorte"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Standorte
</Link>
)}
{kannStammdatenPflegen(role) && (
<Link
href="/fahrzeuge"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Fahrzeuge
</Link>
)}
{canManageUsers(role) && (
<Link
href="/nutzerverwaltung"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Nutzerverwaltung
</Link>
)}
{kannFirmaVerwalten(role) && (
<Link href="/firma" className={linkClass}>
Firma
</Link>
)}
{kannAuditLogSehen(role) && (
<Link href="/audit-log" className={linkClass}>
Audit-Log
</Link>
)}
<Link
href="/profil"
className="flex min-h-11 items-center text-asphalt-grey hover:text-performance-blue focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
>
Mein Profil
</Link>
</nav> </nav>
); );
} }

View File

@ -0,0 +1,24 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { istAktiv } from "@/lib/navigation";
export function AktiverLink({
href,
className,
aktivClassName,
children,
}: {
href: string;
className: string;
aktivClassName: string;
children: React.ReactNode;
}) {
const aktiv = istAktiv(usePathname() ?? "", href);
return (
<Link href={href} aria-current={aktiv ? "page" : undefined} className={`${className} ${aktiv ? aktivClassName : ""}`}>
{children}
</Link>
);
}

View File

@ -0,0 +1,22 @@
import type { NavIcon as NavIconName } from "@/lib/navigation";
// Schlichte Strich-Icons (24er Raster), Farbe ueber currentColor.
const PFADE: Record<NavIconName, string> = {
board: "M4 5h4v14H4zM10 5h4v9h-4zM16 5h4v6h-4z",
auftraege: "M8 4h8l1 2h3v14H4V6h3zM8 11h8M8 15h5",
kalender: "M4 6h16v14H4zM4 10h16M8 3v4M16 3v4",
zeit: "M12 4a8 8 0 100 16 8 8 0 000-16zM12 8v4l3 2",
profil: "M12 12a4 4 0 100-8 4 4 0 000 8zM4 20a8 8 0 0116 0",
auslastung: "M4 19h16M6 16l4-5 3 3 5-7",
reports: "M5 19V9M10 19V5M15 19v-7M20 19v-4",
plattform: "M4 7l8-4 8 4-8 4zM4 12l8 4 8-4M4 17l8 4 8-4",
verwaltung: "M4 7h16M4 12h16M4 17h16",
};
export function NavIcon({ name, className = "h-6 w-6" }: { name: NavIconName; className?: string }) {
return (
<svg viewBox="0 0 24 24" className={className} fill="none" stroke="currentColor" strokeWidth={1.8} aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" d={PFADE[name]} />
</svg>
);
}

View File

@ -0,0 +1,31 @@
"use client";
import type { NavZiel } from "@/lib/navigation";
import { AktiverLink } from "./AktiverLink";
import { NavIcon } from "./NavIcon";
export const MENUE_OEFFNEN = "menue-oeffnen";
const ZIEL =
"flex min-h-14 flex-1 flex-col items-center justify-center gap-0.5 text-xs text-asphalt-grey focus-visible:outline focus-visible:outline-2 focus-visible:outline-performance-blue";
// Feste Leiste fuer die haeufigsten Ziele am Handy; "Mehr" oeffnet das bestehende Menue.
export function UntereLeiste({ ziele }: { ziele: NavZiel[] }) {
return (
<nav
aria-label="Schnellzugriff"
className="fixed inset-x-0 bottom-0 z-40 flex border-t border-aluminium-grey bg-white pb-[env(safe-area-inset-bottom)] lg:hidden"
>
{ziele.map((ziel) => (
<AktiverLink key={ziel.href} href={ziel.href} className={ZIEL} aktivClassName="font-semibold text-performance-blue">
<NavIcon name={ziel.icon} />
{ziel.kurz}
</AktiverLink>
))}
<button type="button" className={ZIEL} onClick={() => window.dispatchEvent(new Event(MENUE_OEFFNEN))}>
<NavIcon name="verwaltung" />
Mehr
</button>
</nav>
);
}