import React, { useEffect } from 'react';
import { Link } from 'react-router-dom';
import { AccessTime, KeyboardArrowRight, MenuBook, People, School } from '@mui/icons-material';
import useTimetableStore from '../../stores/timetableStore';
import { useUser } from '../../contexts/UserContext';
import { useNeoInstitute } from '../../contexts/NeoInstituteContext';
import { CircularProgress } from '@mui/material';
import { logger } from '../../debugConfig';
const MyClassesSkeleton = () => (
);
const MyClassesPage: React.FC = () => {
const { profile } = useUser();
const { selectedInstituteId } = useNeoInstitute();
const {
myClasses,
classesLoading: myClassesLoading,
classesError: myClassesError,
fetchMyClasses,
} = useTimetableStore();
useEffect(() => {
fetchMyClasses().catch((error) =>
logger.warn('my-classes', 'Fetch my classes failed', {
message: error instanceof Error ? error.message : String(error),
})
);
}, [fetchMyClasses, selectedInstituteId]);
if (myClassesLoading) {
return ;
}
const getRoleLabel = (role: string) => {
switch (role) {
case 'teacher': return { text: 'Teacher', color: 'bg-purple-100 text-purple-700' };
case 'student': return { text: 'Student', color: 'bg-green-100 text-green-700' };
case 'assistant': return { text: 'Assistant', color: 'bg-blue-100 text-blue-700' };
default: return { text: role, color: 'bg-gray-100 text-gray-700' };
}
};
const getStatusLabel = (status: string) => {
switch (status) {
case 'active': return { text: 'Active', color: 'bg-green-100 text-green-700' };
case 'pending': return { text: 'Pending', color: 'bg-yellow-100 text-yellow-700' };
case 'completed': return { text: 'Completed', color: 'bg-gray-100 text-gray-700' };
case 'cancelled': return { text: 'Cancelled', color: 'bg-red-100 text-red-700' };
default: return { text: status, color: 'bg-gray-100 text-gray-700' };
}
};
if (myClassesError) {
return (
Error loading your classes: {myClassesError}
);
}
// Separate classes by role
const teachingClasses = myClasses.filter(c => c.role === 'teacher' || c.role === 'assistant');
const enrolledClasses = myClasses.filter(c => c.role === 'student');
return (
{/* Header */}
My Classes
Manage your enrolled classes and teaching assignments
{/* Teaching Section */}
{teachingClasses.length > 0 && (
Teaching
{teachingClasses.length}
{teachingClasses.map((classItem) => (
{classItem.name}
{classItem.class_code && (
{classItem.class_code}
)}
{classItem.description || 'No description'}
{getRoleLabel(classItem.role).text}
{getStatusLabel(classItem.status).text}
{(classItem as any).enrolled_count || 0} students
{classItem.academic_year && (
{classItem.academic_year}
)}
))}
)}
{/* Enrolled Section */}
{enrolledClasses.length > 0 && (
Enrolled
{enrolledClasses.length}
{enrolledClasses.map((classItem) => (
{classItem.name}
{classItem.class_code && (
{classItem.class_code}
)}
{classItem.description || 'No description'}
{getStatusLabel(classItem.status).text}
{(classItem as any).primary_teacher_name} {}
{classItem.academic_year && (
{classItem.academic_year}
)}
))}
)}
{/* Empty State */}
{myClasses.length === 0 && (
No classes found
You are not enrolled in or teaching any classes yet.
Browse Available Classes
)}
);
};
export default MyClassesPage;