forked from fahrPool/fahrPool
feat: Plattform-Verwaltung zeigt Nutzer je Rolle pro Firma
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1592c2f9c8
commit
8daa1b0a40
|
|
@ -4,6 +4,7 @@ import { createAdminClient } from "@/lib/supabase/admin";
|
||||||
import { loadProfile } from "@/lib/auth/profile";
|
import { loadProfile } from "@/lib/auth/profile";
|
||||||
import { pruefeSuperadmin } from "@/lib/plattform/superadmin";
|
import { pruefeSuperadmin } from "@/lib/plattform/superadmin";
|
||||||
import { ladeFirmaFuerPlattform, listFirmenAdmins } from "@/lib/plattform/queries";
|
import { ladeFirmaFuerPlattform, listFirmenAdmins } from "@/lib/plattform/queries";
|
||||||
|
import { formatiereRollen } from "@/lib/plattform/rollen";
|
||||||
import { legeFirmenAdminAn, setzeAdminPasswort, setzeFirmaAktiv } from "../actions";
|
import { legeFirmenAdminAn, setzeAdminPasswort, setzeFirmaAktiv } from "../actions";
|
||||||
import { Alert } from "@/components/ui/Alert";
|
import { Alert } from "@/components/ui/Alert";
|
||||||
import { Button } from "@/components/ui/Button";
|
import { Button } from "@/components/ui/Button";
|
||||||
|
|
@ -36,9 +37,10 @@ export default async function PlattformFirmaPage({
|
||||||
{error && <Alert>{error}</Alert>}
|
{error && <Alert>{error}</Alert>}
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<p className="mb-4 text-asphalt-grey">
|
<p className="text-asphalt-grey">
|
||||||
Status: {firma.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}
|
Status: {firma.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}
|
||||||
</p>
|
</p>
|
||||||
|
<p className="mb-4 text-asphalt-grey">Nutzer: {formatiereRollen(firma.rollen)}</p>
|
||||||
<form action={setzeFirmaAktiv.bind(null, firma.id, !firma.aktiv)}>
|
<form action={setzeFirmaAktiv.bind(null, firma.id, !firma.aktiv)}>
|
||||||
<Button type="submit" variant={firma.aktiv ? "destructive" : "primary"}>
|
<Button type="submit" variant={firma.aktiv ? "destructive" : "primary"}>
|
||||||
{firma.aktiv ? "Firma deaktivieren" : "Firma aktivieren"}
|
{firma.aktiv ? "Firma deaktivieren" : "Firma aktivieren"}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { createAdminClient } from "@/lib/supabase/admin";
|
||||||
import { loadProfile } from "@/lib/auth/profile";
|
import { loadProfile } from "@/lib/auth/profile";
|
||||||
import { pruefeSuperadmin } from "@/lib/plattform/superadmin";
|
import { pruefeSuperadmin } from "@/lib/plattform/superadmin";
|
||||||
import { listFirmen } from "@/lib/plattform/queries";
|
import { listFirmen } from "@/lib/plattform/queries";
|
||||||
|
import { formatiereRollen } from "@/lib/plattform/rollen";
|
||||||
import { legeFirmaAn } from "./actions";
|
import { legeFirmaAn } from "./actions";
|
||||||
import { InstallHinweis } from "@/components/pwa/InstallHinweis";
|
import { InstallHinweis } from "@/components/pwa/InstallHinweis";
|
||||||
import { Alert } from "@/components/ui/Alert";
|
import { Alert } from "@/components/ui/Alert";
|
||||||
|
|
@ -29,11 +30,12 @@ export default async function PlattformPage({ searchParams }: { searchParams: Pr
|
||||||
<ul className="flex flex-col divide-y divide-aluminium-grey">
|
<ul className="flex flex-col divide-y divide-aluminium-grey">
|
||||||
{firmen.map((f) => (
|
{firmen.map((f) => (
|
||||||
<li key={f.id}>
|
<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">
|
<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="font-medium">{f.name}</span>
|
||||||
<span className="text-sm">
|
<span className="text-sm">{f.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}</span>
|
||||||
{f.nutzerAnzahl} Nutzer · {f.aktiv ? "aktiv" : <span className="text-status-danger">deaktiviert</span>}
|
|
||||||
</span>
|
</span>
|
||||||
|
<span className="text-sm">{formatiereRollen(f.rollen)}</span>
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,25 @@
|
||||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||||
|
import { zaehleRollen, type RollenAnzahl } from "./rollen";
|
||||||
|
|
||||||
export type FirmaUebersicht = { id: string; name: string; aktiv: boolean; nutzerAnzahl: number };
|
export type FirmaUebersicht = { id: string; name: string; aktiv: boolean; rollen: RollenAnzahl };
|
||||||
export type FirmenAdmin = { id: string; name: string; username: string; email: string | null };
|
export type FirmenAdmin = { id: string; name: string; username: string; email: string | null };
|
||||||
|
|
||||||
|
type FirmaZeile = { id: string; name: string; aktiv: boolean; profiles: { role: string | null }[] | null };
|
||||||
|
|
||||||
|
function zuUebersicht(f: FirmaZeile): FirmaUebersicht {
|
||||||
|
return { id: f.id, name: f.name, aktiv: f.aktiv, rollen: zaehleRollen(f.profiles) };
|
||||||
|
}
|
||||||
|
|
||||||
// Nur mit dem Service-Client aufrufen.
|
// Nur mit dem Service-Client aufrufen.
|
||||||
export async function listFirmen(admin: SupabaseClient): Promise<FirmaUebersicht[]> {
|
export async function listFirmen(admin: SupabaseClient): Promise<FirmaUebersicht[]> {
|
||||||
const { data, error } = await admin.from("firmen").select("id, name, aktiv, profiles(count)").order("name");
|
const { data, error } = await admin.from("firmen").select("id, name, aktiv, profiles(role)").order("name");
|
||||||
if (error) throw new Error(`Firmen laden fehlgeschlagen: ${error.message}`);
|
if (error) throw new Error(`Firmen laden fehlgeschlagen: ${error.message}`);
|
||||||
return (data ?? []).map((f) => ({
|
return ((data ?? []) as FirmaZeile[]).map(zuUebersicht);
|
||||||
id: f.id as string,
|
|
||||||
name: f.name as string,
|
|
||||||
aktiv: f.aktiv as boolean,
|
|
||||||
nutzerAnzahl: ((f.profiles as { count: number }[] | null)?.[0]?.count ?? 0) as number,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ladeFirmaFuerPlattform(
|
export async function ladeFirmaFuerPlattform(admin: SupabaseClient, firmaId: string): Promise<FirmaUebersicht | null> {
|
||||||
admin: SupabaseClient,
|
const { data } = await admin.from("firmen").select("id, name, aktiv, profiles(role)").eq("id", firmaId).maybeSingle();
|
||||||
firmaId: string
|
return data ? zuUebersicht(data as FirmaZeile) : null;
|
||||||
): Promise<{ id: string; name: string; aktiv: boolean } | null> {
|
|
||||||
const { data } = await admin.from("firmen").select("id, name, aktiv").eq("id", firmaId).maybeSingle();
|
|
||||||
return (data as { id: string; name: string; aktiv: boolean } | null) ?? null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listFirmenAdmins(admin: SupabaseClient, firmaId: string): Promise<FirmenAdmin[]> {
|
export async function listFirmenAdmins(admin: SupabaseClient, firmaId: string): Promise<FirmenAdmin[]> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue