From a33a18e6fa59ff885cd65c0cb860df0747be16a5 Mon Sep 17 00:00:00 2001 From: Jonny Date: Mon, 17 Aug 2026 15:02:17 +0200 Subject: [PATCH] feat: add Standorte page with inline-editable table Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01HCHRPWuV3bd37NJhW2NK6P --- web/app/standorte/page.tsx | 21 ++++ web/components/standorte/NeuerStandort.tsx | 84 ++++++++++++++ web/components/standorte/StandortZeile.tsx | 106 ++++++++++++++++++ web/components/standorte/StandorteTabelle.tsx | 26 +++++ 4 files changed, 237 insertions(+) create mode 100644 web/app/standorte/page.tsx create mode 100644 web/components/standorte/NeuerStandort.tsx create mode 100644 web/components/standorte/StandortZeile.tsx create mode 100644 web/components/standorte/StandorteTabelle.tsx diff --git a/web/app/standorte/page.tsx b/web/app/standorte/page.tsx new file mode 100644 index 0000000..673ee67 --- /dev/null +++ b/web/app/standorte/page.tsx @@ -0,0 +1,21 @@ +import { redirect } from "next/navigation"; +import { loadProfile } from "@/lib/auth/profile"; +import { kannStammdatenPflegen } from "@/lib/auth/roles"; +import { listOrte } from "@/lib/auftraege/queries"; +import { StandorteTabelle } from "@/components/standorte/StandorteTabelle"; + +export default async function StandortePage() { + const profileResult = await loadProfile(); + if (profileResult.status !== "ok" || !kannStammdatenPflegen(profileResult.profile.role)) { + redirect(`/auftraege?error=${encodeURIComponent("Nur Disponent/Admin duerfen Stammdaten pflegen.")}`); + } + + const orte = await listOrte(); + + return ( +
+

Standorte

+ +
+ ); +} diff --git a/web/components/standorte/NeuerStandort.tsx b/web/components/standorte/NeuerStandort.tsx new file mode 100644 index 0000000..718f309 --- /dev/null +++ b/web/components/standorte/NeuerStandort.tsx @@ -0,0 +1,84 @@ +"use client"; + +import { useState, useTransition } from "react"; +import { useRouter } from "next/navigation"; +import { createOrt } from "@/app/standorte/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 NeuerStandort() { + 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 createOrt(formData); + if (!ergebnis.success) { + setFehler(ergebnis.error); + return; + } + setFehler(null); + setOffen(false); + router.refresh(); + }); + } + + if (!offen) { + return ( +
+ +
+ ); + } + + return ( + +
+ {fehler && ( +
+ {fehler} +
+ )} + + + + + + + + +
+
+ ); +} diff --git a/web/components/standorte/StandortZeile.tsx b/web/components/standorte/StandortZeile.tsx new file mode 100644 index 0000000..b5b5010 --- /dev/null +++ b/web/components/standorte/StandortZeile.tsx @@ -0,0 +1,106 @@ +"use client"; + +import { useState, useTransition } from "react"; +import { useRouter } from "next/navigation"; +import type { Ort } from "@/lib/auftraege/queries"; +import { updateOrt } from "@/app/standorte/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 StandortZeile({ ort }: { ort: Ort }) { + 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 updateOrt(ort.id, formData); + if (!ergebnis.success) { + setFehler(ergebnis.error); + return; + } + setFehler(null); + setBearbeiten(false); + router.refresh(); + }); + } + + if (!bearbeiten) { + return ( + +
+ Adresse +

{ort.adresse}

+
+
+ Ansprechpartner +

{ort.ansprechpartner}

+
+
+ +
+
+ ); + } + + return ( + +
+ {fehler && ( +
+ {fehler} +
+ )} + + + + + + + + +
+
+ ); +} diff --git a/web/components/standorte/StandorteTabelle.tsx b/web/components/standorte/StandorteTabelle.tsx new file mode 100644 index 0000000..31e89ae --- /dev/null +++ b/web/components/standorte/StandorteTabelle.tsx @@ -0,0 +1,26 @@ +import type { Ort } from "@/lib/auftraege/queries"; +import { StandortZeile } from "./StandortZeile"; +import { NeuerStandort } from "./NeuerStandort"; + +export function StandorteTabelle({ orte }: { orte: Ort[] }) { + return ( +
+
+
Adresse
+
Ansprechpartner
+
+ Aktionen +
+
+
+ {orte.map((ort) => ( + + ))} + +
+
+ ); +}