forked from fahrPool/fahrPool
feat: add auftraege list page with role-aware sections
This commit is contained in:
parent
e85e9ce993
commit
d292d122c9
|
|
@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -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>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue