forked from fahrPool/fahrPool
91 lines
3.7 KiB
TypeScript
91 lines
3.7 KiB
TypeScript
import Link from "next/link";
|
|
import { notFound, redirect } from "next/navigation";
|
|
import { createAdminClient } from "@/lib/supabase/admin";
|
|
import { loadProfile } from "@/lib/auth/profile";
|
|
import { pruefeSuperadmin } from "@/lib/plattform/superadmin";
|
|
import { ladeFirmaFuerPlattform, listFirmenAdmins } from "@/lib/plattform/queries";
|
|
import { formatiereRollen } from "@/lib/plattform/rollen";
|
|
import { legeFirmenAdminAn, setzeAdminPasswort, setzeFirmaAktiv } from "../actions";
|
|
import { Alert } from "@/components/ui/Alert";
|
|
import { Button } from "@/components/ui/Button";
|
|
import { Card } from "@/components/ui/Card";
|
|
import { FIELD_CLASSES, FormField } from "@/components/ui/FormField";
|
|
|
|
export default async function PlattformFirmaPage({
|
|
params,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ id: string }>;
|
|
searchParams: Promise<{ error?: string }>;
|
|
}) {
|
|
if (!pruefeSuperadmin(await loadProfile())) {
|
|
redirect("/dashboard");
|
|
}
|
|
const { id } = await params;
|
|
const { error } = await searchParams;
|
|
const admin = createAdminClient();
|
|
const firma = await ladeFirmaFuerPlattform(admin, id);
|
|
if (!firma) notFound();
|
|
const admins = await listFirmenAdmins(admin, id);
|
|
|
|
return (
|
|
<div className="mx-auto flex max-w-2xl flex-col gap-6 p-4 md:p-8">
|
|
<Link href="/plattform" className="flex min-h-11 items-center text-performance-blue">
|
|
← Alle Firmen
|
|
</Link>
|
|
<h1 className="text-xl font-semibold text-asphalt-grey">{firma.name}</h1>
|
|
{error && <Alert>{error}</Alert>}
|
|
|
|
<Card>
|
|
<p className="text-asphalt-grey">
|
|
Status: {firma.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}
|
|
</p>
|
|
<p className="mb-4 text-asphalt-grey">Nutzer: {formatiereRollen(firma.rollen)}</p>
|
|
<form action={setzeFirmaAktiv.bind(null, firma.id, !firma.aktiv)}>
|
|
<Button type="submit" variant={firma.aktiv ? "destructive" : "primary"}>
|
|
{firma.aktiv ? "Firma deaktivieren" : "Firma aktivieren"}
|
|
</Button>
|
|
</form>
|
|
</Card>
|
|
|
|
<Card>
|
|
<h2 className="mb-4 font-semibold text-asphalt-grey">Admins</h2>
|
|
<ul className="flex flex-col gap-6">
|
|
{admins.map((a) => (
|
|
<li key={a.id}>
|
|
<p className="font-medium text-asphalt-grey">{a.name}</p>
|
|
<p className="mb-2 text-sm text-asphalt-grey">
|
|
{a.email ?? "-"} · {a.username}
|
|
</p>
|
|
<form action={setzeAdminPasswort.bind(null, firma.id, a.id)}>
|
|
<FormField label="Neues Passwort" htmlFor={`pw-${a.id}`}>
|
|
<input id={`pw-${a.id}`} name="passwort" type="password" required autoComplete="new-password" className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<Button type="submit" variant="secondary">
|
|
Passwort setzen
|
|
</Button>
|
|
</form>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</Card>
|
|
|
|
<Card>
|
|
<h2 className="mb-4 font-semibold text-asphalt-grey">Weiteren Admin anlegen</h2>
|
|
<form action={legeFirmenAdminAn.bind(null, firma.id)}>
|
|
<FormField label="Name" htmlFor="admin-name">
|
|
<input id="admin-name" name="name" required className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<FormField label="E-Mail" htmlFor="admin-email">
|
|
<input id="admin-email" name="email" type="email" required className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<FormField label="Startpasswort" htmlFor="admin-passwort">
|
|
<input id="admin-passwort" name="passwort" type="password" required autoComplete="new-password" className={FIELD_CLASSES} />
|
|
</FormField>
|
|
<Button type="submit">Admin anlegen</Button>
|
|
</form>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|