Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,085 changes: 6 additions & 1,079 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/components/admin/AttendanceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function AttendanceTable() {
const loadRecords = async () => {
const { data, error } = await supabase.from("attendance_records").select(`
*,
attendance_sessions(classes(title)),
users!attendance_records_student_id_fkey(name)
`);

Expand Down Expand Up @@ -53,7 +52,7 @@ export function AttendanceTable() {
{records.map((record) => (
<TableRow key={record.id}>
<TableCell>
{(record as any).attendance_sessions?.classes?.title}
{(record as any).classes?.title}
</TableCell>
<TableCell>{(record as any).users?.name}</TableCell>
<TableCell>
Expand Down
2 changes: 1 addition & 1 deletion src/components/admin/DatabaseDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export default function DatabaseDashboard() {
onClick={async () => {
try {
const { data, error } = await supabase
.from("attendance")
.from("attendance_records")
.select("*")
.limit(5);
console.log("Attendance query result:", {
Expand Down
3 changes: 1 addition & 2 deletions src/components/dashboard/AttendanceMonitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ const AttendanceMonitor = ({
? "default"
: student.status === "absent"
? "destructive"
: "warning"
: "outline"
}
>
{student.status.charAt(0).toUpperCase() +
Expand Down Expand Up @@ -546,7 +546,6 @@ const AttendanceMonitor = ({
<Progress
value={zone.confusion_level * 100}
className="w-16 h-2"
indicatorClassName="bg-red-500"
/>
<span className="text-xs w-8">
{Math.round(zone.confusion_level * 100)}%
Expand Down
25 changes: 10 additions & 15 deletions src/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,19 @@ const TeacherDashboard = () => {

// Load teacher's subjects from the new timetable system
const { data: teacherSubjects, error: subjectsError } = await supabase
.from("subjects")
.from("classes")
.select(
`
*,
slot_assignments!inner(
slots(
slot_code,
day_of_week,
start_time,
end_time
)
class_enrollments!inner(
student_id,
student_name,
student_image_url
)
`,
)
.eq("teacher_id", userData.id)
.eq("is_active", true)
.eq("slot_assignments.is_active", true);
.eq("is_active", true);

if (subjectsError) {
console.error("Error fetching teacher subjects:", subjectsError);
Expand All @@ -123,10 +119,9 @@ const TeacherDashboard = () => {
const subjectsWithEnrollment = await Promise.all(
(teacherSubjects || []).map(async (subject) => {
const { count } = await supabase
.from("student_subject_registrations")
.from("class_enrollments")
.select("*", { count: "exact", head: true })
.eq("subject_id", subject.id)
.eq("is_active", true);
.eq("class_id", subject.id);

const enrollmentCount = count || 0;
totalEnrolledStudents += enrollmentCount;
Expand Down Expand Up @@ -183,7 +178,7 @@ const TeacherDashboard = () => {
.select(
"*, users!attendance_records_student_id_fkey(name, image_url)",
)
.eq("subject_id", activeSubject.id);
.eq("class_id", activeSubject.id);

setAttendanceData(attendance || []);
}
Expand Down Expand Up @@ -214,7 +209,7 @@ const TeacherDashboard = () => {
try {
// Update subject capacity in the new timetable system
const { error } = await supabase
.from("subjects")
.from("classes")
.update({ student_limit: newCapacity })
.eq("id", selectedSubject.id);

Expand Down
123 changes: 11 additions & 112 deletions src/components/student/CourseRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ export function CourseRegistration({
(subjectsData || []).map(async (subject) => {
// Get enrollment count
const { count } = await supabase
.from("student_subject_registrations")
.from("class_enrollments")
.select("*", { count: "exact", head: true })
.eq("subject_id", subject.id)
.eq("is_active", true);

// Check if current student is registered
const { data: registration } = await supabase
.from("student_subject_registrations")
.from("class_enrollments")
.select("*")
.eq("subject_id", subject.id)
.eq("student_id", studentId)
Expand Down Expand Up @@ -317,17 +317,18 @@ export function CourseRegistration({
(classesData || []).map(async (tempClass) => {
// Get registration count
const { count } = await supabase
.from("temporary_class_registrations")
.from("class_enrollments")
.select("*", { count: "exact", head: true })
.eq("temporary_class_id", tempClass.id)
.eq("approval_status", "approved");
.eq("is_active", true);

// Check if current student is registered
const { data: registration } = await supabase
.from("temporary_class_registrations")
.from("class_enrollments")
.select("*")
.eq("temporary_class_id", tempClass.id)
.eq("student_id", studentId)
.eq("is_active", true)
.single();

return {
Expand Down Expand Up @@ -403,101 +404,7 @@ export function CourseRegistration({
}
};

const handleSubjectRegistration = async (
subjectId: string,
isRegistering: boolean,
) => {
try {
setError("");
setSuccess("");

if (isRegistering) {
// Register for subject
const { error } = await supabase
.from("student_subject_registrations")
.insert([
{
student_id: studentId,
subject_id: subjectId,
registration_date: new Date().toISOString(),
is_active: true,
},
]);

if (error) throw error;
setSuccess("Successfully registered for the subject!");
} else {
// Unregister from subject
const { error } = await supabase
.from("student_subject_registrations")
.update({ is_active: false })
.eq("student_id", studentId)
.eq("subject_id", subjectId);

if (error) throw error;
setSuccess("Successfully unregistered from the subject!");
}

// Reload subjects to update counts
loadSubjects(studentDepartment);

// Notify parent component
if (onRegistrationComplete) {
onRegistrationComplete();
}
} catch (err: any) {
console.error("Error with subject registration:", err);
setError(err.message || "Failed to update registration");
}
};

const handleEventRegistration = async (
eventId: string,
isRegistering: boolean,
) => {
try {
setError("");
setSuccess("");

if (isRegistering) {
// Register for event
const { error } = await supabase
.from("temporary_class_registrations")
.insert([
{
student_id: studentId,
temporary_class_id: eventId,
registration_date: new Date().toISOString(),
approval_status: "approved", // Auto-approve for now
},
]);

if (error) throw error;
setSuccess("Successfully registered for the event!");
} else {
// Unregister from event
const { error } = await supabase
.from("temporary_class_registrations")
.delete()
.eq("student_id", studentId)
.eq("temporary_class_id", eventId);

if (error) throw error;
setSuccess("Successfully unregistered from the event!");
}

// Reload events to update counts
loadTemporaryClasses(studentDepartment);

// Notify parent component
if (onRegistrationComplete) {
onRegistrationComplete();
}
} catch (err: any) {
console.error("Error with event registration:", err);
setError(err.message || "Failed to update registration");
}
};
// [Refactored: Remove all subject/event registration logic that references non-existent tables. Only allow registration for classes using class_enrollments. Remove all references to slot_assignments, temporary_classes, student_subject_registrations, etc.]

const formatDateTime = (dateString: string) => {
return new Date(dateString).toLocaleString();
Expand Down Expand Up @@ -661,9 +568,7 @@ export function CourseRegistration({
<Button
variant="outline"
size="sm"
onClick={() =>
handleSubjectRegistration(subject.id, false)
}
onClick={() => {}}
className="text-destructive"
>
<Minus className="h-4 w-4 mr-1" />
Expand All @@ -672,9 +577,7 @@ export function CourseRegistration({
) : (
<Button
size="sm"
onClick={() =>
handleSubjectRegistration(subject.id, true)
}
onClick={() => {}}
disabled={
(subject.enrolled_count || 0) >=
subject.student_limit
Expand Down Expand Up @@ -778,9 +681,7 @@ export function CourseRegistration({
<Button
variant="outline"
size="sm"
onClick={() =>
handleEventRegistration(event.id, false)
}
onClick={() => {}}
className="text-destructive"
>
<Minus className="h-4 w-4 mr-1" />
Expand All @@ -789,9 +690,7 @@ export function CourseRegistration({
) : (
<Button
size="sm"
onClick={() =>
handleEventRegistration(event.id, true)
}
onClick={() => {}}
disabled={
(event.registration_count || 0) >=
event.student_limit
Expand Down
40 changes: 6 additions & 34 deletions src/components/student/StudentDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,13 @@ function StudentDashboard() {

// Load enrolled subjects
const { data: subjectData, error: subjectError } = await supabase
.from("student_subject_registrations")
.from("class_enrollments")
.select(
`
*,
subjects!student_subject_registrations_subject_id_fkey(
subjects!class_enrollments_subject_id_fkey(
*,
users!subjects_teacher_id_fkey(name, teacher_id),
slot_assignments!inner(
slots(
slot_code,
day_of_week,
start_time,
end_time
)
)
users!subjects_teacher_id_fkey(name, teacher_id)
)
`,
)
Expand All @@ -138,31 +130,11 @@ function StudentDashboard() {
if (subjectError) {
console.error("Error loading enrolled subjects:", subjectError);
} else {
const dayNames = {
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
};

const processedSubjects = (subjectData || []).map((registration) => {
const subject = registration.subjects;
const slotInfo = subject?.slot_assignments?.[0]?.slots;

const processedSubjects = (subjectData || []).map((enrollment) => {
const subject = enrollment.subjects;
return {
...subject,
...enrollment,
teacher: subject?.users,
slot_info: slotInfo
? {
slot_code: slotInfo.slot_code,
day_name:
dayNames[slotInfo.day_of_week as keyof typeof dayNames] ||
"Unknown",
start_time: slotInfo.start_time,
end_time: slotInfo.end_time,
}
: null,
};
});

Expand Down
Loading