import Button from "@/components/Low/Button"; import ProgressBar from "@/components/Low/ProgressBar"; import InviteCard from "@/components/Medium/InviteCard"; import ProfileSummary from "@/components/ProfileSummary"; import useAssignments from "@/hooks/useAssignments"; import useGradingSystem from "@/hooks/useGrading"; import useInvites from "@/hooks/useInvites"; import useFilterRecordsByUser from "@/hooks/useFilterRecordsByUser"; import useUsers, { userHashStudent, userHashTeacher, userHashCorporate } from "@/hooks/useUsers"; import { Invite } from "@/interfaces/invite"; import { Assignment } from "@/interfaces/results"; import { CorporateUser, MasterCorporateUser, Stat, User } from "@/interfaces/user"; import useExamStore from "@/stores/exam"; import { getExamById } from "@/utils/exams"; import { getUserCorporate } from "@/utils/groups"; import { countExamModules, countFullExams, MODULE_ARRAY, sortByModule, sortByModuleName } from "@/utils/moduleUtils"; import { getGradingLabel, getLevelLabel, getLevelScore } from "@/utils/score"; import { averageScore, groupBySession } from "@/utils/stats"; import { CreateOrderActions, CreateOrderData, OnApproveActions, OnApproveData, OrderResponseBody } from "@paypal/paypal-js"; import { PayPalButtons } from "@paypal/react-paypal-js"; import axios from "axios"; import clsx from "clsx"; import { capitalize } from "lodash"; import moment from "moment"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useMemo, useState } from "react"; import { BsArrowRepeat, BsBook, BsClipboard, BsFileEarmarkText, BsHeadphones, BsMegaphone, BsPen, BsPencil, BsStar } from "react-icons/bs"; import { toast } from "react-toastify"; import { activeAssignmentFilter } from "@/utils/assignments"; import ModuleBadge from "@/components/ModuleBadge"; import useSessions from "@/hooks/useSessions"; interface Props { user: User; linkedCorporate?: CorporateUser | MasterCorporateUser; } export default function StudentDashboard({ user, linkedCorporate }: Props) { const { sessions } = useSessions(user.id); const { data: stats } = useFilterRecordsByUser(user.id, !user?.id); const { assignments, isLoading: isAssignmentsLoading, reload: reloadAssignments } = useAssignments({ assignees: user?.id }); const { invites, isLoading: isInvitesLoading, reload: reloadInvites } = useInvites({ to: user.id }); const { users: teachers } = useUsers(userHashTeacher); const { users: corporates } = useUsers(userHashCorporate); const users = useMemo(() => [...teachers, ...corporates], [teachers, corporates]); const router = useRouter(); const dispatch = useExamStore((state) => state.dispatch); const startAssignment = (assignment: Assignment) => { const examPromises = assignment.exams.filter((e) => e.assignee === user.id).map((e) => getExamById(e.module, e.id)); Promise.all(examPromises).then((exams) => { if (exams.every((x) => !!x)) { dispatch({ type: "INIT_EXAM", payload: { exams: exams.map((x) => x!).sort(sortByModule), modules: exams .map((x) => x!) .sort(sortByModule) .map((x) => x!.module), assignment } }) router.push("/exam"); } }); }; const studentAssignments = assignments.filter(activeAssignmentFilter); return ( <> {linkedCorporate && (
Linked to: {linkedCorporate?.corporateInformation?.companyInformation.name || linkedCorporate.name}
)} , value: countFullExams(stats), label: "Exams", tooltip: "Number of all conducted completed exams", }, { icon: , value: countExamModules(stats), label: "Modules", tooltip: "Number of all exam modules performed including Level Test", }, { icon: , value: `${stats.length > 0 ? averageScore(stats) : 0}%`, label: "Average Score", tooltip: "Average success rate for questions responded", }, ]} /> {/* Bio */}
Bio {user.bio || "Your bio will appear here, you can change it by clicking on your name in the top right corner."}
{/* Assignments */}
Assignments
{studentAssignments.length === 0 && "Assignments will appear here. It seems that for now there are no assignments for you."} {studentAssignments .sort((a, b) => moment(a.startDate).diff(b.startDate)) .map((assignment) => (
r.user).includes(user.id) && "border-mti-green-light", )} key={assignment.id}>

{assignment.name}

{moment(assignment.startDate).format("DD/MM/YY, HH:mm")} - {moment(assignment.endDate).format("DD/MM/YY, HH:mm")}
{assignment.exams .filter((e) => e.assignee === user.id) .map((e) => e.module) .sort(sortByModuleName) .map((module) => ( ))}
{!assignment.results.map((r) => r.user).includes(user.id) && ( <>
x.assignment?.id === assignment.id).length > 0 && "tooltip", )}>
)} {assignment.results.map((r) => r.user).includes(user.id) && ( )}
))}
{/* Invites */} {invites.length > 0 && (
Invites
{invites.map((invite) => ( ))}
)} {/* Score History */}
Score History
{MODULE_ARRAY.map((module) => { const desiredLevel = user.desiredLevels[module] || 9; const level = user.levels[module] || 0; return (
{module === "reading" && } {module === "listening" && } {module === "writing" && } {module === "speaking" && } {module === "level" && }
{capitalize(module)} {module !== "level" && `Level ${level} / Level 9 (Desired Level: ${desiredLevel})`}
); })}
); }