|
|
|
|
@@ -5,38 +5,38 @@ import ProgressBar from "@/components/Low/ProgressBar";
|
|
|
|
|
import InviteWithUserCard from "@/components/Medium/InviteWithUserCard";
|
|
|
|
|
import ModuleBadge from "@/components/ModuleBadge";
|
|
|
|
|
import ProfileSummary from "@/components/ProfileSummary";
|
|
|
|
|
import {Session} from "@/hooks/useSessions";
|
|
|
|
|
import {Grading} from "@/interfaces";
|
|
|
|
|
import {EntityWithRoles} from "@/interfaces/entity";
|
|
|
|
|
import {Exam} from "@/interfaces/exam";
|
|
|
|
|
import { Session } from "@/hooks/useSessions";
|
|
|
|
|
import { Grading } from "@/interfaces";
|
|
|
|
|
import { EntityWithRoles } from "@/interfaces/entity";
|
|
|
|
|
import { Exam } from "@/interfaces/exam";
|
|
|
|
|
import { InviteWithEntity } from "@/interfaces/invite";
|
|
|
|
|
import {Assignment} from "@/interfaces/results";
|
|
|
|
|
import {Stat, User} from "@/interfaces/user";
|
|
|
|
|
import {sessionOptions} from "@/lib/session";
|
|
|
|
|
import { Assignment } from "@/interfaces/results";
|
|
|
|
|
import { Stat, User } from "@/interfaces/user";
|
|
|
|
|
import { sessionOptions } from "@/lib/session";
|
|
|
|
|
import useExamStore from "@/stores/exam";
|
|
|
|
|
import {findBy, mapBy, redirect, serialize} from "@/utils";
|
|
|
|
|
import { findBy, mapBy, redirect, serialize } from "@/utils";
|
|
|
|
|
import { requestUser } from "@/utils/api";
|
|
|
|
|
import {activeAssignmentFilter} from "@/utils/assignments";
|
|
|
|
|
import {getAssignmentsByAssignee} from "@/utils/assignments.be";
|
|
|
|
|
import {getEntitiesWithRoles, getEntityWithRoles} from "@/utils/entities.be";
|
|
|
|
|
import {getExamsByIds} from "@/utils/exams.be";
|
|
|
|
|
import {getGradingSystemByEntity} from "@/utils/grading.be";
|
|
|
|
|
import {convertInvitersToEntity, getInvitesByInvitee} from "@/utils/invites.be";
|
|
|
|
|
import {countExamModules, countFullExams, MODULE_ARRAY, sortByModule, sortByModuleName} from "@/utils/moduleUtils";
|
|
|
|
|
import {checkAccess} from "@/utils/permissions";
|
|
|
|
|
import {getGradingLabel} from "@/utils/score";
|
|
|
|
|
import {getSessionsByUser} from "@/utils/sessions.be";
|
|
|
|
|
import {averageScore} from "@/utils/stats";
|
|
|
|
|
import {getStatsByUser} from "@/utils/stats.be";
|
|
|
|
|
import { activeAssignmentFilter } from "@/utils/assignments";
|
|
|
|
|
import { getAssignmentsByAssignee } from "@/utils/assignments.be";
|
|
|
|
|
import { getEntitiesWithRoles, getEntityWithRoles } from "@/utils/entities.be";
|
|
|
|
|
import { getExamsByIds } from "@/utils/exams.be";
|
|
|
|
|
import { getGradingSystemByEntity } from "@/utils/grading.be";
|
|
|
|
|
import { convertInvitersToEntity, getInvitesByInvitee } from "@/utils/invites.be";
|
|
|
|
|
import { countExamModules, countFullExams, MODULE_ARRAY, sortByModule, sortByModuleName } from "@/utils/moduleUtils";
|
|
|
|
|
import { checkAccess } from "@/utils/permissions";
|
|
|
|
|
import { getGradingLabel } from "@/utils/score";
|
|
|
|
|
import { getSessionsByUser } from "@/utils/sessions.be";
|
|
|
|
|
import { averageScore } from "@/utils/stats";
|
|
|
|
|
import { getStatsByUser } from "@/utils/stats.be";
|
|
|
|
|
import clsx from "clsx";
|
|
|
|
|
import {withIronSessionSsr} from "iron-session/next";
|
|
|
|
|
import {capitalize, uniqBy} from "lodash";
|
|
|
|
|
import { withIronSessionSsr } from "iron-session/next";
|
|
|
|
|
import { capitalize, uniqBy } from "lodash";
|
|
|
|
|
import moment from "moment";
|
|
|
|
|
import Head from "next/head";
|
|
|
|
|
import {useRouter} from "next/router";
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import {BsBook, BsClipboard, BsFileEarmarkText, BsHeadphones, BsMegaphone, BsPen, BsPencil, BsStar} from "react-icons/bs";
|
|
|
|
|
import {ToastContainer} from "react-toastify";
|
|
|
|
|
import { BsBook, BsClipboard, BsFileEarmarkText, BsHeadphones, BsMegaphone, BsPen, BsPencil, BsStar } from "react-icons/bs";
|
|
|
|
|
import { ToastContainer } from "react-toastify";
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
user: User;
|
|
|
|
|
@@ -49,9 +49,9 @@ interface Props {
|
|
|
|
|
grading: Grading;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
|
|
|
|
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
|
|
|
|
const user = await requestUser(req, res)
|
|
|
|
|
if (!user) return redirect("/login")
|
|
|
|
|
if (!user || !user.isVerified) return redirect("/login")
|
|
|
|
|
|
|
|
|
|
if (!checkAccess(user, ["admin", "developer", "student"]))
|
|
|
|
|
return redirect("/")
|
|
|
|
|
@@ -59,7 +59,7 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
|
|
|
|
const entityIDS = mapBy(user.entities, "id") || [];
|
|
|
|
|
|
|
|
|
|
const entities = await getEntitiesWithRoles(entityIDS);
|
|
|
|
|
const assignments = await getAssignmentsByAssignee(user.id, {archived: {$ne: true}});
|
|
|
|
|
const assignments = await getAssignmentsByAssignee(user.id, { archived: { $ne: true } });
|
|
|
|
|
const stats = await getStatsByUser(user.id);
|
|
|
|
|
const sessions = await getSessionsByUser(user.id, 10);
|
|
|
|
|
const invites = await getInvitesByInvitee(user.id);
|
|
|
|
|
@@ -69,16 +69,16 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
|
|
|
|
|
|
|
|
|
const examIDs = uniqBy(
|
|
|
|
|
assignments.flatMap((a) =>
|
|
|
|
|
a.exams.filter((e) => e.assignee === user.id).map((e) => ({module: e.module, id: e.id, key: `${e.module}_${e.id}`})),
|
|
|
|
|
a.exams.filter((e) => e.assignee === user.id).map((e) => ({ module: e.module, id: e.id, key: `${e.module}_${e.id}` })),
|
|
|
|
|
),
|
|
|
|
|
"key",
|
|
|
|
|
);
|
|
|
|
|
const exams = await getExamsByIds(examIDs);
|
|
|
|
|
|
|
|
|
|
return {props: serialize({user, entities, assignments, stats, exams, sessions, invites: formattedInvites, grading})};
|
|
|
|
|
return { props: serialize({ user, entities, assignments, stats, exams, sessions, invites: formattedInvites, grading }) };
|
|
|
|
|
}, sessionOptions);
|
|
|
|
|
|
|
|
|
|
export default function Dashboard({user, entities, assignments, stats, invites, grading, sessions, exams}: Props) {
|
|
|
|
|
export default function Dashboard({ user, entities, assignments, stats, invites, grading, sessions, exams }: Props) {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
const dispatch = useExamStore((state) => state.dispatch);
|
|
|
|
|
@@ -90,11 +90,13 @@ export default function Dashboard({user, entities, assignments, stats, invites,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (assignmentExams.every((x) => !!x)) {
|
|
|
|
|
dispatch({type: "INIT_EXAM", payload: {
|
|
|
|
|
exams: assignmentExams.sort(sortByModule),
|
|
|
|
|
modules: mapBy(assignmentExams.sort(sortByModule), 'module'),
|
|
|
|
|
assignment
|
|
|
|
|
}})
|
|
|
|
|
dispatch({
|
|
|
|
|
type: "INIT_EXAM", payload: {
|
|
|
|
|
exams: assignmentExams.sort(sortByModule),
|
|
|
|
|
modules: mapBy(assignmentExams.sort(sortByModule), 'module'),
|
|
|
|
|
assignment
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.push("/exam");
|
|
|
|
|
}
|
|
|
|
|
|