1
0
Fork 0
fahrPool/web/app/plattform/page.tsx

75 lines
3.2 KiB
TypeScript

import Link from "next/link";
import { redirect } from "next/navigation";
import { createAdminClient } from "@/lib/supabase/admin";
import { loadProfile } from "@/lib/auth/profile";
import { pruefeSuperadmin } from "@/lib/plattform/superadmin";
import { listFirmen } from "@/lib/plattform/queries";
import { formatiereRollen } from "@/lib/plattform/rollen";
import { legeFirmaAn } from "./actions";
import { InstallHinweis } from "@/components/pwa/InstallHinweis";
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 PlattformPage({
searchParams,
}: {
searchParams: Promise<{ error?: string; hinweis?: string }>;
}) {
if (!pruefeSuperadmin(await loadProfile())) {
redirect("/dashboard");
}
const { error, hinweis } = await searchParams;
const firmen = await listFirmen(createAdminClient());
return (
<div className="mx-auto flex max-w-2xl flex-col gap-6 p-4 md:p-8">
<InstallHinweis />
<h1 className="text-xl font-semibold text-asphalt-grey">Plattform-Verwaltung</h1>
{error && <Alert>{error}</Alert>}
{hinweis && (
<p role="status" className="rounded-md border border-status-success bg-green-50 px-4 py-3 text-asphalt-grey">
{hinweis}
</p>
)}
<Card>
<h2 className="mb-4 font-semibold text-asphalt-grey">Firmen</h2>
<ul className="flex flex-col divide-y divide-aluminium-grey">
{firmen.map((f) => (
<li key={f.id}>
<Link href={`/plattform/${f.id}`} className="flex min-h-11 flex-col justify-center gap-1 py-2 text-asphalt-grey hover:text-performance-blue">
<span className="flex items-center justify-between gap-4">
<span className="font-medium">{f.name}</span>
<span className="text-sm">{f.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}</span>
</span>
<span className="text-sm">{formatiereRollen(f.rollen)}</span>
</Link>
</li>
))}
</ul>
</Card>
<Card>
<h2 className="mb-4 font-semibold text-asphalt-grey">Neue Firma anlegen</h2>
<form action={legeFirmaAn}>
<FormField label="Firmenname" htmlFor="neu-firmenname">
<input id="neu-firmenname" name="firmenname" required maxLength={100} className={FIELD_CLASSES} />
</FormField>
<FormField label="Name des ersten Admins" htmlFor="neu-name">
<input id="neu-name" name="name" required className={FIELD_CLASSES} />
</FormField>
<FormField label="E-Mail des Admins" htmlFor="neu-email">
<input id="neu-email" name="email" type="email" required className={FIELD_CLASSES} />
</FormField>
<FormField label="Startpasswort (muss beim ersten Login geändert werden)" htmlFor="neu-passwort">
<input id="neu-passwort" name="passwort" type="password" required autoComplete="new-password" className={FIELD_CLASSES} />
</FormField>
<Button type="submit">Firma anlegen</Button>
</form>
</Card>
</div>
);
}