forked from fahrPool/fahrPool
feat: switch Nutzerverwaltung page to inline-editable table
This commit is contained in:
parent
d261061c1c
commit
930994126f
|
|
@ -2,14 +2,14 @@ import { redirect } from "next/navigation";
|
||||||
import { loadProfile } from "@/lib/auth/profile";
|
import { loadProfile } from "@/lib/auth/profile";
|
||||||
import { canManageUsers } from "@/lib/auth/roles";
|
import { canManageUsers } from "@/lib/auth/roles";
|
||||||
import { listNutzer } from "@/lib/nutzerverwaltung/queries";
|
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 { Card } from "@/components/ui/Card";
|
||||||
import { Button } from "@/components/ui/Button";
|
import { Button } from "@/components/ui/Button";
|
||||||
import { Alert } from "@/components/ui/Alert";
|
import { Alert } from "@/components/ui/Alert";
|
||||||
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
|
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
|
||||||
|
|
||||||
const ROLLEN_OPTIONEN = ["admin", "disponent", "fahrer", "readonly"] as const;
|
|
||||||
|
|
||||||
export default async function NutzerverwaltungPage({
|
export default async function NutzerverwaltungPage({
|
||||||
searchParams,
|
searchParams,
|
||||||
}: {
|
}: {
|
||||||
|
|
@ -24,7 +24,7 @@ export default async function NutzerverwaltungPage({
|
||||||
const nutzerListe = await listNutzer();
|
const nutzerListe = await listNutzer();
|
||||||
|
|
||||||
return (
|
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>
|
<h1 className="mb-6 text-xl font-semibold text-asphalt-grey">Nutzerverwaltung</h1>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
|
|
@ -34,52 +34,7 @@ export default async function NutzerverwaltungPage({
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<section className="mb-8">
|
<section className="mb-8">
|
||||||
<ul className="grid grid-cols-1 gap-3">
|
<NutzerTabelle nutzerListe={nutzerListe} eigeneId={profileResult.profile.id} />
|
||||||
{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>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
|
|
@ -96,7 +51,7 @@ export default async function NutzerverwaltungPage({
|
||||||
</FormField>
|
</FormField>
|
||||||
<FormField label="Rolle" htmlFor="rolle">
|
<FormField label="Rolle" htmlFor="rolle">
|
||||||
<select id="rolle" name="rolle" defaultValue="readonly" className={FIELD_CLASSES}>
|
<select id="rolle" name="rolle" defaultValue="readonly" className={FIELD_CLASSES}>
|
||||||
{ROLLEN_OPTIONEN.map((rolle) => (
|
{GUELTIGE_ROLLEN.map((rolle) => (
|
||||||
<option key={rolle} value={rolle}>
|
<option key={rolle} value={rolle}>
|
||||||
{rolle}
|
{rolle}
|
||||||
</option>
|
</option>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue