All files / src/app/teacher-page/page/view-class ViewClassPage.jsx

90% Statements 18/20
75% Branches 6/8
100% Functions 4/4
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113                                        1x 5x 5x 5x   5x   5x 5x                                                                                 5x                       5x 5x 5x 5x 5x     5x 4x   4x                                          
import React, { useEffect, useMemo } from "react";
import TabsComponent from "@/utils/components/TabsComponent";
import Gradebook from "@/app/teacher-page/page/gradebook/Gradebook";
import AssignmentsTable from "@/app/teacher-page/page/assignments/AssignmentsPage";
import ClassRoster from "@/app/teacher-page/page/class-roster/ClassRoster";
import ClassDetails from "@/app/teacher-page/page/class-details/ClassDetails";
import AppBar from "@mui/material/AppBar";
import Box from "@mui/material/Box";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";
import { _fetchSpecificClassByCode } from "@/store/slices/teacher/TeacherSpecificClass";
import { _teacherFetchAllAssignments } from "@/store/slices/teacher/TeacherAssignments";
import { fetchTeacherMadeAssignmentQuota } from "@/store/slices/teacher/TeacherFeatureFlags";
import BasicBreadcrumbs from "@/utils/components/breadcrumbs/basic-breadcrumbs/BasicBreadcrumbs";
import getCurrentSemesterYear from "@/utils/helpers/getCurrentSemesterYear";
import PageError from "@/utils/components/page-error/PageError";
import SimpleLoading from "@/utils/components/SimpleLoading";
 
const Main = () => {
    const { specificClassData, hasErrors, isLoading } = useSelector((state) => state.TeacherSpecificClass);
    const { currentYear } = getCurrentSemesterYear();
    const { classCode } = useParams();
 
    const dispatch = useDispatch();
 
    const tabContents = useMemo(
        () => [
            {
                id: "Gradebook",
                label: "Gradebook",
                component: (
                    <Box sx={{ mt: 5, mb: 10 }}>
                        <Gradebook />
                    </Box>
                ),
            },
            {
                id: "Assignments",
                label: "Assignments",
                component: (
                    <Box sx={{ mt: 2, mb: 4 }}>
                        <AssignmentsTable />
                    </Box>
                ),
            },
            {
                id: "Class Roster",
                label: "Class Roster",
                component: (
                    <Box sx={{ mt: 5, mb: 10 }}>
                        <ClassRoster />
                    </Box>
                ),
            },
            {
                id: "Class Details",
                label: "Class Details",
                component: (
                    <Box sx={{ mt: 5, mb: 10 }}>
                        <ClassDetails />
                    </Box>
                ),
            },
        ],
        []
    );
 
    const breadcrumb = [
        {
            name: "Classes",
            isLink: true,
            path: "/teacher/classes",
        },
        {
            name: specificClassData?.title,
            isLink: false,
        },
    ];
 
    useEffect(() => {
        Iif (!classCode) return;
        dispatch(_fetchSpecificClassByCode(classCode));
        dispatch(fetchTeacherMadeAssignmentQuota());
        dispatch(_teacherFetchAllAssignments(classCode));
    }, [dispatch, classCode]);
 
    if (isLoading) return <SimpleLoading showLoading={true} />;
    Iif (hasErrors) return <PageError />;
 
    return (
        <React.Fragment>
            <AppBar position="relative" color="primary">
                {specificClassData && (
                    <Toolbar sx={{ display: "flex", justifyContent: "space-between" }}>
                        <Typography variant="h6">
                            {`${currentYear}-${specificClassData.semester} : ${specificClassData.title} (${specificClassData.section})`}
                        </Typography>
                        <Typography variant="h6">Class code: {specificClassData.class_code}</Typography>
                    </Toolbar>
                )}
            </AppBar>
            <BasicBreadcrumbs links={breadcrumb} />
            <Box sx={{ padding: "2%" }}>
                <TabsComponent tabContents={tabContents} />
            </Box>
        </React.Fragment>
    );
};
 
export default Main;