/** * Dashboard для родителя */ 'use client'; import React, { useState, useEffect } from 'react'; import { getParentDashboard, DashboardStats } from '@/api/dashboard'; import { StatCard } from './StatCard'; import { LoadingSpinner } from '@/components/common/LoadingSpinner'; export const ParentDashboard: React.FC = () => { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { loadDashboard(); }, []); const loadDashboard = async () => { try { setLoading(true); setError(null); const data = await getParentDashboard(); setStats(data); } catch (err: any) { console.error('Error loading dashboard:', err); setError(err.message || 'Ошибка загрузки данных'); } finally { setLoading(false); } }; if (error && !stats) { return (

{error}

); } return (
{/* Приветствие */}

Добро пожаловать! 👨‍👩‍👧‍👦

Отслеживайте прогресс ваших детей и их успехи в обучении

{/* Статистика по детям */} {stats?.children_stats && stats.children_stats.length > 0 && (
{stats.children_stats.map((child) => (
{child.avatar_url ? ( {child.name} ) : (
{child.name.charAt(0).toUpperCase()}
)}

{child.name}

{child.completed_lessons} / {child.total_lessons} занятий

Прогресс занятий {Math.round((child.completed_lessons / child.total_lessons) * 100)}%
Средняя оценка: {child.average_grade != null ? String(parseFloat(Number(child.average_grade).toFixed(2))) : '—'}
Домашних заданий: 0 ? 'var(--md-sys-color-error)' : 'var(--md-sys-color-tertiary)' }}> {child.homework_pending}
))}
)} {/* Общая статистика */}
} />
); };