1
0
Fork 0

feat: switch Nutzerverwaltung page to inline-editable table

This commit is contained in:
Jonny 2026-08-17 18:03:26 +02:00
parent d261061c1c
commit 930994126f
1 changed files with 6 additions and 51 deletions

View File

@ -2,14 +2,14 @@ import { redirect } from "next/navigation";
import { loadProfile } from "@/lib/auth/profile";
import { canManageUsers } from "@/lib/auth/roles";
import { listNutzer } from "@/lib/nutzerverwaltung/queries";
import { erstelleNutzer, aendereRolle, sperreNutzer, entsperreNutzer } from "./actions";
import { GUELTIGE_ROLLEN } from "@/lib/nutzerverwaltung/validate-nutzer";
import { erstelleNutzer } from "./actions";
import { NutzerTabelle } from "@/components/nutzerverwaltung/NutzerTabelle";
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";
const ROLLEN_OPTIONEN = ["admin", "disponent", "fahrer", "readonly"] as const;
export default async function NutzerverwaltungPage({
searchParams,
}: {
@ -24,7 +24,7 @@ export default async function NutzerverwaltungPage({
const nutzerListe = await listNutzer();
return (
<div className="mx-auto max-w-2xl p-4 md:p-8">
<div className="mx-auto max-w-4xl p-4 md:p-8">
<h1 className="mb-6 text-xl font-semibold text-asphalt-grey">Nutzerverwaltung</h1>
{error && (
@ -34,52 +34,7 @@ export default async function NutzerverwaltungPage({
)}
<section className="mb-8">
<ul className="grid grid-cols-1 gap-3">
{nutzerListe.map((nutzer) => {
const istEigenerAccount = nutzer.id === profileResult.profile.id;
const aendereRolleAction = aendereRolle.bind(null, nutzer.id);
const sperrenAction = sperreNutzer.bind(null, nutzer.id);
const entsperrenAction = entsperreNutzer.bind(null, nutzer.id);
return (
<li key={nutzer.id}>
<Card>
<p className="text-asphalt-grey">
{nutzer.name} {nutzer.email ? `(${nutzer.email})` : ""}
{nutzer.gesperrt && <span className="ml-2 text-status-danger">Gesperrt</span>}
</p>
<form action={aendereRolleAction} className="mt-2 flex flex-wrap items-center gap-3">
<select
name="rolle"
defaultValue={nutzer.role}
disabled={istEigenerAccount}
className={FIELD_CLASSES}
>
{ROLLEN_OPTIONEN.map((rolle) => (
<option key={rolle} value={rolle}>
{rolle}
</option>
))}
</select>
<Button type="submit" fullWidth={false} disabled={istEigenerAccount}>
Rolle ändern
</Button>
</form>
<form action={nutzer.gesperrt ? entsperrenAction : sperrenAction} className="mt-2">
<Button
type="submit"
fullWidth={false}
variant={nutzer.gesperrt ? "secondary" : "destructive"}
disabled={istEigenerAccount}
>
{nutzer.gesperrt ? "Entsperren" : "Sperren"}
</Button>
</form>
</Card>
</li>
);
})}
</ul>
<NutzerTabelle nutzerListe={nutzerListe} eigeneId={profileResult.profile.id} />
</section>
<Card>
@ -96,7 +51,7 @@ export default async function NutzerverwaltungPage({
</FormField>
<FormField label="Rolle" htmlFor="rolle">
<select id="rolle" name="rolle" defaultValue="readonly" className={FIELD_CLASSES}>
{ROLLEN_OPTIONEN.map((rolle) => (
{GUELTIGE_ROLLEN.map((rolle) => (
<option key={rolle} value={rolle}>
{rolle}
</option>