"use client"; import { useState, useEffect } from "react"; import { useDictionary } from "@/components/DictionaryContext"; interface Log { id: string; mailbox: string; sender: string | null; subject: string | null; status: string; error: string | null; createdAt: string; user?: { name: string | null; email: string; } | null; } export default function LogsPage() { const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); const dict = useDictionary(); const fetchLogs = async () => { setLoading(true); try { const res = await fetch("/api/logs"); if (!res.ok) { const errorData = await res.json().catch(() => ({})); throw new Error(errorData.error || `HTTP error! status: ${res.status}`); } const data = await res.json(); if (Array.isArray(data)) setLogs(data); } catch (error: any) { console.error("Failed to fetch logs:", error); alert(error.message); } finally { setLoading(false); } }; useEffect(() => { fetchLogs(); }, []); return ( <>

{dict.logs?.title || "Bildirim Logları"}

{dict.logs?.subtitle || "Son gönderilen bildirimlerin durumu"}

{loading ? (
) : logs.length === 0 ? (
{dict.logs?.noLogs || "Log kaydı bulunamadı"}
) : ( {logs.map((log) => ( ))}
{dict.logs?.mailbox || "Alıcı"} {dict.logs?.sender || "Gönderen"} / {dict.logs?.subject || "Konu"} {dict.logs?.status || "Durum"} {dict.logs?.date || "Tarih"}
{log.mailbox}
{log.user && (
→ {log.user.name || log.user.email}
)}
{log.sender || "Unknown"}
{log.subject || "(No Subject)"}
{log.status === "SENT" ? (dict.logs?.sent || "GÖNDERİLDİ") : (dict.logs?.failed || "HATA")} {log.error && (
{log.error}
)}
{new Date(log.createdAt).toLocaleString()}
)}
); } function RefreshIcon() { return ( ); }