import Link from "next/link"; import { redirect } from "next/navigation"; import { loadProfile } from "@/lib/auth/profile"; import { kannStammdatenPflegen } from "@/lib/auth/roles"; import { listOrte } from "@/lib/auftraege/queries"; import { loadOrt } from "@/lib/orte-fahrzeuge/queries"; import { createOrt, updateOrt } from "./actions"; import { Card } from "@/components/ui/Card"; import { Button } from "@/components/ui/Button"; import { Alert } from "@/components/ui/Alert"; import { FormField, FIELD_CLASSES } from "@/components/ui/FormField"; export default async function StammdatenPage({ searchParams, }: { searchParams: Promise<{ error?: string; bearbeite_ort?: string }>; }) { const profileResult = await loadProfile(); if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { redirect(`/auftraege?error=${encodeURIComponent("Nur Disponent/Admin duerfen Stammdaten pflegen.")}`); } const { error, bearbeite_ort } = await searchParams; const [orte, bearbeiteterOrt] = await Promise.all([ listOrte(), bearbeite_ort ? loadOrt(bearbeite_ort) : Promise.resolve(null), ]); const updateOrtAction = bearbeiteterOrt ? updateOrt.bind(null, bearbeiteterOrt.id) : null; return (

Stammdaten

{error && (
{error}
)}

Orte

{bearbeiteterOrt && updateOrtAction ? (

Ort bearbeiten

Abbrechen
) : (

Neuen Ort anlegen

)}
); }