import Link from "next/link"; import { redirect } from "next/navigation"; import { createClient } from "@/lib/supabase/server"; import { loadProfile } from "@/lib/auth/profile"; import { kannAuditLogSehen } from "@/lib/auth/roles"; import { BEREICHE, aenderungZeilen, akteurText, aktionText, bereichText, datensatzText, formatiereZeitpunkt } from "@/lib/audit/bezeichnungen"; import { filterAlsQuery, parseAuditFilter } from "@/lib/audit/filter"; import { ladeAuditLog } from "@/lib/audit/queries"; import { Card } from "@/components/ui/Card"; import { FIELD_CLASSES, FormField } from "@/components/ui/FormField"; import { buttonClasses } from "@/components/ui/Button"; const PRO_SEITE = 50; // Obergrenze je Seitenaufruf (PostgREST max_rows, Standard 1000). const MAX_LADEN = 1000; export default async function AuditLogPage({ searchParams, }: { searchParams: Promise>; }) { const profil = await loadProfile(); if (profil.status !== "ok" || !kannAuditLogSehen(profil.profile.role)) { redirect("/dashboard"); } const filter = parseAuditFilter(await searchParams); const supabase = await createClient(); const gewuenscht = filter.seite * PRO_SEITE; // Eine Zeile mehr laden, um zu wissen, ob es weitergeht (max. MAX_LADEN je Aufruf). const eintraege = await ladeAuditLog(supabase, { role: profil.profile.role, firmaId: profil.profile.firma_id }, filter, { limit: Math.min(gewuenscht + 1, MAX_LADEN), offset: 0, }); const hatMehr = eintraege.length > gewuenscht; const sichtbar = eintraege.slice(0, gewuenscht); const { data: nutzer, error: nutzerFehler } = await supabase.from("profiles").select("id, name").order("name"); if (nutzerFehler) { throw new Error(`Nutzer laden fehlgeschlagen: ${nutzerFehler.message}`); } const namen = new Map((nutzer ?? []).map((n) => [n.id as string, n.name as string])); const query = filterAlsQuery(filter); return (

Audit-Log

CSV exportieren
{sichtbar.length === 0 ? (

Keine Einträge gefunden.

) : ( )} {hatMehr && ( Weitere laden )}
); }