import { useEffect, useState, useCallback } from 'react' import { useTranslation } from 'react-i18next' import { useAuth } from '../contexts/AuthContext' import { dashboardApi, DashboardResponse } from '../services/dashboard' import { StatisticsCard, WorkloadWidget, HealthSummaryWidget, QuickActions, } from '../components/dashboard' import { Skeleton } from '../components/Skeleton' export default function Dashboard() { const { t } = useTranslation('dashboard') const { user } = useAuth() const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchDashboard = useCallback(async () => { setLoading(true) setError(null) try { const response = await dashboardApi.getDashboard() setData(response) } catch (err) { setError(t('common:messages.networkError')) console.error('Dashboard fetch error:', err) } finally { setLoading(false) } }, [t]) useEffect(() => { fetchDashboard() }, [fetchDashboard]) // Loading state if (loading) { return (
{/* Statistics Cards Skeleton */}
{[1, 2, 3, 4].map((i) => (
))}
{/* Widgets Skeleton */}
{/* Quick Actions Skeleton */}
{[1, 2, 3, 4].map((i) => ( ))}
) } // Error state if (error) { return (

{t('welcome', { name: user?.name })}

!

{t('common:messages.error')}

{error}

) } // Success state return (
{/* Welcome Section */}

{t('welcome', { name: user?.name })}

{t('sections.projectOverview')}

{/* Statistics Cards */} {data && ( <>
0} /> 0} />
{/* Widgets Grid */}
{/* Quick Actions */} )}
) } const styles: { [key: string]: React.CSSProperties } = { container: { padding: '24px', maxWidth: '1200px', margin: '0 auto', display: 'flex', flexDirection: 'column', gap: '24px', }, welcomeSection: { marginBottom: '8px', }, welcomeTitle: { margin: 0, fontSize: '24px', fontWeight: 600, color: '#333', }, welcomeSubtitle: { margin: '8px 0 0 0', fontSize: '14px', color: '#666', }, statsGrid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: '16px', }, widgetsGrid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(300px, 1fr))', gap: '16px', }, skeletonCard: { backgroundColor: 'white', borderRadius: '8px', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)', padding: '20px', display: 'flex', alignItems: 'center', gap: '16px', }, skeletonWidget: { backgroundColor: 'white', borderRadius: '8px', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)', padding: '20px', }, errorCard: { backgroundColor: 'white', borderRadius: '8px', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)', padding: '40px', textAlign: 'center', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '16px', }, errorIcon: { width: '60px', height: '60px', borderRadius: '50%', backgroundColor: '#ffebee', color: '#f44336', fontSize: '32px', fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center', }, errorTitle: { margin: 0, fontSize: '18px', fontWeight: 600, color: '#333', }, errorMessage: { margin: 0, fontSize: '14px', color: '#666', maxWidth: '400px', }, retryButton: { padding: '10px 24px', fontSize: '14px', fontWeight: 500, color: 'white', backgroundColor: '#2196f3', border: 'none', borderRadius: '6px', cursor: 'pointer', transition: 'background-color 0.2s ease', }, }