1
0
Fork 0

feat: add auftraege list page with role-aware sections

This commit is contained in:
Jonny 2026-07-05 21:45:27 +02:00
parent e85e9ce993
commit d292d122c9
3 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import Link from "next/link";
import { loadProfile } from "@/lib/auth/profile";
import { listAuftraegeFuerListe } from "@/lib/auftraege/queries";
import { AuftragListe } from "@/components/AuftragListe";
export default async function AuftraegePage() {
const profileResult = await loadProfile();
if (profileResult.status !== "ok") {
return null;
}
const { meine, offene, alle } = await listAuftraegeFuerListe(profileResult.profile);
const istFahrer = profileResult.profile.role === "fahrer";
const kannAnlegen = profileResult.profile.role === "admin" || profileResult.profile.role === "disponent";
return (
<main>
<h1>Aufträge</h1>
{kannAnlegen && <Link href="/auftraege/neu">Neuen Auftrag anlegen</Link>}
{istFahrer ? (
<>
<AuftragListe titel="Meine Aufträge" auftraege={meine} />
<AuftragListe titel="Offene Aufträge" auftraege={offene} />
</>
) : (
<AuftragListe titel="Alle Aufträge" auftraege={alle} />
)}
</main>
);
}

View File

@ -0,0 +1,29 @@
import Link from "next/link";
import type { Auftrag } from "@/lib/auftraege/queries";
export function AuftragListe({ titel, auftraege }: { titel: string; auftraege: Auftrag[] }) {
if (auftraege.length === 0) {
return (
<section>
<h2>{titel}</h2>
<p>Keine Aufträge.</p>
</section>
);
}
return (
<section>
<h2>{titel}</h2>
<ul>
{auftraege.map((auftrag) => (
<li key={auftrag.id}>
<Link href={`/auftraege/${auftrag.id}`}>
{auftrag.abholort.adresse} → {auftrag.zielort.adresse} ({auftrag.fahrzeug.kennzeichen}) —{" "}
{auftrag.status}
</Link>
</li>
))}
</ul>
</section>
);
}

View File

@ -5,6 +5,7 @@ export function NavLinks({ role }: { role: Role }) {
return ( return (
<nav> <nav>
<Link href="/dashboard">Dashboard</Link> <Link href="/dashboard">Dashboard</Link>
<Link href="/auftraege">Aufträge</Link>
{canManageUsers(role) && <Link href="/nutzerverwaltung">Nutzerverwaltung</Link>} {canManageUsers(role) && <Link href="/nutzerverwaltung">Nutzerverwaltung</Link>}
</nav> </nav>
); );