uchill/front_material/app/(protected)/dashboard/page.tsx

60 lines
1.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { useAuth } from '@/contexts/AuthContext';
import { useSelectedChild } from '@/contexts/SelectedChildContext';
import { LoadingSpinner } from '@/components/common/LoadingSpinner';
import { MentorDashboard } from '@/components/dashboard/MentorDashboard';
import { ClientDashboard } from '@/components/dashboard/ClientDashboard';
import { ParentDashboard } from '@/components/dashboard/ParentDashboard';
export default function DashboardPage() {
const { user, loading: authLoading } = useAuth();
const { selectedChild, loading: childLoading, childrenList } = useSelectedChild();
if (authLoading) {
return <LoadingSpinner size="large" fullPage />;
}
if (!user) {
return null;
}
if (user.role === 'mentor') {
return <MentorDashboard />;
}
if (user.role === 'client') {
return <ClientDashboard />;
}
// Родитель: те же страницы, что и студент — показываем дашборд выбранного ребёнка
if (user.role === 'parent') {
if (childLoading && childrenList.length === 0) {
return <LoadingSpinner size="large" fullPage />;
}
if (childrenList.length === 0) {
return (
<div style={{
padding: '24px',
textAlign: 'center',
color: 'var(--md-sys-color-on-surface-variant)'
}}>
<p>Нет привязанных детей. Обратитесь к администратору.</p>
</div>
);
}
if (selectedChild) {
return <ClientDashboard childId={selectedChild.id} childName={selectedChild.name} />;
}
return <ParentDashboard />;
}
return (
<div style={{
padding: '24px',
textAlign: 'center',
color: 'var(--md-sys-color-on-surface-variant)'
}}>
<p>Неизвестная роль пользователя</p>
</div>
);
}