import { useEffect, useState } from 'react' import AdminLayout from '../../components/AdminLayout' import { useAuth } from '../../context/AuthContext' import { fetchAdminStats } from '../../lib/api' export default function AdminDashboard() { const { user } = useAuth() const [stats, setStats] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { if (user && user.role === 'admin') { const loadStats = async () => { const data = await fetchAdminStats() setStats(data) setLoading(false) } loadStats() } }, [user]) if (!user || user.role !== 'admin') { return (

Unauthorized Access

You do not have permission to view this page

) } if (loading) return
Loading...
return (

Admin Dashboard

Total Articles

{stats.articles}

Active Projects

{stats.projects}

Current Tenders

{stats.tenders}

Recent Articles

{stats.recentArticles.map(article => (

{article.title}

{new Date(article.createdAt).toLocaleDateString()}

))}
) }