Updated it to work with the new canges
This commit is contained in:
@@ -357,7 +357,7 @@ export default function ExamPage({page}: Props) {
|
|||||||
exercise,
|
exercise,
|
||||||
solutions.find((x) => x.exercise === exercise.id)!,
|
solutions.find((x) => x.exercise === exercise.id)!,
|
||||||
evaluationID,
|
evaluationID,
|
||||||
index === 0 ? 1 : 2,
|
index + 1,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,42 +1,32 @@
|
|||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { withIronSessionSsr } from "iron-session/next";
|
import {withIronSessionSsr} from "iron-session/next";
|
||||||
import { sessionOptions } from "@/lib/session";
|
import {sessionOptions} from "@/lib/session";
|
||||||
import { Stat, User } from "@/interfaces/user";
|
import {Stat, User} from "@/interfaces/user";
|
||||||
import { useEffect, useState } from "react";
|
import {useEffect, useState} from "react";
|
||||||
import useStats from "@/hooks/useStats";
|
import useStats from "@/hooks/useStats";
|
||||||
import { convertToUserSolutions, groupByDate } from "@/utils/stats";
|
import {convertToUserSolutions, groupByDate} from "@/utils/stats";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import useUsers from "@/hooks/useUsers";
|
import useUsers from "@/hooks/useUsers";
|
||||||
import useExamStore from "@/stores/examStore";
|
import useExamStore from "@/stores/examStore";
|
||||||
import { Module } from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import { ToastContainer } from "react-toastify";
|
import {ToastContainer} from "react-toastify";
|
||||||
import { useRouter } from "next/router";
|
import {useRouter} from "next/router";
|
||||||
import { uniqBy } from "lodash";
|
import {uniqBy} from "lodash";
|
||||||
import { getExamById } from "@/utils/exams";
|
import {getExamById} from "@/utils/exams";
|
||||||
import { sortByModule } from "@/utils/moduleUtils";
|
import {sortByModule} from "@/utils/moduleUtils";
|
||||||
import Layout from "@/components/High/Layout";
|
import Layout from "@/components/High/Layout";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { calculateBandScore } from "@/utils/score";
|
import {calculateBandScore} from "@/utils/score";
|
||||||
import {
|
import {BsBook, BsClipboard, BsClock, BsHeadphones, BsMegaphone, BsPen, BsPersonDash, BsPersonFillX, BsXCircle} from "react-icons/bs";
|
||||||
BsBook,
|
|
||||||
BsClipboard,
|
|
||||||
BsClock,
|
|
||||||
BsHeadphones,
|
|
||||||
BsMegaphone,
|
|
||||||
BsPen,
|
|
||||||
BsPersonDash,
|
|
||||||
BsPersonFillX,
|
|
||||||
BsXCircle,
|
|
||||||
} from "react-icons/bs";
|
|
||||||
import Select from "@/components/Low/Select";
|
import Select from "@/components/Low/Select";
|
||||||
import useGroups from "@/hooks/useGroups";
|
import useGroups from "@/hooks/useGroups";
|
||||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||||
import useAssignments from "@/hooks/useAssignments";
|
import useAssignments from "@/hooks/useAssignments";
|
||||||
import { uuidv4 } from "@firebase/util";
|
import {uuidv4} from "@firebase/util";
|
||||||
import { usePDFDownload } from "@/hooks/usePDFDownload";
|
import {usePDFDownload} from "@/hooks/usePDFDownload";
|
||||||
import useRecordStore from "@/stores/recordStore";
|
import useRecordStore from "@/stores/recordStore";
|
||||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||||
const user = req.session.user;
|
const user = req.session.user;
|
||||||
|
|
||||||
if (!user || !user.isVerified) {
|
if (!user || !user.isVerified) {
|
||||||
@@ -58,7 +48,7 @@ export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { user: req.session.user },
|
props: {user: req.session.user},
|
||||||
};
|
};
|
||||||
}, sessionOptions);
|
}, sessionOptions);
|
||||||
|
|
||||||
@@ -67,21 +57,16 @@ const defaultSelectableCorporate = {
|
|||||||
label: "All",
|
label: "All",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function History({ user }: { user: User }) {
|
export default function History({user}: {user: User}) {
|
||||||
const [statsUserId, setStatsUserId] = useRecordStore((state) => [
|
const [statsUserId, setStatsUserId] = useRecordStore((state) => [state.selectedUser, state.setSelectedUser]);
|
||||||
state.selectedUser,
|
|
||||||
state.setSelectedUser,
|
|
||||||
]);
|
|
||||||
// const [statsUserId, setStatsUserId] = useState<string | undefined>(user.id);
|
// const [statsUserId, setStatsUserId] = useState<string | undefined>(user.id);
|
||||||
const [groupedStats, setGroupedStats] = useState<{ [key: string]: Stat[] }>();
|
const [groupedStats, setGroupedStats] = useState<{[key: string]: Stat[]}>();
|
||||||
const [filter, setFilter] = useState<
|
const [filter, setFilter] = useState<"months" | "weeks" | "days" | "assignments">();
|
||||||
"months" | "weeks" | "days" | "assignments"
|
const {assignments} = useAssignments({});
|
||||||
>();
|
|
||||||
const { assignments } = useAssignments({});
|
|
||||||
|
|
||||||
const { users } = useUsers();
|
const {users} = useUsers();
|
||||||
const { stats, isLoading: isStatsLoading } = useStats(statsUserId);
|
const {stats, isLoading: isStatsLoading} = useStats(statsUserId);
|
||||||
const { groups: allGroups } = useGroups();
|
const {groups: allGroups} = useGroups();
|
||||||
|
|
||||||
const groups = allGroups.filter((x) => x.admin === user.id);
|
const groups = allGroups.filter((x) => x.admin === user.id);
|
||||||
|
|
||||||
@@ -106,8 +91,8 @@ export default function History({ user }: { user: User }) {
|
|||||||
)
|
)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
})
|
}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [stats, isStatsLoading]);
|
}, [stats, isStatsLoading]);
|
||||||
@@ -121,33 +106,26 @@ export default function History({ user }: { user: User }) {
|
|||||||
setFilter((prev) => (prev === value ? undefined : value));
|
setFilter((prev) => (prev === value ? undefined : value));
|
||||||
};
|
};
|
||||||
|
|
||||||
const filterStatsByDate = (stats: { [key: string]: Stat[] }) => {
|
const filterStatsByDate = (stats: {[key: string]: Stat[]}) => {
|
||||||
if (filter && filter !== "assignments") {
|
if (filter && filter !== "assignments") {
|
||||||
const filterDate = moment()
|
const filterDate = moment()
|
||||||
.subtract({ [filter as string]: 1 })
|
.subtract({[filter as string]: 1})
|
||||||
.format("x");
|
.format("x");
|
||||||
const filteredStats: { [key: string]: Stat[] } = {};
|
const filteredStats: {[key: string]: Stat[]} = {};
|
||||||
|
|
||||||
Object.keys(stats).forEach((timestamp) => {
|
Object.keys(stats).forEach((timestamp) => {
|
||||||
if (timestamp >= filterDate)
|
if (timestamp >= filterDate) filteredStats[timestamp] = stats[timestamp];
|
||||||
filteredStats[timestamp] = stats[timestamp];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return filteredStats;
|
return filteredStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter && filter === "assignments") {
|
if (filter && filter === "assignments") {
|
||||||
const filteredStats: { [key: string]: Stat[] } = {};
|
const filteredStats: {[key: string]: Stat[]} = {};
|
||||||
|
|
||||||
Object.keys(stats).forEach((timestamp) => {
|
Object.keys(stats).forEach((timestamp) => {
|
||||||
if (
|
if (stats[timestamp].map((s) => s.assignment === undefined).includes(false))
|
||||||
stats[timestamp]
|
filteredStats[timestamp] = [...stats[timestamp].filter((s) => !!s.assignment)];
|
||||||
.map((s) => s.assignment === undefined)
|
|
||||||
.includes(false)
|
|
||||||
)
|
|
||||||
filteredStats[timestamp] = [
|
|
||||||
...stats[timestamp].filter((s) => !!s.assignment),
|
|
||||||
];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return filteredStats;
|
return filteredStats;
|
||||||
@@ -163,11 +141,9 @@ export default function History({ user }: { user: User }) {
|
|||||||
return date.format(formatter);
|
return date.format(formatter);
|
||||||
};
|
};
|
||||||
|
|
||||||
const aggregateScoresByModule = (
|
const aggregateScoresByModule = (stats: Stat[]): {module: Module; total: number; missing: number; correct: number}[] => {
|
||||||
stats: Stat[]
|
|
||||||
): { module: Module; total: number; missing: number; correct: number }[] => {
|
|
||||||
const scores: {
|
const scores: {
|
||||||
[key in Module]: { total: number; missing: number; correct: number };
|
[key in Module]: {total: number; missing: number; correct: number};
|
||||||
} = {
|
} = {
|
||||||
reading: {
|
reading: {
|
||||||
total: 0,
|
total: 0,
|
||||||
@@ -206,28 +182,17 @@ export default function History({ user }: { user: User }) {
|
|||||||
|
|
||||||
return Object.keys(scores)
|
return Object.keys(scores)
|
||||||
.filter((x) => scores[x as Module].total > 0)
|
.filter((x) => scores[x as Module].total > 0)
|
||||||
.map((x) => ({ module: x as Module, ...scores[x as Module] }));
|
.map((x) => ({module: x as Module, ...scores[x as Module]}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const customContent = (timestamp: string) => {
|
const customContent = (timestamp: string) => {
|
||||||
if (!groupedStats) return <></>;
|
if (!groupedStats) return <></>;
|
||||||
|
|
||||||
const dateStats = groupedStats[timestamp];
|
const dateStats = groupedStats[timestamp];
|
||||||
const correct = dateStats.reduce(
|
const correct = dateStats.reduce((accumulator, current) => accumulator + current.score.correct, 0);
|
||||||
(accumulator, current) => accumulator + current.score.correct,
|
const total = dateStats.reduce((accumulator, current) => accumulator + current.score.total, 0);
|
||||||
0
|
const aggregatedScores = aggregateScoresByModule(dateStats).filter((x) => x.total > 0);
|
||||||
);
|
const assignmentID = dateStats.reduce((_, current) => current.assignment as any, "");
|
||||||
const total = dateStats.reduce(
|
|
||||||
(accumulator, current) => accumulator + current.score.total,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
const aggregatedScores = aggregateScoresByModule(dateStats).filter(
|
|
||||||
(x) => x.total > 0
|
|
||||||
);
|
|
||||||
const assignmentID = dateStats.reduce(
|
|
||||||
(_, current) => current.assignment as any,
|
|
||||||
""
|
|
||||||
);
|
|
||||||
const assignment = assignments.find((a) => a.id === assignmentID);
|
const assignment = assignments.find((a) => a.id === assignmentID);
|
||||||
const isDisabled = dateStats.some((x) => x.isDisabled);
|
const isDisabled = dateStats.some((x) => x.isDisabled);
|
||||||
|
|
||||||
@@ -236,14 +201,16 @@ export default function History({ user }: { user: User }) {
|
|||||||
level: calculateBandScore(x.correct, x.total, x.module, user.focus),
|
level: calculateBandScore(x.correct, x.total, x.module, user.focus),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { timeSpent, inactivity, session } = dateStats[0];
|
const {timeSpent, inactivity, session} = dateStats[0];
|
||||||
|
|
||||||
const selectExam = () => {
|
const selectExam = () => {
|
||||||
const examPromises = uniqBy(dateStats, "exam").map((stat) => {
|
const examPromises = uniqBy(dateStats, "exam").map((stat) => {
|
||||||
console.log({ stat });
|
console.log({stat});
|
||||||
return getExamById(stat.module, stat.exam);
|
return getExamById(stat.module, stat.exam);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isDisabled) return;
|
||||||
|
|
||||||
Promise.all(examPromises).then((exams) => {
|
Promise.all(examPromises).then((exams) => {
|
||||||
if (exams.every((x) => !!x)) {
|
if (exams.every((x) => !!x)) {
|
||||||
if (!!timeSpent) setTimeSpent(timeSpent);
|
if (!!timeSpent) setTimeSpent(timeSpent);
|
||||||
@@ -256,7 +223,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
exams
|
exams
|
||||||
.map((x) => x!)
|
.map((x) => x!)
|
||||||
.sort(sortByModule)
|
.sort(sortByModule)
|
||||||
.map((x) => x!.module)
|
.map((x) => x!.module),
|
||||||
);
|
);
|
||||||
router.push("/exercises");
|
router.push("/exercises");
|
||||||
}
|
}
|
||||||
@@ -266,7 +233,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
const textColor = clsx(
|
const textColor = clsx(
|
||||||
correct / total >= 0.7 && "text-mti-purple",
|
correct / total >= 0.7 && "text-mti-purple",
|
||||||
correct / total >= 0.3 && correct / total < 0.7 && "text-mti-red",
|
correct / total >= 0.3 && correct / total < 0.7 && "text-mti-red",
|
||||||
correct / total < 0.3 && "text-mti-rose"
|
correct / total < 0.3 && "text-mti-rose",
|
||||||
);
|
);
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
@@ -276,18 +243,12 @@ export default function History({ user }: { user: User }) {
|
|||||||
<span className="font-medium">{formatTimestamp(timestamp)}</span>
|
<span className="font-medium">{formatTimestamp(timestamp)}</span>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{!!timeSpent && (
|
{!!timeSpent && (
|
||||||
<span
|
<span className="text-sm flex gap-2 items-center tooltip" data-tip="Time Spent">
|
||||||
className="text-sm flex gap-2 items-center tooltip"
|
|
||||||
data-tip="Time Spent"
|
|
||||||
>
|
|
||||||
<BsClock /> {Math.floor(timeSpent / 60)} minutes
|
<BsClock /> {Math.floor(timeSpent / 60)} minutes
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{!!inactivity && (
|
{!!inactivity && (
|
||||||
<span
|
<span className="text-sm flex gap-2 items-center tooltip" data-tip="Inactivity">
|
||||||
className="text-sm flex gap-2 items-center tooltip"
|
|
||||||
data-tip="Inactivity"
|
|
||||||
>
|
|
||||||
<BsXCircle /> {Math.floor(inactivity / 60)} minutes
|
<BsXCircle /> {Math.floor(inactivity / 60)} minutes
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
@@ -296,12 +257,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<span className={textColor}>
|
<span className={textColor}>
|
||||||
Level{" "}
|
Level{" "}
|
||||||
{(
|
{(aggregatedLevels.reduce((accumulator, current) => accumulator + current.level, 0) / aggregatedLevels.length).toFixed(1)}
|
||||||
aggregatedLevels.reduce(
|
|
||||||
(accumulator, current) => accumulator + current.level,
|
|
||||||
0
|
|
||||||
) / aggregatedLevels.length
|
|
||||||
).toFixed(1)}
|
|
||||||
</span>
|
</span>
|
||||||
{renderPdfIcon(session, textColor, textColor)}
|
{renderPdfIcon(session, textColor, textColor)}
|
||||||
</div>
|
</div>
|
||||||
@@ -309,7 +265,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
|
|
||||||
<div className="w-full flex flex-col gap-1">
|
<div className="w-full flex flex-col gap-1">
|
||||||
<div className="grid grid-cols-4 gap-2 place-items-start w-full -md:mt-2">
|
<div className="grid grid-cols-4 gap-2 place-items-start w-full -md:mt-2">
|
||||||
{aggregatedLevels.map(({ module, level }) => (
|
{aggregatedLevels.map(({module, level}) => (
|
||||||
<div
|
<div
|
||||||
key={module}
|
key={module}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
@@ -318,9 +274,8 @@ export default function History({ user }: { user: User }) {
|
|||||||
module === "listening" && "bg-ielts-listening",
|
module === "listening" && "bg-ielts-listening",
|
||||||
module === "writing" && "bg-ielts-writing",
|
module === "writing" && "bg-ielts-writing",
|
||||||
module === "speaking" && "bg-ielts-speaking",
|
module === "speaking" && "bg-ielts-speaking",
|
||||||
module === "level" && "bg-ielts-level"
|
module === "level" && "bg-ielts-level",
|
||||||
)}
|
)}>
|
||||||
>
|
|
||||||
{module === "reading" && <BsBook className="w-4 h-4" />}
|
{module === "reading" && <BsBook className="w-4 h-4" />}
|
||||||
{module === "listening" && <BsHeadphones className="w-4 h-4" />}
|
{module === "listening" && <BsHeadphones className="w-4 h-4" />}
|
||||||
{module === "writing" && <BsPen className="w-4 h-4" />}
|
{module === "writing" && <BsPen className="w-4 h-4" />}
|
||||||
@@ -333,8 +288,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
|
|
||||||
{assignment && (
|
{assignment && (
|
||||||
<span className="font-light text-sm">
|
<span className="font-light text-sm">
|
||||||
Assignment: {assignment.name}, Teacher:{" "}
|
Assignment: {assignment.name}, Teacher: {users.find((u) => u.id === assignment.assigner)?.name}
|
||||||
{users.find((u) => u.id === assignment.assigner)?.name}
|
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -349,15 +303,12 @@ export default function History({ user }: { user: User }) {
|
|||||||
"flex flex-col justify-between gap-4 border border-mti-gray-platinum p-4 cursor-pointer rounded-xl transition ease-in-out duration-300 -md:hidden",
|
"flex flex-col justify-between gap-4 border border-mti-gray-platinum p-4 cursor-pointer rounded-xl transition ease-in-out duration-300 -md:hidden",
|
||||||
isDisabled && "grayscale tooltip",
|
isDisabled && "grayscale tooltip",
|
||||||
correct / total >= 0.7 && "hover:border-mti-purple",
|
correct / total >= 0.7 && "hover:border-mti-purple",
|
||||||
correct / total >= 0.3 &&
|
correct / total >= 0.3 && correct / total < 0.7 && "hover:border-mti-red",
|
||||||
correct / total < 0.7 &&
|
correct / total < 0.3 && "hover:border-mti-rose",
|
||||||
"hover:border-mti-red",
|
|
||||||
correct / total < 0.3 && "hover:border-mti-rose"
|
|
||||||
)}
|
)}
|
||||||
onClick={isDisabled ? () => null : selectExam}
|
onClick={selectExam}
|
||||||
data-tip="This exam is still being evaluated..."
|
data-tip="This exam is still being evaluated..."
|
||||||
role="button"
|
role="button">
|
||||||
>
|
|
||||||
{content}
|
{content}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -365,14 +316,11 @@ export default function History({ user }: { user: User }) {
|
|||||||
className={clsx(
|
className={clsx(
|
||||||
"flex flex-col gap-4 border border-mti-gray-platinum p-4 cursor-pointer rounded-xl transition ease-in-out duration-300 -md:tooltip md:hidden",
|
"flex flex-col gap-4 border border-mti-gray-platinum p-4 cursor-pointer rounded-xl transition ease-in-out duration-300 -md:tooltip md:hidden",
|
||||||
correct / total >= 0.7 && "hover:border-mti-purple",
|
correct / total >= 0.7 && "hover:border-mti-purple",
|
||||||
correct / total >= 0.3 &&
|
correct / total >= 0.3 && correct / total < 0.7 && "hover:border-mti-red",
|
||||||
correct / total < 0.7 &&
|
correct / total < 0.3 && "hover:border-mti-rose",
|
||||||
"hover:border-mti-red",
|
|
||||||
correct / total < 0.3 && "hover:border-mti-rose"
|
|
||||||
)}
|
)}
|
||||||
data-tip="Your screen size is too small to view previous exams."
|
data-tip="Your screen size is too small to view previous exams."
|
||||||
role="button"
|
role="button">
|
||||||
>
|
|
||||||
{content}
|
{content}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@@ -389,20 +337,15 @@ export default function History({ user }: { user: User }) {
|
|||||||
})),
|
})),
|
||||||
];
|
];
|
||||||
|
|
||||||
const [selectedCorporate, setSelectedCorporate] = useState<string>(
|
const [selectedCorporate, setSelectedCorporate] = useState<string>(defaultSelectableCorporate.value);
|
||||||
defaultSelectableCorporate.value
|
|
||||||
);
|
|
||||||
|
|
||||||
const getUsersList = (): User[] => {
|
const getUsersList = (): User[] => {
|
||||||
if (selectedCorporate) {
|
if (selectedCorporate) {
|
||||||
// get groups for that corporate
|
// get groups for that corporate
|
||||||
const selectedCorporateGroups = allGroups.filter(
|
const selectedCorporateGroups = allGroups.filter((x) => x.admin === selectedCorporate);
|
||||||
(x) => x.admin === selectedCorporate
|
|
||||||
);
|
|
||||||
|
|
||||||
// get the teacher ids for that group
|
// get the teacher ids for that group
|
||||||
const selectedCorporateGroupsParticipants =
|
const selectedCorporateGroupsParticipants = selectedCorporateGroups.flatMap((x) => x.participants);
|
||||||
selectedCorporateGroups.flatMap((x) => x.participants);
|
|
||||||
|
|
||||||
// // search for groups for these teachers
|
// // search for groups for these teachers
|
||||||
// const teacherGroups = allGroups.filter((x) => {
|
// const teacherGroups = allGroups.filter((x) => {
|
||||||
@@ -413,9 +356,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
// ...selectedCorporateGroupsParticipants,
|
// ...selectedCorporateGroupsParticipants,
|
||||||
// ...teacherGroups.flatMap((x) => x.participants),
|
// ...teacherGroups.flatMap((x) => x.participants),
|
||||||
// ];
|
// ];
|
||||||
const userListWithUsers = selectedCorporateGroupsParticipants.map((x) =>
|
const userListWithUsers = selectedCorporateGroupsParticipants.map((x) => users.find((y) => y.id === x)) as User[];
|
||||||
users.find((y) => y.id === x)
|
|
||||||
) as User[];
|
|
||||||
return userListWithUsers.filter((x) => x);
|
return userListWithUsers.filter((x) => x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,9 +367,7 @@ export default function History({ user }: { user: User }) {
|
|||||||
|
|
||||||
const getSelectedUser = () => {
|
const getSelectedUser = () => {
|
||||||
if (selectedCorporate) {
|
if (selectedCorporate) {
|
||||||
const userInCorporate = corporateFilteredUserList.find(
|
const userInCorporate = corporateFilteredUserList.find((x) => x.id === statsUserId);
|
||||||
(x) => x.id === statsUserId
|
|
||||||
);
|
|
||||||
return userInCorporate || corporateFilteredUserList[0];
|
return userInCorporate || corporateFilteredUserList[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,34 +402,21 @@ export default function History({ user }: { user: User }) {
|
|||||||
<div className="xl:w-3/4">
|
<div className="xl:w-3/4">
|
||||||
{(user.type === "developer" || user.type === "admin") && (
|
{(user.type === "developer" || user.type === "admin") && (
|
||||||
<>
|
<>
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Corporate</label>
|
||||||
Corporate
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
options={selectableCorporates}
|
options={selectableCorporates}
|
||||||
value={selectableCorporates.find(
|
value={selectableCorporates.find((x) => x.value === selectedCorporate)}
|
||||||
(x) => x.value === selectedCorporate
|
onChange={(value) => setSelectedCorporate(value?.value || "")}
|
||||||
)}
|
|
||||||
onChange={(value) =>
|
|
||||||
setSelectedCorporate(value?.value || "")
|
|
||||||
}
|
|
||||||
styles={{
|
styles={{
|
||||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||||
option: (styles, state) => ({
|
option: (styles, state) => ({
|
||||||
...styles,
|
...styles,
|
||||||
backgroundColor: state.isFocused
|
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||||
? "#D5D9F0"
|
|
||||||
: state.isSelected
|
|
||||||
? "#7872BF"
|
|
||||||
: "white",
|
|
||||||
color: state.isFocused ? "black" : styles.color,
|
color: state.isFocused ? "black" : styles.color,
|
||||||
}),
|
}),
|
||||||
}}
|
}}></Select>
|
||||||
></Select>
|
<label className="font-normal text-base text-mti-gray-dim">User</label>
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
|
||||||
User
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
options={corporateFilteredUserList.map((x) => ({
|
options={corporateFilteredUserList.map((x) => ({
|
||||||
@@ -500,32 +426,23 @@ export default function History({ user }: { user: User }) {
|
|||||||
value={selectedUserSelectValue}
|
value={selectedUserSelectValue}
|
||||||
onChange={(value) => setStatsUserId(value?.value)}
|
onChange={(value) => setStatsUserId(value?.value)}
|
||||||
styles={{
|
styles={{
|
||||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||||
option: (styles, state) => ({
|
option: (styles, state) => ({
|
||||||
...styles,
|
...styles,
|
||||||
backgroundColor: state.isFocused
|
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||||
? "#D5D9F0"
|
|
||||||
: state.isSelected
|
|
||||||
? "#7872BF"
|
|
||||||
: "white",
|
|
||||||
color: state.isFocused ? "black" : styles.color,
|
color: state.isFocused ? "black" : styles.color,
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{(user.type === "corporate" || user.type === "teacher") &&
|
{(user.type === "corporate" || user.type === "teacher") && groups.length > 0 && (
|
||||||
groups.length > 0 && (
|
|
||||||
<>
|
<>
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">User</label>
|
||||||
User
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
options={users
|
options={users
|
||||||
.filter((x) =>
|
.filter((x) => groups.flatMap((y) => y.participants).includes(x.id))
|
||||||
groups.flatMap((y) => y.participants).includes(x.id)
|
|
||||||
)
|
|
||||||
.map((x) => ({
|
.map((x) => ({
|
||||||
value: x.id,
|
value: x.id,
|
||||||
label: `${x.name} - ${x.email}`,
|
label: `${x.name} - ${x.email}`,
|
||||||
@@ -533,14 +450,10 @@ export default function History({ user }: { user: User }) {
|
|||||||
value={selectedUserSelectValue}
|
value={selectedUserSelectValue}
|
||||||
onChange={(value) => setStatsUserId(value?.value)}
|
onChange={(value) => setStatsUserId(value?.value)}
|
||||||
styles={{
|
styles={{
|
||||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||||
option: (styles, state) => ({
|
option: (styles, state) => ({
|
||||||
...styles,
|
...styles,
|
||||||
backgroundColor: state.isFocused
|
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||||
? "#D5D9F0"
|
|
||||||
: state.isSelected
|
|
||||||
? "#7872BF"
|
|
||||||
: "white",
|
|
||||||
color: state.isFocused ? "black" : styles.color,
|
color: state.isFocused ? "black" : styles.color,
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
@@ -553,59 +466,49 @@ export default function History({ user }: { user: User }) {
|
|||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
||||||
"transition duration-300 ease-in-out",
|
"transition duration-300 ease-in-out",
|
||||||
filter === "assignments" && "!bg-mti-purple-light !text-white"
|
filter === "assignments" && "!bg-mti-purple-light !text-white",
|
||||||
)}
|
)}
|
||||||
onClick={() => toggleFilter("assignments")}
|
onClick={() => toggleFilter("assignments")}>
|
||||||
>
|
|
||||||
Assignments
|
Assignments
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
||||||
"transition duration-300 ease-in-out",
|
"transition duration-300 ease-in-out",
|
||||||
filter === "months" && "!bg-mti-purple-light !text-white"
|
filter === "months" && "!bg-mti-purple-light !text-white",
|
||||||
)}
|
)}
|
||||||
onClick={() => toggleFilter("months")}
|
onClick={() => toggleFilter("months")}>
|
||||||
>
|
|
||||||
Last month
|
Last month
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
||||||
"transition duration-300 ease-in-out",
|
"transition duration-300 ease-in-out",
|
||||||
filter === "weeks" && "!bg-mti-purple-light !text-white"
|
filter === "weeks" && "!bg-mti-purple-light !text-white",
|
||||||
)}
|
)}
|
||||||
onClick={() => toggleFilter("weeks")}
|
onClick={() => toggleFilter("weeks")}>
|
||||||
>
|
|
||||||
Last week
|
Last week
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
|
||||||
"transition duration-300 ease-in-out",
|
"transition duration-300 ease-in-out",
|
||||||
filter === "days" && "!bg-mti-purple-light !text-white"
|
filter === "days" && "!bg-mti-purple-light !text-white",
|
||||||
)}
|
)}
|
||||||
onClick={() => toggleFilter("days")}
|
onClick={() => toggleFilter("days")}>
|
||||||
>
|
|
||||||
Last day
|
Last day
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{groupedStats &&
|
{groupedStats && Object.keys(groupedStats).length > 0 && !isStatsLoading && (
|
||||||
Object.keys(groupedStats).length > 0 &&
|
|
||||||
!isStatsLoading && (
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 w-full gap-4 xl:gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 w-full gap-4 xl:gap-6">
|
||||||
{Object.keys(filterStatsByDate(groupedStats))
|
{Object.keys(filterStatsByDate(groupedStats))
|
||||||
.sort((a, b) => parseInt(b) - parseInt(a))
|
.sort((a, b) => parseInt(b) - parseInt(a))
|
||||||
.map(customContent)}
|
.map(customContent)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{groupedStats &&
|
{groupedStats && Object.keys(groupedStats).length === 0 && !isStatsLoading && (
|
||||||
Object.keys(groupedStats).length === 0 &&
|
<span className="font-semibold ml-1">No record to display...</span>
|
||||||
!isStatsLoading && (
|
|
||||||
<span className="font-semibold ml-1">
|
|
||||||
No record to display...
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</Layout>
|
</Layout>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export const evaluateSpeakingAnswer = async (
|
|||||||
case "speaking":
|
case "speaking":
|
||||||
return {...(await evaluateSpeakingExercise(exercise, exercise.id, solution, id, task)), id} as UserSolution;
|
return {...(await evaluateSpeakingExercise(exercise, exercise.id, solution, id, task)), id} as UserSolution;
|
||||||
case "interactiveSpeaking":
|
case "interactiveSpeaking":
|
||||||
return {...(await evaluateInteractiveSpeakingExercise(exercise.id, solution, id, exercise.variant)), id} as UserSolution;
|
return {...(await evaluateInteractiveSpeakingExercise(exercise.id, solution, id, task === 3 ? "final" : "initial")), id} as UserSolution;
|
||||||
default:
|
default:
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user