import Link from "next/link"; import { redirect } from "next/navigation"; import { getLocale, getTranslations } from "next-intl/server"; import { Download, PackageOpen } from "lucide-react"; import { requireSession } from "@/server/auth"; import { dbForTenant } from "@/server/db"; import { hasPermission } from "@/server/rbac"; import { PageHead, Pill } from "@/components/mockup-ui"; import { Button } from "@/components/ui/button"; import { formatInstantDate } from "@/lib/trial/dates"; import { requestExportAction } from "@/server/actions/trial-tenant"; import { listTenantExports } from "@/server/services/trial/export"; const TONE = { queued: "warn", running: "warn", done: "ok", failed: "mut", expired: "mut" } as const; /** L15 Testphase: data export for tenant administrators (also available in the read-only state). */ export default async function DataExportPage({ searchParams }: { searchParams: Promise<{ requested?: string; error?: string }> }) { const session = await requireSession(); if (!hasPermission(session, "tenant:manage")) redirect("/dashboard"); const sp = await searchParams; const [t, locale] = await Promise.all([getTranslations("trial.export"), getLocale()]); const ctx = { db: dbForTenant(session.user.tenantId), tenantId: session.user.tenantId, userId: session.user.id, permissions: new Set(session.user.permissions ?? []) }; const exports = await listTenantExports(ctx); const errorKey = sp.error === "export_running" ? "export_running" : "failed"; return (

{t("contents")}

{t("readOnlyHint")}

{sp.requested &&

{t("requested")}

} {sp.error &&

{t(`errors.${errorKey}`)}

}

{t("listTitle")}

{exports.length === 0 ? (

{t("empty")}

) : (
    {exports.map((e) => { const status = e.expired ? "expired" : (e.status as keyof typeof TONE); return (
  • {t(`status.${status}`)} {t("created")}: {e.createdAt.toLocaleString(locale === "en" ? "en-GB" : "de-DE", { timeZone: "Europe/Berlin" })} {e.bytes != null && {(e.bytes / 1024 / 1024).toFixed(1)} MB} {e.status === "failed" && e.error && {e.error}} {e.status === "done" && !e.expired && ( {t("download")} {e.expiresAt && ({t("expires", { date: formatInstantDate(e.expiresAt, locale) })})} )}
  • ); })}
)}
); }