Merge remote-tracking branch 'origin/develop' into feature/ExamGenRework
This commit is contained in:
@@ -11,7 +11,6 @@ import Reading from "@/exams/Reading";
|
||||
import Selection from "@/exams/Selection";
|
||||
import Speaking from "@/exams/Speaking";
|
||||
import Writing from "@/exams/Writing";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import { Exam, LevelExam, UserSolution, Variant } from "@/interfaces/exam";
|
||||
import { Stat, User } from "@/interfaces/user";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
@@ -21,12 +20,7 @@ import axios from "axios";
|
||||
import { useRouter } from "next/router";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import useSessions from "@/hooks/useSessions";
|
||||
import ShortUniqueId from "short-unique-id";
|
||||
import clsx from "clsx";
|
||||
import useGradingSystem from "@/hooks/useGrading";
|
||||
import { Assignment } from "@/interfaces/results";
|
||||
import { mapBy } from "@/utils";
|
||||
|
||||
interface Props {
|
||||
page: "exams" | "exercises";
|
||||
@@ -214,7 +208,6 @@ export default function ExamPage({ page, user, destination = "/exam", hideSideba
|
||||
}, [setModuleIndex, showSolutions]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(selectedModules)
|
||||
if (selectedModules.length > 0 && exams.length > 0 && moduleIndex < selectedModules.length) {
|
||||
const nextExam = exams[moduleIndex];
|
||||
|
||||
@@ -264,6 +257,7 @@ export default function ExamPage({ page, user, destination = "/exam", hideSideba
|
||||
isDisabled: solution.isDisabled,
|
||||
shuffleMaps: solution.shuffleMaps,
|
||||
...(assignment ? { assignment: assignment.id } : {}),
|
||||
isPractice: solution.isPractice
|
||||
}));
|
||||
|
||||
axios
|
||||
@@ -422,7 +416,7 @@ export default function ExamPage({ page, user, destination = "/exam", hideSideba
|
||||
},
|
||||
};
|
||||
|
||||
userSolutions.forEach((x) => {
|
||||
userSolutions.filter(x => !x.isPractice).forEach((x) => {
|
||||
const examModule =
|
||||
x.module || (x.type === "writing" ? "writing" : x.type === "speaking" || x.type === "interactiveSpeaking" ? "speaking" : undefined);
|
||||
|
||||
|
||||
@@ -1,44 +1,45 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import {User} from "@/interfaces/user";
|
||||
import {toast, ToastContainer} from "react-toastify";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import axios from "axios";
|
||||
import {FormEvent, useEffect, useState} from "react";
|
||||
import { FormEvent, useEffect, useMemo, useState } from "react";
|
||||
import Head from "next/head";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import {Divider} from "primereact/divider";
|
||||
import { Divider } from "primereact/divider";
|
||||
import Button from "@/components/Low/Button";
|
||||
import {BsArrowRepeat, BsCheck} from "react-icons/bs";
|
||||
import { BsArrowRepeat, BsCheck } from "react-icons/bs";
|
||||
import Link from "next/link";
|
||||
import Input from "@/components/Low/Input";
|
||||
import clsx from "clsx";
|
||||
import {useRouter} from "next/router";
|
||||
import { useRouter } from "next/router";
|
||||
import EmailVerification from "./(auth)/EmailVerification";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { redirect } from "@/utils";
|
||||
|
||||
const EMAIL_REGEX = new RegExp(/^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$/g);
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res, query}) => {
|
||||
export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => {
|
||||
const destination = !query.destination ? "/" : Buffer.from(query.destination as string, 'base64').toString()
|
||||
const user = await requestUser(req, res)
|
||||
if (user) return redirect(destination)
|
||||
|
||||
return {
|
||||
props: {user: null, destination},
|
||||
props: { user: null, destination },
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Login({ destination }: { destination: string }) {
|
||||
export default function Login({ destination = "/" }: { destination?: string }) {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [rememberPassword, setRememberPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
const isOfficialExamLogin = useMemo(() => destination.startsWith("/official-exam"), [destination])
|
||||
|
||||
const {user, mutateUser} = useUser({
|
||||
const { user, mutateUser } = useUser({
|
||||
redirectTo: destination,
|
||||
redirectIfFound: true,
|
||||
});
|
||||
@@ -56,10 +57,10 @@ export default function Login({ destination }: { destination: string }) {
|
||||
}
|
||||
|
||||
axios
|
||||
.post<{ok: boolean}>("/api/reset", {email})
|
||||
.post<{ ok: boolean }>("/api/reset", { email })
|
||||
.then((response) => {
|
||||
if (response.data.ok) {
|
||||
toast.success("You should receive an e-mail to reset your password!", {toastId: "forgot-success"});
|
||||
toast.success("You should receive an e-mail to reset your password!", { toastId: "forgot-success" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ export default function Login({ destination }: { destination: string }) {
|
||||
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.post<User>("/api/login", {email, password})
|
||||
.post<User>("/api/login", { email, password })
|
||||
.then((response) => {
|
||||
toast.success("You have been logged in!", {
|
||||
toastId: "login-successful",
|
||||
@@ -92,7 +93,7 @@ export default function Login({ destination }: { destination: string }) {
|
||||
toastId: "wrong-credentials",
|
||||
});
|
||||
} else {
|
||||
toast.error("Something went wrong!", {toastId: "server-error"});
|
||||
toast.error("Something went wrong!", { toastId: "server-error" });
|
||||
}
|
||||
setIsLoading(false);
|
||||
})
|
||||
@@ -110,14 +111,25 @@ export default function Login({ destination }: { destination: string }) {
|
||||
<main className="flex h-[100vh] w-full bg-white text-black">
|
||||
<ToastContainer />
|
||||
<section className="relative hidden h-full w-fit min-w-fit lg:flex">
|
||||
{/* <div className="bg-mti-rose-light absolute z-10 h-full w-full bg-opacity-50" /> */}
|
||||
<img src="/red-stock-photo.jpg" alt="People smiling looking at a tablet" className="aspect-auto h-full" />
|
||||
{!isOfficialExamLogin && (
|
||||
<img src="/red-stock-photo.jpg" alt="People smiling looking at a tablet" className="aspect-auto h-full" />
|
||||
)}
|
||||
{isOfficialExamLogin && (
|
||||
<img src="/purple-stock-photo.png" alt="People smiling looking at a tablet" className="aspect-auto h-full" />
|
||||
)}
|
||||
</section>
|
||||
<section className="flex h-full w-full flex-col items-center justify-center gap-2">
|
||||
<div className={clsx("flex flex-col items-center", !user && "mb-4")}>
|
||||
<img src="/logo_title.png" alt="EnCoach's Logo" className="w-36 lg:w-56" />
|
||||
<h1 className="text-2xl font-bold lg:text-4xl">Login to your account</h1>
|
||||
<p className="text-mti-gray-cool self-start text-sm font-normal lg:text-base">with your registered Email Address</p>
|
||||
{!isOfficialExamLogin && (
|
||||
<>
|
||||
<h1 className="text-2xl font-bold lg:text-4xl">Login to your account</h1>
|
||||
<p className="text-mti-gray-cool self-start text-sm font-normal lg:text-base">with your registered Email Address</p>
|
||||
</>
|
||||
)}
|
||||
{isOfficialExamLogin && (
|
||||
<h1 className="text-2xl font-bold lg:text-4xl">Welcome to the Official Exams Portal</h1>
|
||||
)}
|
||||
</div>
|
||||
<Divider className="max-w-xs lg:max-w-md" />
|
||||
{!user && (
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import Head from "next/head";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {Stat, User} from "@/interfaces/user";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { Stat, User } from "@/interfaces/user";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import useFilterRecordsByUser from "@/hooks/useFilterRecordsByUser";
|
||||
import {groupByDate} from "@/utils/stats";
|
||||
import { groupByDate } from "@/utils/stats";
|
||||
import moment from "moment";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {ToastContainer} from "react-toastify";
|
||||
import { ToastContainer } from "react-toastify";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import clsx from "clsx";
|
||||
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||
import {uuidv4} from "@firebase/util";
|
||||
import {usePDFDownload} from "@/hooks/usePDFDownload";
|
||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||
import { uuidv4 } from "@firebase/util";
|
||||
import { usePDFDownload } from "@/hooks/usePDFDownload";
|
||||
import useRecordStore from "@/stores/recordStore";
|
||||
import StatsGridItem from "@/components/Medium/StatGridItem";
|
||||
import RecordFilter from "@/components/Medium/RecordFilter";
|
||||
import {useRouter} from "next/router";
|
||||
import { useRouter } from "next/router";
|
||||
import useTrainingContentStore from "@/stores/trainingContentStore";
|
||||
import {Assignment} from "@/interfaces/results";
|
||||
import {getEntitiesUsers, getUsers} from "@/utils/users.be";
|
||||
import {getAssignments, getEntitiesAssignments} from "@/utils/assignments.be";
|
||||
import { Assignment } from "@/interfaces/results";
|
||||
import { getEntitiesUsers, getUsers } from "@/utils/users.be";
|
||||
import { getAssignments, getEntitiesAssignments } from "@/utils/assignments.be";
|
||||
import useGradingSystem from "@/hooks/useGrading";
|
||||
import { mapBy, redirect, serialize } from "@/utils";
|
||||
import { getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
@@ -33,7 +33,7 @@ import { EntityWithRoles } from "@/interfaces/entity";
|
||||
import CardList from "@/components/High/CardList";
|
||||
import { requestUser } from "@/utils/api";
|
||||
|
||||
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")
|
||||
|
||||
@@ -43,12 +43,10 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
|
||||
const entities = await getEntitiesWithRoles(checkAccess(user, ["admin", "developer"]) ? undefined : entityIDs)
|
||||
const users = await (checkAccess(user, ["admin", "developer"]) ? getUsers() : getEntitiesUsers(mapBy(entities, 'id')))
|
||||
const groups = await (checkAccess(user, ["admin", "developer"]) ? getGroups() : getGroupsByEntities(mapBy(entities, 'id')))
|
||||
const assignments = await (checkAccess(user, ["admin", "developer"]) ? getAssignments() : getEntitiesAssignments(mapBy(entities, 'id')))
|
||||
const gradingSystems = await Promise.all(entityIDs.map(getGradingSystemByEntity))
|
||||
|
||||
return {
|
||||
props: serialize({user, users, assignments, entities, gradingSystems}),
|
||||
props: serialize({ user, users, assignments, entities }),
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
@@ -58,13 +56,12 @@ interface Props {
|
||||
user: User;
|
||||
users: User[];
|
||||
assignments: Assignment[];
|
||||
gradingSystems: Grading[]
|
||||
entities: EntityWithRoles[]
|
||||
}
|
||||
|
||||
const MAX_TRAINING_EXAMS = 10;
|
||||
|
||||
export default function History({user, users, assignments, entities, gradingSystems}: Props) {
|
||||
export default function History({ user, users, assignments, entities }: Props) {
|
||||
const router = useRouter();
|
||||
const [statsUserId, setStatsUserId, training, setTraining] = useRecordStore((state) => [
|
||||
state.selectedUser,
|
||||
@@ -75,8 +72,8 @@ export default function History({user, users, assignments, entities, gradingSyst
|
||||
|
||||
const [filter, setFilter] = useState<Filter>();
|
||||
|
||||
const {data: stats, isLoading: isStatsLoading} = useFilterRecordsByUser<Stat[]>(statsUserId || user?.id);
|
||||
const {gradingSystem} = useGradingSystem();
|
||||
const { data: stats, isLoading: isStatsLoading } = useFilterRecordsByUser<Stat[]>(statsUserId || user?.id);
|
||||
const { gradingSystem } = useGradingSystem();
|
||||
|
||||
const setExams = useExamStore((state) => state.setExams);
|
||||
const setShowSolutions = useExamStore((state) => state.setShowSolutions);
|
||||
@@ -113,12 +110,12 @@ export default function History({user, users, assignments, entities, gradingSyst
|
||||
};
|
||||
}, [router.events, setTraining]);
|
||||
|
||||
const filterStatsByDate = (stats: {[key: string]: Stat[]}) => {
|
||||
const filterStatsByDate = (stats: { [key: string]: Stat[] }) => {
|
||||
if (filter && filter !== "assignments") {
|
||||
const filterDate = moment()
|
||||
.subtract({[filter as string]: 1})
|
||||
.subtract({ [filter as string]: 1 })
|
||||
.format("x");
|
||||
const filteredStats: {[key: string]: Stat[]} = {};
|
||||
const filteredStats: { [key: string]: Stat[] } = {};
|
||||
|
||||
Object.keys(stats).forEach((timestamp) => {
|
||||
if (timestamp >= filterDate) filteredStats[timestamp] = stats[timestamp];
|
||||
@@ -127,7 +124,7 @@ export default function History({user, users, assignments, entities, gradingSyst
|
||||
}
|
||||
|
||||
if (filter && filter === "assignments") {
|
||||
const filteredStats: {[key: string]: Stat[]} = {};
|
||||
const filteredStats: { [key: string]: Stat[] } = {};
|
||||
|
||||
Object.keys(stats).forEach((timestamp) => {
|
||||
if (stats[timestamp].map((s) => s.assignment === undefined).includes(false))
|
||||
@@ -140,21 +137,21 @@ export default function History({user, users, assignments, entities, gradingSyst
|
||||
return stats;
|
||||
};
|
||||
|
||||
const handleTrainingContentSubmission = () => {
|
||||
if (groupedStats) {
|
||||
const groupedStatsByDate = filterStatsByDate(groupedStats);
|
||||
const allStats = Object.keys(groupedStatsByDate);
|
||||
const selectedStats = selectedTrainingExams.reduce<Record<string, Stat[]>>((accumulator, moduleAndTimestamp) => {
|
||||
const timestamp = moduleAndTimestamp.split("-")[1];
|
||||
if (allStats.includes(timestamp) && !accumulator.hasOwnProperty(timestamp)) {
|
||||
accumulator[timestamp] = groupedStatsByDate[timestamp];
|
||||
}
|
||||
return accumulator;
|
||||
}, {});
|
||||
setTrainingStats(Object.values(selectedStats).flat());
|
||||
router.push("/training");
|
||||
}
|
||||
};
|
||||
const handleTrainingContentSubmission = () => {
|
||||
if (groupedStats) {
|
||||
const groupedStatsByDate = filterStatsByDate(groupedStats);
|
||||
const allStats = Object.keys(groupedStatsByDate);
|
||||
const selectedStats = selectedTrainingExams.reduce<Record<string, Stat[]>>((accumulator, moduleAndTimestamp) => {
|
||||
const timestamp = moduleAndTimestamp.split("-")[1];
|
||||
if (allStats.includes(timestamp) && !accumulator.hasOwnProperty(timestamp)) {
|
||||
accumulator[timestamp] = groupedStatsByDate[timestamp];
|
||||
}
|
||||
return accumulator;
|
||||
}, {});
|
||||
setTrainingStats(Object.values(selectedStats).flat());
|
||||
router.push("/training");
|
||||
}
|
||||
};
|
||||
|
||||
const filteredStats = useMemo(() =>
|
||||
Object.keys(filterStatsByDate(groupedStats))
|
||||
@@ -203,7 +200,7 @@ const handleTrainingContentSubmission = () => {
|
||||
<ToastContainer />
|
||||
{user && (
|
||||
<Layout user={user}>
|
||||
<RecordFilter user={user} users={users} entities={entities} filterState={{filter: filter, setFilter: setFilter}}>
|
||||
<RecordFilter user={user} users={users} entities={entities} filterState={{ filter: filter, setFilter: setFilter }}>
|
||||
{training && (
|
||||
<div className="flex flex-row">
|
||||
<div className="font-semibold text-2xl mr-4">
|
||||
|
||||
Reference in New Issue
Block a user