erp-platform/ui/src/components/classroom/Dashboard.tsx

36 lines
1 KiB
TypeScript
Raw Normal View History

2025-08-26 08:39:09 +00:00
import { useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { RoleSelector } from './RoleSelector'
import { useClassroomLogic } from '@/utils/hooks/useClassroomLogic'
import { ROUTES_ENUM } from '@/routes/route.constant'
import { Room } from './Room'
export function Dashboard() {
const {
2025-08-26 08:59:57 +00:00
roleState,
2025-08-26 08:39:09 +00:00
currentClass,
handleRoleSelect,
handleJoinClass,
handleLeaveClass,
handleCreateClass,
handleEditClass,
handleDeleteClass,
} = useClassroomLogic()
const navigate = useNavigate()
useEffect(() => {
2025-08-26 08:59:57 +00:00
if (roleState === 'dashboard') {
2025-08-26 08:39:09 +00:00
navigate(ROUTES_ENUM.protected.admin.classroom.classes, { replace: true })
}
2025-08-26 08:59:57 +00:00
}, [roleState, navigate])
2025-08-26 08:39:09 +00:00
2025-08-26 08:59:57 +00:00
if (roleState === 'role-selection') {
2025-08-26 08:39:09 +00:00
return <RoleSelector onRoleSelect={handleRoleSelect} />
2025-08-26 08:59:57 +00:00
} else if (roleState === 'dashboard') {
2025-08-26 08:39:09 +00:00
return null
2025-08-26 08:59:57 +00:00
} else if (roleState === 'classroom' && currentClass) {
2025-08-26 08:39:09 +00:00
return <Room classSession={currentClass} onLeaveClass={handleLeaveClass} />
}
return null
}