forked from fahrPool/fahrPool
77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { loadProfile } from "@/lib/auth/profile";
|
|
import { canManageUsers } from "@/lib/auth/roles";
|
|
import { listNutzer } from "@/lib/nutzerverwaltung/queries";
|
|
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";
|
|
|
|
export default async function NutzerverwaltungPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ error?: string }>;
|
|
}) {
|
|
const profileResult = await loadProfile();
|
|
if (profileResult.status !== "ok" || !canManageUsers(profileResult.profile.role)) {
|
|
redirect(`/auftraege?error=${encodeURIComponent("Nur Admin darf die Nutzerverwaltung nutzen.")}`);
|
|
}
|
|
|
|
const { error } = await searchParams;
|
|
const nutzerListe = await listNutzer();
|
|
|
|
return (
|
|
<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 && (
|
|
<div className="mb-6">
|
|
<Alert>{error}</Alert>
|
|
</div>
|
|
)}
|
|
|
|
<section className="mb-8">
|
|
<NutzerTabelle nutzerListe={nutzerListe} eigeneId={profileResult.profile.id} />
|
|
</section>
|
|
|
|
<Card>
|
|
<form action={erstelleNutzer}>
|
|
<h2 className="mb-4 text-base font-semibold text-asphalt-grey">Neuen Nutzer anlegen</h2>
|
|
<FormField label="Name" htmlFor="name">
|
|
<input id="name" name="name" type="text" required className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<FormField label="Benutzername" htmlFor="username">
|
|
<input
|
|
id="username"
|
|
name="username"
|
|
type="text"
|
|
required
|
|
pattern="[a-z0-9._-]{3,30}"
|
|
className={FIELD_CLASSES}
|
|
/>
|
|
</FormField>
|
|
<FormField label="E-Mail" htmlFor="email">
|
|
<input id="email" name="email" type="email" required className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<FormField label="Passwort" htmlFor="passwort">
|
|
<input id="passwort" name="passwort" type="password" required minLength={8} className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<FormField label="Rolle" htmlFor="rolle">
|
|
<select id="rolle" name="rolle" defaultValue="readonly" className={FIELD_CLASSES}>
|
|
{GUELTIGE_ROLLEN.map((rolle) => (
|
|
<option key={rolle} value={rolle}>
|
|
{rolle}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</FormField>
|
|
<Button type="submit">Nutzer anlegen</Button>
|
|
</form>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|