1
0
Fork 0

feat: add Standorte page with inline-editable table

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCHRPWuV3bd37NJhW2NK6P
This commit is contained in:
Jonny 2026-08-17 15:02:17 +02:00
parent 587e36f81c
commit a33a18e6fa
4 changed files with 237 additions and 0 deletions

View File

@ -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 (
<div className="mx-auto max-w-4xl p-4 md:p-8">
<h1 className="mb-6 text-xl font-semibold text-asphalt-grey">Standorte</h1>
<StandorteTabelle orte={orte} />
</div>
);
}

View File

@ -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<string | null>(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 (
<div role="row" className="p-4 md:px-4 md:py-3">
<button
type="button"
onClick={() => setOffen(true)}
className="min-h-11 text-sm text-performance-blue hover:underline"
>
+ Neuen Standort anlegen
</button>
</div>
);
}
return (
<Card role="row" className="md:rounded-none md:border-0 md:border-b">
<form
action={handleSubmit}
className="flex flex-col gap-3 md:grid md:grid-cols-[1fr_1fr_auto_auto] md:items-end md:gap-4"
>
{fehler && (
<div className="md:col-span-4">
<Alert>{fehler}</Alert>
</div>
)}
<FormField label="Adresse" htmlFor="neu-standort-adresse">
<input id="neu-standort-adresse" name="adresse" type="text" required className={FIELD_CLASSES} />
</FormField>
<FormField label="Ansprechpartner" htmlFor="neu-standort-ansprechpartner">
<input
id="neu-standort-ansprechpartner"
name="ansprechpartner"
type="text"
required
className={FIELD_CLASSES}
/>
</FormField>
<Button type="submit" fullWidth={false} disabled={isPending}>
Anlegen
</Button>
<Button
type="button"
variant="secondary"
fullWidth={false}
onClick={() => {
setOffen(false);
setFehler(null);
}}
>
Abbrechen
</Button>
</form>
</Card>
);
}

View File

@ -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<string | null>(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 (
<Card
role="row"
className="md:grid md:grid-cols-[1fr_1fr_auto] md:items-center md:gap-4 md:rounded-none md:border-0 md:border-b md:p-0 md:px-4 md:py-3 md:shadow-none"
>
<div role="cell">
<span className="text-xs font-medium text-asphalt-grey md:hidden">Adresse</span>
<p className="text-asphalt-grey">{ort.adresse}</p>
</div>
<div role="cell" className="mt-2 md:mt-0">
<span className="text-xs font-medium text-asphalt-grey md:hidden">Ansprechpartner</span>
<p className="text-asphalt-grey">{ort.ansprechpartner}</p>
</div>
<div role="cell" className="mt-3 md:mt-0">
<button
type="button"
onClick={() => setBearbeiten(true)}
className="min-h-11 text-sm text-performance-blue hover:underline"
>
Bearbeiten
</button>
</div>
</Card>
);
}
return (
<Card role="row" className="md:rounded-none md:border-0 md:border-b">
<form
action={handleSubmit}
className="flex flex-col gap-3 md:grid md:grid-cols-[1fr_1fr_auto_auto] md:items-end md:gap-4"
>
{fehler && (
<div className="md:col-span-4">
<Alert>{fehler}</Alert>
</div>
)}
<FormField label="Adresse" htmlFor={`adresse-${ort.id}`}>
<input
id={`adresse-${ort.id}`}
name="adresse"
type="text"
required
defaultValue={ort.adresse}
className={FIELD_CLASSES}
/>
</FormField>
<FormField label="Ansprechpartner" htmlFor={`ansprechpartner-${ort.id}`}>
<input
id={`ansprechpartner-${ort.id}`}
name="ansprechpartner"
type="text"
required
defaultValue={ort.ansprechpartner}
className={FIELD_CLASSES}
/>
</FormField>
<Button type="submit" fullWidth={false} disabled={isPending}>
Speichern
</Button>
<Button
type="button"
variant="secondary"
fullWidth={false}
onClick={() => {
setBearbeiten(false);
setFehler(null);
}}
>
Abbrechen
</Button>
</form>
</Card>
);
}

View File

@ -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 (
<div role="table" aria-label="Standorte" className="w-full">
<div
role="row"
className="hidden border-b border-aluminium-grey px-4 py-2 text-sm font-semibold text-asphalt-grey md:grid md:grid-cols-[1fr_1fr_auto]"
>
<div role="columnheader">Adresse</div>
<div role="columnheader">Ansprechpartner</div>
<div role="columnheader">
<span className="sr-only">Aktionen</span>
</div>
</div>
<div role="rowgroup" className="flex flex-col gap-3 md:gap-0">
{orte.map((ort) => (
<StandortZeile key={ort.id} ort={ort} />
))}
<NeuerStandort />
</div>
</div>
);
}