'use client'; import React, { useEffect, useState } from 'react'; import { CareerStats } from '@/app/types'; import { apiClient } from '@/app/utils/apiClient'; import { Box, Typography, Grid, Paper, Card, CardContent, CircularProgress, Alert } from '@mui/material'; import { Chart as ChartJS, ArcElement, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend } from 'chart.js'; import { Doughnut, Bar } from 'react-chartjs-2'; import WorkIcon from '@mui/icons-material/Work'; import PeopleIcon from '@mui/icons-material/People'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import HourglassEmptyIcon from '@mui/icons-material/HourglassEmpty'; ChartJS.register( ArcElement, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend ); const CareerStatsDashboard: React.FC = () => { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchStats = async () => { setLoading(true); try { const response = await apiClient('/careers/stats'); if (response.success) { setStats(response.data); } else { setError('Failed to load career statistics'); } } catch (err) { console.error('Error fetching career stats:', err); setError('Failed to load career statistics. Please try again.'); } finally { setLoading(false); } }; fetchStats(); }, []); const statsItems = [ { title: 'Total Job Listings', value: stats?.careers.total || 0, icon: , color: '#3b82f6' }, { title: 'Active Jobs', value: stats?.careers.active || 0, icon: , color: '#10b981' }, { title: 'Total Applications', value: stats?.applications.total || 0, icon: , color: '#8b5cf6' }, { title: 'Pending Applications', value: stats?.applications.pending || 0, icon: , color: '#f59e0b' } ]; if (loading) { return ( ); } if (error) { return ( {error} ); } return ( Careers Dashboard {statsItems.map((item, index) => ( {item.title} {item.value} {item.icon} ))} Job Listings Status Application Status Distribution ); }; export default CareerStatsDashboard;