From a5b21436c75f8b6dacbb8eb51b05663f6fb0d86e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 6 Apr 2026 15:21:01 +0200 Subject: [PATCH] fix --- .../app/dashboard/admin/logs/page.tsx | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/apps/frontend/app/dashboard/admin/logs/page.tsx b/apps/frontend/app/dashboard/admin/logs/page.tsx index 9d5c6f2..b40fe25 100644 --- a/apps/frontend/app/dashboard/admin/logs/page.tsx +++ b/apps/frontend/app/dashboard/admin/logs/page.tsx @@ -11,9 +11,9 @@ import { Bug, Server, } from 'lucide-react'; +import { get, download } from '@/lib/api/client'; -const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000'; -const LOGS_API_URL = `${API_URL}/api/v1/logs`; +const LOGS_PREFIX = '/api/v1/logs'; // ─── Types ──────────────────────────────────────────────────────────────────── @@ -125,8 +125,7 @@ export default function AdminLogsPage() { // Load available services useEffect(() => { - fetch(`${LOGS_API_URL}/services`) - .then(r => r.json()) + get<{ services: string[] }>(`${LOGS_PREFIX}/services`) .then(d => setServices(d.services || [])) .catch(() => {}); }, []); @@ -150,14 +149,9 @@ export default function AdminLogsPage() { setLoading(true); setError(null); try { - const res = await fetch( - `${LOGS_API_URL}/export?${buildQueryString('json')}`, + const data = await get( + `${LOGS_PREFIX}/export?${buildQueryString('json')}`, ); - if (!res.ok) { - const body = await res.json().catch(() => ({})); - throw new Error(body.error || `HTTP ${res.status}`); - } - const data: LogsResponse = await res.json(); setLogs(data.logs || []); setTotal(data.total || 0); } catch (err: any) { @@ -174,19 +168,11 @@ export default function AdminLogsPage() { const handleExport = async (format: 'json' | 'csv') => { setExportLoading(true); try { - const res = await fetch( - `${LOGS_API_URL}/export?${buildQueryString(format)}`, + const filename = `xpeditis-logs-${new Date().toISOString().slice(0, 10)}.${format}`; + await download( + `${LOGS_PREFIX}/export?${buildQueryString(format)}`, + filename, ); - if (!res.ok) throw new Error(`HTTP ${res.status}`); - const blob = await res.blob(); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = `xpeditis-logs-${new Date().toISOString().slice(0, 10)}.${format}`; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); } catch (err: any) { setError(err.message); } finally {