forked from fahrPool/fahrPool
64 lines
2.9 KiB
TypeScript
64 lines
2.9 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 { 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 }> }) {
|
|
if (!pruefeSuperadmin(await loadProfile())) {
|
|
redirect("/dashboard");
|
|
}
|
|
const { error } = 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>}
|
|
|
|
<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 items-center justify-between gap-4 py-2 text-asphalt-grey hover:text-performance-blue">
|
|
<span className="font-medium">{f.name}</span>
|
|
<span className="text-sm">
|
|
{f.nutzerAnzahl} Nutzer · {f.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}
|
|
</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>
|
|
);
|
|
}
|