diff --git a/web/app/plattform/[id]/page.tsx b/web/app/plattform/[id]/page.tsx index de28a83..748c25e 100644 --- a/web/app/plattform/[id]/page.tsx +++ b/web/app/plattform/[id]/page.tsx @@ -4,6 +4,7 @@ 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"; @@ -36,9 +37,10 @@ export default async function PlattformFirmaPage({ {error && {error}} - + Status: {firma.aktiv ? "aktiv" : deaktiviert} + Nutzer: {formatiereRollen(firma.rollen)} {firma.aktiv ? "Firma deaktivieren" : "Firma aktivieren"} diff --git a/web/app/plattform/page.tsx b/web/app/plattform/page.tsx index c68364e..3d8e38c 100644 --- a/web/app/plattform/page.tsx +++ b/web/app/plattform/page.tsx @@ -4,6 +4,7 @@ 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"; @@ -29,11 +30,12 @@ export default async function PlattformPage({ searchParams }: { searchParams: Pr {firmen.map((f) => ( - - {f.name} - - {f.nutzerAnzahl} Nutzer ยท {f.aktiv ? "aktiv" : deaktiviert} + + + {f.name} + {f.aktiv ? "aktiv" : deaktiviert} + {formatiereRollen(f.rollen)} ))} diff --git a/web/lib/plattform/queries.ts b/web/lib/plattform/queries.ts index f623f63..6895191 100644 --- a/web/lib/plattform/queries.ts +++ b/web/lib/plattform/queries.ts @@ -1,26 +1,25 @@ 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 }; +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. export async function listFirmen(admin: SupabaseClient): Promise { - 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}`); - return (data ?? []).map((f) => ({ - 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, - })); + return ((data ?? []) as FirmaZeile[]).map(zuUebersicht); } -export async function ladeFirmaFuerPlattform( - admin: SupabaseClient, - firmaId: string -): 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 ladeFirmaFuerPlattform(admin: SupabaseClient, firmaId: string): Promise { + const { data } = await admin.from("firmen").select("id, name, aktiv, profiles(role)").eq("id", firmaId).maybeSingle(); + return data ? zuUebersicht(data as FirmaZeile) : null; } export async function listFirmenAdmins(admin: SupabaseClient, firmaId: string): Promise {
+
Status: {firma.aktiv ? "aktiv" : deaktiviert}
Nutzer: {formatiereRollen(firma.rollen)}