"use client"; import { useEffect, useState } from "react"; import { RefreshCw, Bell } from "lucide-react"; import { AdminLayout } from "@/components/admin/admin-layout"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { useLanguage } from "@/components/language-provider"; interface NotificationItem { id: string; event_type: string; title: string; message: string; status: string; created_at: string; } export default function AdminNotificationsPage() { const { lang } = useLanguage(); const [notifications, setNotifications] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const token = localStorage.getItem("access_token"); if (!token) { window.location.href = "/login?redirect=/admin/notifications"; return; } const fetchData = async () => { const baseURL = process.env.NEXT_PUBLIC_API_URL; try { const res = await fetch(`${baseURL}/health/notifications/`, { headers: { Authorization: `Bearer ${token}` }, }); const data = await res.json(); setNotifications(data.results || []); } catch (e) { console.error(e); } finally { setLoading(false); } }; fetchData(); }, []); const t = (fa: string, en: string) => (lang === "fa" ? fa : en); if (loading) { return (
); } return (

{t("اعلانات", "Notifications")}

{notifications.map((n) => (

{n.title}

{n.status}

{n.message}

{new Date(n.created_at).toLocaleString(lang === "fa" ? "fa-IR" : "en-US")}

))} {notifications.length === 0 && !loading && (
{t("اعلانی یافت نشد", "No notifications found")}
)}
); }