From 16b030048852b0d783da904b15b2de3c837f3ae7 Mon Sep 17 00:00:00 2001 From: Jonny Date: Mon, 17 Aug 2026 15:12:00 +0200 Subject: [PATCH] feat: add Fahrzeuge page with inline-editable table Co-Authored-By: Claude Sonnet 5 --- web/app/fahrzeuge/page.tsx | 21 ++++ web/components/fahrzeuge/FahrzeugZeile.tsx | 118 ++++++++++++++++++ web/components/fahrzeuge/FahrzeugeTabelle.tsx | 27 ++++ web/components/fahrzeuge/NeuerFahrzeug.tsx | 81 ++++++++++++ 4 files changed, 247 insertions(+) create mode 100644 web/app/fahrzeuge/page.tsx create mode 100644 web/components/fahrzeuge/FahrzeugZeile.tsx create mode 100644 web/components/fahrzeuge/FahrzeugeTabelle.tsx create mode 100644 web/components/fahrzeuge/NeuerFahrzeug.tsx diff --git a/web/app/fahrzeuge/page.tsx b/web/app/fahrzeuge/page.tsx new file mode 100644 index 0000000..5e4ef32 --- /dev/null +++ b/web/app/fahrzeuge/page.tsx @@ -0,0 +1,21 @@ +import { redirect } from "next/navigation"; +import { loadProfile } from "@/lib/auth/profile"; +import { kannStammdatenPflegen } from "@/lib/auth/roles"; +import { listFahrzeuge } from "@/lib/auftraege/queries"; +import { FahrzeugeTabelle } from "@/components/fahrzeuge/FahrzeugeTabelle"; + +export default async function FahrzeugePage() { + const profileResult = await loadProfile(); + if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { + redirect(`/auftraege?error=${encodeURIComponent("Nur Disponent/Admin duerfen Stammdaten pflegen.")}`); + } + + const fahrzeuge = await listFahrzeuge(); + + return ( +
+

Fahrzeuge

+ +
+ ); +} diff --git a/web/components/fahrzeuge/FahrzeugZeile.tsx b/web/components/fahrzeuge/FahrzeugZeile.tsx new file mode 100644 index 0000000..599575f --- /dev/null +++ b/web/components/fahrzeuge/FahrzeugZeile.tsx @@ -0,0 +1,118 @@ +"use client"; + +import { useState, useTransition } from "react"; +import { useRouter } from "next/navigation"; +import type { Fahrzeug } from "@/lib/auftraege/queries"; +import { updateFahrzeug } from "@/app/fahrzeuge/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 function FahrzeugZeile({ fahrzeug }: { fahrzeug: Fahrzeug }) { + const router = useRouter(); + const [bearbeiten, setBearbeiten] = useState(false); + const [fehler, setFehler] = useState(null); + const [isPending, startTransition] = useTransition(); + + function handleSubmit(formData: FormData) { + startTransition(async () => { + const ergebnis = await updateFahrzeug(fahrzeug.id, formData); + if (!ergebnis.success) { + setFehler(ergebnis.error); + return; + } + setFehler(null); + setBearbeiten(false); + router.refresh(); + }); + } + + if (!bearbeiten) { + return ( + +
+ Kennzeichen +

{fahrzeug.kennzeichen}

+
+
+ Marke +

{fahrzeug.marke ?? "—"}

+
+
+ Modell +

{fahrzeug.modell ?? "—"}

+
+
+ +
+
+ ); + } + + return ( + +
+ {fehler && ( +
+ {fehler} +
+ )} + + + + + + + + + + + +
+
+ ); +} diff --git a/web/components/fahrzeuge/FahrzeugeTabelle.tsx b/web/components/fahrzeuge/FahrzeugeTabelle.tsx new file mode 100644 index 0000000..f898019 --- /dev/null +++ b/web/components/fahrzeuge/FahrzeugeTabelle.tsx @@ -0,0 +1,27 @@ +import type { Fahrzeug } from "@/lib/auftraege/queries"; +import { FahrzeugZeile } from "./FahrzeugZeile"; +import { NeuerFahrzeug } from "./NeuerFahrzeug"; + +export function FahrzeugeTabelle({ fahrzeuge }: { fahrzeuge: Fahrzeug[] }) { + return ( +
+
+
Kennzeichen
+
Marke
+
Modell
+
+ Aktionen +
+
+
+ {fahrzeuge.map((fahrzeug) => ( + + ))} + +
+
+ ); +} diff --git a/web/components/fahrzeuge/NeuerFahrzeug.tsx b/web/components/fahrzeuge/NeuerFahrzeug.tsx new file mode 100644 index 0000000..229b9d1 --- /dev/null +++ b/web/components/fahrzeuge/NeuerFahrzeug.tsx @@ -0,0 +1,81 @@ +"use client"; + +import { useState, useTransition } from "react"; +import { useRouter } from "next/navigation"; +import { createFahrzeug } from "@/app/fahrzeuge/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 function NeuerFahrzeug() { + const router = useRouter(); + const [offen, setOffen] = useState(false); + const [fehler, setFehler] = useState(null); + const [isPending, startTransition] = useTransition(); + + function handleSubmit(formData: FormData) { + startTransition(async () => { + const ergebnis = await createFahrzeug(formData); + if (!ergebnis.success) { + setFehler(ergebnis.error); + return; + } + setFehler(null); + setOffen(false); + router.refresh(); + }); + } + + if (!offen) { + return ( +
+ +
+ ); + } + + return ( + +
+ {fehler && ( +
+ {fehler} +
+ )} + + + + + + + + + + + +
+
+ ); +}