forked from fahrPool/fahrPool
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import Link from "next/link";
|
|
import { loadProfile } from "@/lib/auth/profile";
|
|
import { listAuftraegeFuerListe } from "@/lib/auftraege/queries";
|
|
import { AuftragListe } from "@/components/AuftragListe";
|
|
import { Alert } from "@/components/ui/Alert";
|
|
import { buttonClasses } from "@/components/ui/Button";
|
|
|
|
export default async function AuftraegePage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ error?: string }>;
|
|
}) {
|
|
const { error } = await searchParams;
|
|
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 className="mx-auto max-w-5xl p-4 md:p-8">
|
|
<div className="mb-6 flex items-center justify-between">
|
|
<h1 className="text-xl font-semibold text-asphalt-grey">Aufträge</h1>
|
|
{kannAnlegen && (
|
|
<Link href="/auftraege/neu" className={buttonClasses("primary", false)}>
|
|
Neuen Auftrag anlegen
|
|
</Link>
|
|
)}
|
|
</div>
|
|
{error && (
|
|
<div className="mb-6">
|
|
<Alert>{error}</Alert>
|
|
</div>
|
|
)}
|
|
{istFahrer ? (
|
|
<>
|
|
<AuftragListe titel="Meine Aufträge" auftraege={meine} />
|
|
<AuftragListe titel="Offene Aufträge" auftraege={offene} />
|
|
</>
|
|
) : (
|
|
<AuftragListe titel="Alle Aufträge" auftraege={alle} />
|
|
)}
|
|
</main>
|
|
);
|
|
}
|