/** * Dashboard для студента (роль client) или для выбранного ребёнка (роль parent) */ 'use client'; import React, { useState, useEffect } from 'react'; import { getClientDashboard, getChildDashboard, DashboardStats } from '@/api/dashboard'; import { StatCard } from './StatCard'; import { LessonCard } from './LessonCard'; import { HomeworkCard } from './HomeworkCard'; import { LoadingSpinner } from '@/components/common/LoadingSpinner'; export interface ClientDashboardProps { /** Для родителя: id выбранного ребёнка (user_id) — данные загружаются как для этого ребёнка */ childId?: string | null; /** Для родителя: имя ребёнка для приветствия */ childName?: string | null; } export const ClientDashboard: React.FC = ({ childId }) => { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const isParentView = Boolean(childId); useEffect(() => { loadDashboard(); }, [childId]); const loadDashboard = async () => { try { setLoading(true); setError(null); const data = isParentView && childId ? await getChildDashboard(childId) : await getClientDashboard(); setStats(data); } catch (err: any) { console.error('Error loading dashboard:', err); setError(err.message || 'Ошибка загрузки данных'); } finally { setLoading(false); } }; if (error && !stats) { return (

{error}

); } return (
{/* Статистика студента */}
} /> } /> } /> } />
{/* Следующее занятие */} {stats?.next_lesson && (

Ближайшее занятие

)} {/* Домашние задания и расписание */}
{/* Домашние задания */}

Ваши домашние задания

{loading ? ( ) : stats?.recent_homework && stats.recent_homework.length > 0 ? (
{stats.recent_homework.slice(0, 3).map((homework) => ( ))}
) : (

Нет домашних заданий

)}
{/* Ближайшие занятия */}

Ваши занятия

{loading ? ( ) : stats?.upcoming_lessons && stats.upcoming_lessons.length > 0 ? (
{stats.upcoming_lessons.slice(0, 3).map((lesson) => ( ))}
) : (

Нет запланированных занятий

)}
); };