Merge branch 'develop' into ENCOA-38/add-validity-date-for-discounts
This commit is contained in:
@@ -16,9 +16,13 @@ function Question({
|
||||
}: MultipleChoiceQuestion & {userSolution: string | undefined; onSelectOption?: (option: string) => void; showSolution?: boolean}) {
|
||||
return (
|
||||
<div className="flex flex-col gap-10">
|
||||
{isNaN(Number(id)) ? (
|
||||
<span className="">{prompt}</span>
|
||||
) : (
|
||||
<span className="">
|
||||
{id} - {prompt}
|
||||
</span>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-4 justify-between">
|
||||
{variant === "image" &&
|
||||
options.map((option) => (
|
||||
|
||||
@@ -27,9 +27,13 @@ function Question({
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4">
|
||||
<span>
|
||||
{isNaN(Number(id)) ? (
|
||||
<span className="">{prompt}</span>
|
||||
) : (
|
||||
<span className="">
|
||||
{id} - {prompt}
|
||||
</span>
|
||||
)}
|
||||
<div className="grid grid-cols-4 gap-4 place-items-center">
|
||||
{variant === "image" &&
|
||||
options.map((option) => (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import { Module } from "@/interfaces";
|
||||
import { useEffect, useState } from "react";
|
||||
import {Module} from "@/interfaces";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
import AbandonPopup from "@/components/AbandonPopup";
|
||||
import Layout from "@/components/High/Layout";
|
||||
@@ -12,18 +12,15 @@ import Selection from "@/exams/Selection";
|
||||
import Speaking from "@/exams/Speaking";
|
||||
import Writing from "@/exams/Writing";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import { Exam, UserSolution, Variant } from "@/interfaces/exam";
|
||||
import { Stat } from "@/interfaces/user";
|
||||
import {Exam, UserSolution, Variant} from "@/interfaces/exam";
|
||||
import {Stat} from "@/interfaces/user";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {
|
||||
evaluateSpeakingAnswer,
|
||||
evaluateWritingAnswer,
|
||||
} from "@/utils/evaluation";
|
||||
import { defaultExamUserSolutions, getExam } from "@/utils/exams";
|
||||
import {evaluateSpeakingAnswer, evaluateWritingAnswer} from "@/utils/evaluation";
|
||||
import {defaultExamUserSolutions, getExam} from "@/utils/exams";
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/router";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
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";
|
||||
|
||||
@@ -31,15 +28,13 @@ interface Props {
|
||||
page: "exams" | "exercises";
|
||||
}
|
||||
|
||||
export default function ExamPage({ page }: Props) {
|
||||
export default function ExamPage({page}: Props) {
|
||||
const [variant, setVariant] = useState<Variant>("full");
|
||||
const [avoidRepeated, setAvoidRepeated] = useState(false);
|
||||
const [hasBeenUploaded, setHasBeenUploaded] = useState(false);
|
||||
const [showAbandonPopup, setShowAbandonPopup] = useState(false);
|
||||
const [isEvaluationLoading, setIsEvaluationLoading] = useState(false);
|
||||
const [statsAwaitingEvaluation, setStatsAwaitingEvaluation] = useState<
|
||||
string[]
|
||||
>([]);
|
||||
const [statsAwaitingEvaluation, setStatsAwaitingEvaluation] = useState<string[]>([]);
|
||||
const [timeSpent, setTimeSpent] = useState(0);
|
||||
|
||||
const resetStore = useExamStore((state) => state.reset);
|
||||
@@ -48,20 +43,18 @@ export default function ExamPage({ page }: Props) {
|
||||
|
||||
const examStore = useExamStore;
|
||||
|
||||
const { exam, setExam } = useExamStore((state) => state);
|
||||
const { exams, setExams } = useExamStore((state) => state);
|
||||
const { sessionId, setSessionId } = useExamStore((state) => state);
|
||||
const { partIndex, setPartIndex } = useExamStore((state) => state);
|
||||
const { moduleIndex, setModuleIndex } = useExamStore((state) => state);
|
||||
const { questionIndex, setQuestionIndex } = useExamStore((state) => state);
|
||||
const { exerciseIndex, setExerciseIndex } = useExamStore((state) => state);
|
||||
const { userSolutions, setUserSolutions } = useExamStore((state) => state);
|
||||
const { showSolutions, setShowSolutions } = useExamStore((state) => state);
|
||||
const { selectedModules, setSelectedModules } = useExamStore(
|
||||
(state) => state,
|
||||
);
|
||||
const {exam, setExam} = useExamStore((state) => state);
|
||||
const {exams, setExams} = useExamStore((state) => state);
|
||||
const {sessionId, setSessionId} = useExamStore((state) => state);
|
||||
const {partIndex, setPartIndex} = useExamStore((state) => state);
|
||||
const {moduleIndex, setModuleIndex} = useExamStore((state) => state);
|
||||
const {questionIndex, setQuestionIndex} = useExamStore((state) => state);
|
||||
const {exerciseIndex, setExerciseIndex} = useExamStore((state) => state);
|
||||
const {userSolutions, setUserSolutions} = useExamStore((state) => state);
|
||||
const {showSolutions, setShowSolutions} = useExamStore((state) => state);
|
||||
const {selectedModules, setSelectedModules} = useExamStore((state) => state);
|
||||
|
||||
const { user } = useUser({ redirectTo: "/login" });
|
||||
const {user} = useUser({redirectTo: "/login"});
|
||||
const router = useRouter();
|
||||
|
||||
const reset = () => {
|
||||
@@ -97,10 +90,7 @@ export default function ExamPage({ page }: Props) {
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(
|
||||
() => setTimeSpent((prev) => prev + initialTimeSpent),
|
||||
[initialTimeSpent],
|
||||
);
|
||||
useEffect(() => setTimeSpent((prev) => prev + initialTimeSpent), [initialTimeSpent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (userSolutions.length === 0 && exams.length > 0) {
|
||||
@@ -122,28 +112,10 @@ export default function ExamPage({ page }: Props) {
|
||||
)
|
||||
saveSession();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [
|
||||
assignment,
|
||||
exam,
|
||||
exams,
|
||||
moduleIndex,
|
||||
selectedModules,
|
||||
sessionId,
|
||||
userSolutions,
|
||||
user,
|
||||
exerciseIndex,
|
||||
partIndex,
|
||||
questionIndex,
|
||||
]);
|
||||
}, [assignment, exam, exams, moduleIndex, selectedModules, sessionId, userSolutions, user, exerciseIndex, partIndex, questionIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
timeSpent % 20 === 0 &&
|
||||
timeSpent > 0 &&
|
||||
moduleIndex < selectedModules.length &&
|
||||
!showSolutions
|
||||
)
|
||||
saveSession();
|
||||
if (timeSpent % 20 === 0 && timeSpent > 0 && moduleIndex < selectedModules.length && !showSolutions) saveSession();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [timeSpent]);
|
||||
|
||||
@@ -177,20 +149,11 @@ export default function ExamPage({ page }: Props) {
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (
|
||||
selectedModules.length > 0 &&
|
||||
exams.length > 0 &&
|
||||
moduleIndex < selectedModules.length
|
||||
) {
|
||||
if (selectedModules.length > 0 && exams.length > 0 && moduleIndex < selectedModules.length) {
|
||||
const nextExam = exams[moduleIndex];
|
||||
|
||||
if (partIndex === -1 && nextExam.module !== "listening")
|
||||
setPartIndex(0);
|
||||
if (
|
||||
exerciseIndex === -1 &&
|
||||
!["reading", "listening"].includes(nextExam?.module)
|
||||
)
|
||||
setExerciseIndex(0);
|
||||
if (partIndex === -1 && nextExam.module !== "listening") setPartIndex(0);
|
||||
if (exerciseIndex === -1 && !["reading", "listening"].includes(nextExam?.module)) setExerciseIndex(0);
|
||||
setExam(nextExam ? updateExamWithUserSolutions(nextExam) : undefined);
|
||||
}
|
||||
})();
|
||||
@@ -205,9 +168,7 @@ export default function ExamPage({ page }: Props) {
|
||||
module,
|
||||
avoidRepeated,
|
||||
variant,
|
||||
user?.type === "student" || user?.type === "developer"
|
||||
? user.preferredGender
|
||||
: undefined,
|
||||
user?.type === "student" || user?.type === "developer" ? user.preferredGender : undefined,
|
||||
),
|
||||
);
|
||||
Promise.all(examPromises).then((values) => {
|
||||
@@ -224,13 +185,7 @@ export default function ExamPage({ page }: Props) {
|
||||
}, [selectedModules, setExams, exams]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
selectedModules.length > 0 &&
|
||||
exams.length !== 0 &&
|
||||
moduleIndex >= selectedModules.length &&
|
||||
!hasBeenUploaded &&
|
||||
!showSolutions
|
||||
) {
|
||||
if (selectedModules.length > 0 && exams.length !== 0 && moduleIndex >= selectedModules.length && !hasBeenUploaded && !showSolutions) {
|
||||
const newStats: Stat[] = userSolutions.map((solution) => ({
|
||||
...solution,
|
||||
id: solution.id || uuidv4(),
|
||||
@@ -241,11 +196,11 @@ export default function ExamPage({ page }: Props) {
|
||||
user: user?.id || "",
|
||||
date: new Date().getTime(),
|
||||
isDisabled: solution.isDisabled,
|
||||
...(assignment ? { assignment: assignment.id } : {}),
|
||||
...(assignment ? {assignment: assignment.id} : {}),
|
||||
}));
|
||||
|
||||
axios
|
||||
.post<{ ok: boolean }>("/api/stats", newStats)
|
||||
.post<{ok: boolean}>("/api/stats", newStats)
|
||||
.then((response) => setHasBeenUploaded(response.data.ok))
|
||||
.catch(() => setHasBeenUploaded(false));
|
||||
}
|
||||
@@ -266,17 +221,10 @@ export default function ExamPage({ page }: Props) {
|
||||
const checkIfStatsHaveBeenEvaluated = (ids: string[]) => {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const awaitedStats = await Promise.all(
|
||||
ids.map(
|
||||
async (id) => (await axios.get<Stat>(`/api/stats/${id}`)).data,
|
||||
),
|
||||
);
|
||||
const solutionsEvaluated = awaitedStats.every((stat) =>
|
||||
stat.solutions.every((x) => x.evaluation !== null),
|
||||
);
|
||||
const awaitedStats = await Promise.all(ids.map(async (id) => (await axios.get<Stat>(`/api/stats/${id}`)).data));
|
||||
const solutionsEvaluated = awaitedStats.every((stat) => stat.solutions.every((x) => x.evaluation !== null));
|
||||
if (solutionsEvaluated) {
|
||||
const statsUserSolutions: UserSolution[] = awaitedStats.map(
|
||||
(stat) => ({
|
||||
const statsUserSolutions: UserSolution[] = awaitedStats.map((stat) => ({
|
||||
id: stat.id,
|
||||
exercise: stat.exercise,
|
||||
score: stat.score,
|
||||
@@ -284,20 +232,15 @@ export default function ExamPage({ page }: Props) {
|
||||
type: stat.type,
|
||||
exam: stat.exam,
|
||||
module: stat.module,
|
||||
}),
|
||||
);
|
||||
}));
|
||||
|
||||
const updatedUserSolutions = userSolutions.map((x) => {
|
||||
const respectiveSolution = statsUserSolutions.find(
|
||||
(y) => y.exercise === x.exercise,
|
||||
);
|
||||
const respectiveSolution = statsUserSolutions.find((y) => y.exercise === x.exercise);
|
||||
return respectiveSolution ? respectiveSolution : x;
|
||||
});
|
||||
|
||||
setUserSolutions(updatedUserSolutions);
|
||||
return setStatsAwaitingEvaluation((prev) =>
|
||||
prev.filter((x) => !ids.includes(x)),
|
||||
);
|
||||
return setStatsAwaitingEvaluation((prev) => prev.filter((x) => !ids.includes(x)));
|
||||
}
|
||||
|
||||
return checkIfStatsHaveBeenEvaluated(ids);
|
||||
@@ -313,22 +256,20 @@ export default function ExamPage({ page }: Props) {
|
||||
Object.assign(p, {
|
||||
exercises: p.exercises.map((x) =>
|
||||
Object.assign(x, {
|
||||
userSolutions: userSolutions.find((y) => x.id === y.exercise)
|
||||
?.solutions,
|
||||
userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
);
|
||||
return Object.assign(exam, { parts });
|
||||
return Object.assign(exam, {parts});
|
||||
}
|
||||
|
||||
const exercises = exam.exercises.map((x) =>
|
||||
Object.assign(x, {
|
||||
userSolutions: userSolutions.find((y) => x.id === y.exercise)
|
||||
?.solutions,
|
||||
userSolutions: userSolutions.find((y) => x.id === y.exercise)?.solutions,
|
||||
}),
|
||||
);
|
||||
return Object.assign(exam, { exercises });
|
||||
return Object.assign(exam, {exercises});
|
||||
};
|
||||
|
||||
const onFinish = async (solutions: UserSolution[]) => {
|
||||
@@ -339,12 +280,7 @@ export default function ExamPage({ page }: Props) {
|
||||
|
||||
if (exam && !solutionExams.includes(exam.id)) return;
|
||||
|
||||
if (
|
||||
exam &&
|
||||
(exam.module === "writing" || exam.module === "speaking") &&
|
||||
solutions.length > 0 &&
|
||||
!showSolutions
|
||||
) {
|
||||
if (exam && (exam.module === "writing" || exam.module === "speaking") && solutions.length > 0 && !showSolutions) {
|
||||
setHasBeenUploaded(true);
|
||||
setIsEvaluationLoading(true);
|
||||
|
||||
@@ -353,45 +289,27 @@ export default function ExamPage({ page }: Props) {
|
||||
exam.exercises.map(async (exercise, index) => {
|
||||
const evaluationID = uuidv4();
|
||||
if (exercise.type === "writing")
|
||||
return await evaluateWritingAnswer(
|
||||
exercise,
|
||||
index + 1,
|
||||
solutions.find((x) => x.exercise === exercise.id)!,
|
||||
evaluationID,
|
||||
);
|
||||
return await evaluateWritingAnswer(exercise, index + 1, solutions.find((x) => x.exercise === exercise.id)!, evaluationID);
|
||||
|
||||
if (
|
||||
exercise.type === "interactiveSpeaking" ||
|
||||
exercise.type === "speaking"
|
||||
)
|
||||
if (exercise.type === "interactiveSpeaking" || exercise.type === "speaking")
|
||||
return await evaluateSpeakingAnswer(
|
||||
exercise,
|
||||
solutions.find((x) => x.exercise === exercise.id)!,
|
||||
evaluationID,
|
||||
index === 0 ? 1 : 2,
|
||||
);
|
||||
}),
|
||||
)
|
||||
).filter((x) => !!x) as UserSolution[];
|
||||
|
||||
newSolutions = [
|
||||
...newSolutions.filter(
|
||||
(x) => !responses.map((y) => y.exercise).includes(x.exercise),
|
||||
),
|
||||
...responses,
|
||||
];
|
||||
setStatsAwaitingEvaluation((prev) => [
|
||||
...prev,
|
||||
...responses.filter((x) => !!x).map((r) => (r as any).id),
|
||||
]);
|
||||
newSolutions = [...newSolutions.filter((x) => !responses.map((y) => y.exercise).includes(x.exercise)), ...responses];
|
||||
setStatsAwaitingEvaluation((prev) => [...prev, ...responses.filter((x) => !!x).map((r) => (r as any).id)]);
|
||||
setHasBeenUploaded(false);
|
||||
}
|
||||
|
||||
axios.get("/api/stats/update");
|
||||
|
||||
setUserSolutions([
|
||||
...userSolutions.filter((x) => !solutionIds.includes(x.exercise)),
|
||||
...newSolutions,
|
||||
]);
|
||||
setUserSolutions([...userSolutions.filter((x) => !solutionIds.includes(x.exercise)), ...newSolutions]);
|
||||
setModuleIndex(moduleIndex + 1);
|
||||
|
||||
setPartIndex(-1);
|
||||
@@ -406,7 +324,7 @@ export default function ExamPage({ page }: Props) {
|
||||
correct: number;
|
||||
}[] => {
|
||||
const scores: {
|
||||
[key in Module]: { total: number; missing: number; correct: number };
|
||||
[key in Module]: {total: number; missing: number; correct: number};
|
||||
} = {
|
||||
reading: {
|
||||
total: 0,
|
||||
@@ -437,12 +355,7 @@ export default function ExamPage({ page }: Props) {
|
||||
|
||||
userSolutions.forEach((x) => {
|
||||
const examModule =
|
||||
x.module ||
|
||||
(x.type === "writing"
|
||||
? "writing"
|
||||
: x.type === "speaking" || x.type === "interactiveSpeaking"
|
||||
? "speaking"
|
||||
: undefined);
|
||||
x.module || (x.type === "writing" ? "writing" : x.type === "speaking" || x.type === "interactiveSpeaking" ? "speaking" : undefined);
|
||||
|
||||
scores[examModule!] = {
|
||||
total: scores[examModule!].total + x.score.total,
|
||||
@@ -453,7 +366,7 @@ export default function ExamPage({ page }: Props) {
|
||||
|
||||
return Object.keys(scores)
|
||||
.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 renderScreen = () => {
|
||||
@@ -482,9 +395,7 @@ export default function ExamPage({ page }: Props) {
|
||||
onViewResults={(index?: number) => {
|
||||
setShowSolutions(true);
|
||||
setModuleIndex(index || 0);
|
||||
setExerciseIndex(
|
||||
["reading", "listening"].includes(exams[0].module) ? -1 : 0,
|
||||
);
|
||||
setExerciseIndex(["reading", "listening"].includes(exams[0].module) ? -1 : 0);
|
||||
setPartIndex(exams[0].module === "listening" ? -1 : 0);
|
||||
setExam(exams[0]);
|
||||
}}
|
||||
@@ -494,49 +405,23 @@ export default function ExamPage({ page }: Props) {
|
||||
}
|
||||
|
||||
if (exam && exam.module === "reading") {
|
||||
return (
|
||||
<Reading
|
||||
exam={exam}
|
||||
onFinish={onFinish}
|
||||
showSolutions={showSolutions}
|
||||
/>
|
||||
);
|
||||
return <Reading exam={exam} onFinish={onFinish} showSolutions={showSolutions} />;
|
||||
}
|
||||
|
||||
if (exam && exam.module === "listening") {
|
||||
return (
|
||||
<Listening
|
||||
exam={exam}
|
||||
onFinish={onFinish}
|
||||
showSolutions={showSolutions}
|
||||
/>
|
||||
);
|
||||
return <Listening exam={exam} onFinish={onFinish} showSolutions={showSolutions} />;
|
||||
}
|
||||
|
||||
if (exam && exam.module === "writing") {
|
||||
return (
|
||||
<Writing
|
||||
exam={exam}
|
||||
onFinish={onFinish}
|
||||
showSolutions={showSolutions}
|
||||
/>
|
||||
);
|
||||
return <Writing exam={exam} onFinish={onFinish} showSolutions={showSolutions} />;
|
||||
}
|
||||
|
||||
if (exam && exam.module === "speaking") {
|
||||
return (
|
||||
<Speaking
|
||||
exam={exam}
|
||||
onFinish={onFinish}
|
||||
showSolutions={showSolutions}
|
||||
/>
|
||||
);
|
||||
return <Speaking exam={exam} onFinish={onFinish} showSolutions={showSolutions} />;
|
||||
}
|
||||
|
||||
if (exam && exam.module === "level") {
|
||||
return (
|
||||
<Level exam={exam} onFinish={onFinish} showSolutions={showSolutions} />
|
||||
);
|
||||
return <Level exam={exam} onFinish={onFinish} showSolutions={showSolutions} />;
|
||||
}
|
||||
|
||||
return <>Loading...</>;
|
||||
@@ -549,13 +434,8 @@ export default function ExamPage({ page }: Props) {
|
||||
<Layout
|
||||
user={user}
|
||||
className="justify-between"
|
||||
focusMode={
|
||||
selectedModules.length !== 0 &&
|
||||
!showSolutions &&
|
||||
moduleIndex < selectedModules.length
|
||||
}
|
||||
onFocusLayerMouseEnter={() => setShowAbandonPopup(true)}
|
||||
>
|
||||
focusMode={selectedModules.length !== 0 && !showSolutions && moduleIndex < selectedModules.length}
|
||||
onFocusLayerMouseEnter={() => setShowAbandonPopup(true)}>
|
||||
<>
|
||||
{renderScreen()}
|
||||
{!showSolutions && moduleIndex < selectedModules.length && (
|
||||
|
||||
@@ -121,12 +121,12 @@ export default function PaymentDue({user, hasExpired = false, clientID, reload}:
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-start gap-2">
|
||||
{!appliedDiscount && (
|
||||
{appliedDiscount === 0 && (
|
||||
<span className="text-2xl">
|
||||
{p.price} {p.currency}
|
||||
</span>
|
||||
)}
|
||||
{appliedDiscount && (
|
||||
{appliedDiscount > 0 && (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-2xl line-through">
|
||||
{p.price} {p.currency}
|
||||
|
||||
@@ -30,6 +30,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const audioFile = files.audio;
|
||||
const audioFileRef = ref(storage, `speaking_recordings/${fields.id}.wav`);
|
||||
const task = parseInt(fields.task.toString());
|
||||
|
||||
const binary = fs.readFileSync((audioFile as any).path).buffer;
|
||||
const snapshot = await uploadBytes(audioFileRef, binary);
|
||||
@@ -39,7 +40,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
res.status(200).json(null);
|
||||
|
||||
console.log("🌱 - Still processing");
|
||||
const backendRequest = await evaluate({answers: [{question: fields.question, answer: path}]});
|
||||
const backendRequest = await evaluate({answer: path, question: fields.question}, task);
|
||||
console.log("🌱 - Process complete");
|
||||
|
||||
const correspondingStat = await getCorrespondingStat(fields.id, 1);
|
||||
@@ -76,14 +77,14 @@ async function getCorrespondingStat(id: string, index: number): Promise<Stat> {
|
||||
return getCorrespondingStat(id, index + 1);
|
||||
}
|
||||
|
||||
async function evaluate(body: {answers: object[]}): Promise<AxiosResponse> {
|
||||
const backendRequest = await axios.post(`${process.env.BACKEND_URL}/speaking_task_3`, body, {
|
||||
async function evaluate(body: {answer: string; question: string}, task: number): Promise<AxiosResponse> {
|
||||
const backendRequest = await axios.post(`${process.env.BACKEND_URL}/speaking_task_${task}`, body, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.BACKEND_JWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (typeof backendRequest.data === "string") return evaluate(body);
|
||||
if (typeof backendRequest.data === "string") return evaluate(body, task);
|
||||
return backendRequest;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (updatedUser.status || updatedUser.type === "corporate") {
|
||||
// there's no await as this does not affect the user
|
||||
propagateStatusChange(queryId, updatedUser.status);
|
||||
propagateExpiryDateChanges(queryId, user.subscriptionExpirationDate || null, updatedUser.subscriptionExpirationDate || null);
|
||||
propagateExpiryDateChanges(queryId, user.subscriptionExpirationDate, updatedUser.subscriptionExpirationDate || null);
|
||||
}
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
|
||||
@@ -1,53 +1,39 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import Head from "next/head";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import {
|
||||
ChangeEvent,
|
||||
Dispatch,
|
||||
ReactNode,
|
||||
SetStateAction,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {ChangeEvent, Dispatch, ReactNode, SetStateAction, useEffect, useRef, useState} from "react";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import {toast, ToastContainer} from "react-toastify";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import Input from "@/components/Low/Input";
|
||||
import Button from "@/components/Low/Button";
|
||||
import Link from "next/link";
|
||||
import axios from "axios";
|
||||
import { ErrorMessage } from "@/constants/errors";
|
||||
import {ErrorMessage} from "@/constants/errors";
|
||||
import clsx from "clsx";
|
||||
import {
|
||||
CorporateUser,
|
||||
EmploymentStatus,
|
||||
EMPLOYMENT_STATUS,
|
||||
Gender,
|
||||
User,
|
||||
} from "@/interfaces/user";
|
||||
import {CorporateUser, EmploymentStatus, EMPLOYMENT_STATUS, Gender, User} from "@/interfaces/user";
|
||||
import CountrySelect from "@/components/Low/CountrySelect";
|
||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||
import moment from "moment";
|
||||
import { BsCamera, BsQuestionCircleFill } from "react-icons/bs";
|
||||
import { USER_TYPE_LABELS } from "@/resources/user";
|
||||
import {BsCamera, BsQuestionCircleFill} from "react-icons/bs";
|
||||
import {USER_TYPE_LABELS} from "@/resources/user";
|
||||
import useGroups from "@/hooks/useGroups";
|
||||
import useUsers from "@/hooks/useUsers";
|
||||
import { convertBase64 } from "@/utils";
|
||||
import { Divider } from "primereact/divider";
|
||||
import {convertBase64} from "@/utils";
|
||||
import {Divider} from "primereact/divider";
|
||||
import GenderInput from "@/components/High/GenderInput";
|
||||
import EmploymentStatusInput from "@/components/High/EmploymentStatusInput";
|
||||
import TimezoneSelect from "@/components/Low/TImezoneSelect";
|
||||
import Modal from "@/components/Modal";
|
||||
import { Module } from "@/interfaces";
|
||||
import {Module} from "@/interfaces";
|
||||
import ModuleLevelSelector from "@/components/Medium/ModuleLevelSelector";
|
||||
import Select from "@/components/Low/Select";
|
||||
import { InstructorGender } from "@/interfaces/exam";
|
||||
import { capitalize } from "lodash";
|
||||
import {InstructorGender} from "@/interfaces/exam";
|
||||
import {capitalize} from "lodash";
|
||||
import TopicModal from "@/components/Medium/TopicModal";
|
||||
import { v4 } from "uuid";
|
||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||
import {v4} from "uuid";
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
const user = req.session.user;
|
||||
|
||||
if (!user || !user.isVerified) {
|
||||
@@ -69,7 +55,7 @@ export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||
}
|
||||
|
||||
return {
|
||||
props: { user: req.session.user },
|
||||
props: {user: req.session.user},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
@@ -78,11 +64,9 @@ interface Props {
|
||||
mutateUser: Function;
|
||||
}
|
||||
|
||||
const DoubleColumnRow = ({ children }: { children: ReactNode }) => (
|
||||
<div className="flex flex-col lg:flex-row gap-8 w-full">{children}</div>
|
||||
);
|
||||
const DoubleColumnRow = ({children}: {children: ReactNode}) => <div className="flex flex-col lg:flex-row gap-8 w-full">{children}</div>;
|
||||
|
||||
function UserProfile({ user, mutateUser }: Props) {
|
||||
function UserProfile({user, mutateUser}: Props) {
|
||||
const [bio, setBio] = useState(user.bio || "");
|
||||
const [name, setName] = useState(user.name || "");
|
||||
const [email, setEmail] = useState(user.email || "");
|
||||
@@ -91,89 +75,49 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [profilePicture, setProfilePicture] = useState(user.profilePicture);
|
||||
|
||||
const [desiredLevels, setDesiredLevels] = useState<
|
||||
{ [key in Module]: number } | undefined
|
||||
>(
|
||||
["developer", "student"].includes(user.type)
|
||||
? user.desiredLevels
|
||||
: undefined,
|
||||
const [desiredLevels, setDesiredLevels] = useState<{[key in Module]: number} | undefined>(
|
||||
["developer", "student"].includes(user.type) ? user.desiredLevels : undefined,
|
||||
);
|
||||
const [focus, setFocus] = useState<"academic" | "general">(user.focus);
|
||||
|
||||
const [country, setCountry] = useState<string>(
|
||||
user.demographicInformation?.country || "",
|
||||
);
|
||||
const [phone, setPhone] = useState<string>(
|
||||
user.demographicInformation?.phone || "",
|
||||
);
|
||||
const [gender, setGender] = useState<Gender | undefined>(
|
||||
user.demographicInformation?.gender || undefined,
|
||||
);
|
||||
const [country, setCountry] = useState<string>(user.demographicInformation?.country || "");
|
||||
const [phone, setPhone] = useState<string>(user.demographicInformation?.phone || "");
|
||||
const [gender, setGender] = useState<Gender | undefined>(user.demographicInformation?.gender || undefined);
|
||||
const [employment, setEmployment] = useState<EmploymentStatus | undefined>(
|
||||
user.type === "corporate"
|
||||
? undefined
|
||||
: user.demographicInformation?.employment,
|
||||
);
|
||||
const [passport_id, setPassportID] = useState<string | undefined>(
|
||||
user.type === "student"
|
||||
? user.demographicInformation?.passport_id
|
||||
: undefined,
|
||||
user.type === "corporate" ? undefined : user.demographicInformation?.employment,
|
||||
);
|
||||
const [passport_id, setPassportID] = useState<string | undefined>(user.type === "student" ? user.demographicInformation?.passport_id : undefined);
|
||||
|
||||
const [preferredGender, setPreferredGender] = useState<
|
||||
InstructorGender | undefined
|
||||
>(
|
||||
user.type === "student" || user.type === "developer"
|
||||
? user.preferredGender || "varied"
|
||||
: undefined,
|
||||
const [preferredGender, setPreferredGender] = useState<InstructorGender | undefined>(
|
||||
user.type === "student" || user.type === "developer" ? user.preferredGender || "varied" : undefined,
|
||||
);
|
||||
const [preferredTopics, setPreferredTopics] = useState<string[] | undefined>(
|
||||
user.type === "student" || user.type === "developer"
|
||||
? user.preferredTopics
|
||||
: undefined,
|
||||
user.type === "student" || user.type === "developer" ? user.preferredTopics : undefined,
|
||||
);
|
||||
|
||||
const [position, setPosition] = useState<string | undefined>(
|
||||
user.type === "corporate"
|
||||
? user.demographicInformation?.position
|
||||
: undefined,
|
||||
);
|
||||
const [corporateInformation, setCorporateInformation] = useState(
|
||||
user.type === "corporate" ? user.corporateInformation : undefined,
|
||||
);
|
||||
const [companyName, setCompanyName] = useState<string | undefined>(
|
||||
user.type === "agent" ? user.agentInformation?.companyName : undefined,
|
||||
);
|
||||
const [commercialRegistration, setCommercialRegistration] = useState<
|
||||
string | undefined
|
||||
>(
|
||||
user.type === "agent"
|
||||
? user.agentInformation?.commercialRegistration
|
||||
: undefined,
|
||||
);
|
||||
const [arabName, setArabName] = useState<string | undefined>(
|
||||
user.type === "agent" ? user.agentInformation?.companyArabName : undefined,
|
||||
const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined);
|
||||
const [corporateInformation, setCorporateInformation] = useState(user.type === "corporate" ? user.corporateInformation : undefined);
|
||||
const [companyName, setCompanyName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyName : undefined);
|
||||
const [commercialRegistration, setCommercialRegistration] = useState<string | undefined>(
|
||||
user.type === "agent" ? user.agentInformation?.commercialRegistration : undefined,
|
||||
);
|
||||
const [arabName, setArabName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyArabName : undefined);
|
||||
|
||||
const [timezone, setTimezone] = useState<string>(
|
||||
user.demographicInformation?.timezone || moment.tz.guess(),
|
||||
);
|
||||
const [timezone, setTimezone] = useState<string>(user.demographicInformation?.timezone || moment.tz.guess());
|
||||
|
||||
const [isPreferredTopicsOpen, setIsPreferredTopicsOpen] = useState(false);
|
||||
|
||||
const { groups } = useGroups();
|
||||
const { users } = useUsers();
|
||||
const {groups} = useGroups();
|
||||
const {users} = useUsers();
|
||||
|
||||
const profilePictureInput = useRef(null);
|
||||
const expirationDateColor = (date: Date) => {
|
||||
const momentDate = moment(date);
|
||||
const today = moment(new Date());
|
||||
|
||||
if (today.add(1, "days").isAfter(momentDate))
|
||||
return "!bg-mti-red-ultralight border-mti-red-light";
|
||||
if (today.add(3, "days").isAfter(momentDate))
|
||||
return "!bg-mti-rose-ultralight border-mti-rose-light";
|
||||
if (today.add(7, "days").isAfter(momentDate))
|
||||
return "!bg-mti-orange-ultralight border-mti-orange-light";
|
||||
if (today.add(1, "days").isAfter(momentDate)) return "!bg-mti-red-ultralight border-mti-red-light";
|
||||
if (today.add(3, "days").isAfter(momentDate)) return "!bg-mti-rose-ultralight border-mti-rose-light";
|
||||
if (today.add(7, "days").isAfter(momentDate)) return "!bg-mti-orange-ultralight border-mti-orange-light";
|
||||
};
|
||||
|
||||
const uploadProfilePicture = async (event: ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -193,20 +137,15 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
}
|
||||
|
||||
if (newPassword && !password) {
|
||||
toast.error(
|
||||
"To update your password you need to input your current one!",
|
||||
);
|
||||
toast.error("To update your password you need to input your current one!");
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (email !== user?.email) {
|
||||
const userAdmins = groups
|
||||
.filter((x) => x.participants.includes(user.id))
|
||||
.map((x) => x.admin);
|
||||
const userAdmins = groups.filter((x) => x.participants.includes(user.id)).map((x) => x.admin);
|
||||
const message =
|
||||
users.filter((x) => userAdmins.includes(x.id) && x.type === "corporate")
|
||||
.length > 0
|
||||
users.filter((x) => userAdmins.includes(x.id) && x.type === "corporate").length > 0
|
||||
? "If you change your e-mail address, you will lose all benefits from your university/institute. Are you sure you want to continue?"
|
||||
: "Are you sure you want to update your e-mail address?";
|
||||
|
||||
@@ -227,6 +166,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
desiredLevels,
|
||||
preferredGender,
|
||||
preferredTopics,
|
||||
focus,
|
||||
demographicInformation: {
|
||||
phone,
|
||||
country,
|
||||
@@ -236,7 +176,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
passport_id,
|
||||
timezone,
|
||||
},
|
||||
...(user.type === "corporate" ? { corporateInformation } : {}),
|
||||
...(user.type === "corporate" ? {corporateInformation} : {}),
|
||||
...(user.type === "agent"
|
||||
? {
|
||||
agentInformation: {
|
||||
@@ -250,7 +190,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
toast.success("Your profile has been updated!");
|
||||
mutateUser((response.data as { user: User }).user);
|
||||
mutateUser((response.data as {user: User}).user);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
@@ -266,9 +206,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
|
||||
const ExpirationDate = () => (
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Expiry Date (click to purchase)
|
||||
</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Expiry Date (click to purchase)</label>
|
||||
<Link
|
||||
href="/payment"
|
||||
className={clsx(
|
||||
@@ -278,29 +216,21 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
? "!bg-mti-green-ultralight !border-mti-green-light"
|
||||
: expirationDateColor(user.subscriptionExpirationDate),
|
||||
"bg-white border-mti-gray-platinum",
|
||||
)}
|
||||
>
|
||||
)}>
|
||||
{!user.subscriptionExpirationDate && "Unlimited"}
|
||||
{user.subscriptionExpirationDate &&
|
||||
moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
||||
{user.subscriptionExpirationDate && moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
|
||||
const TimezoneInput = () => (
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Timezone
|
||||
</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Timezone</label>
|
||||
<TimezoneSelect value={timezone} onChange={setTimezone} />
|
||||
</div>
|
||||
);
|
||||
|
||||
const manualDownloadLink = ["student", "teacher", "corporate"].includes(
|
||||
user.type,
|
||||
)
|
||||
? `/manuals/${user.type}.pdf`
|
||||
: "";
|
||||
const manualDownloadLink = ["student", "teacher", "corporate"].includes(user.type) ? `/manuals/${user.type}.pdf` : "";
|
||||
|
||||
return (
|
||||
<Layout user={user}>
|
||||
@@ -309,10 +239,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
<div className="flex -md:flex-col-reverse -md:items-center w-full justify-between">
|
||||
<div className="flex flex-col gap-8 w-full md:w-2/3">
|
||||
<h1 className="text-4xl font-bold mb-6 -md:hidden">Edit Profile</h1>
|
||||
<form
|
||||
className="flex flex-col items-center gap-6 w-full"
|
||||
onSubmit={(e) => e.preventDefault()}
|
||||
>
|
||||
<form className="flex flex-col items-center gap-6 w-full" onSubmit={(e) => e.preventDefault()}>
|
||||
<DoubleColumnRow>
|
||||
{user.type !== "corporate" ? (
|
||||
<Input
|
||||
@@ -408,9 +335,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
|
||||
<DoubleColumnRow>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Country *
|
||||
</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Country *</label>
|
||||
<CountrySelect value={country} onChange={setCountry} />
|
||||
</div>
|
||||
<Input
|
||||
@@ -443,48 +368,59 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
|
||||
<Divider />
|
||||
|
||||
{desiredLevels &&
|
||||
["developer", "student"].includes(user.type) && (
|
||||
{desiredLevels && ["developer", "student"].includes(user.type) && (
|
||||
<>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Desired Levels
|
||||
</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Desired Levels</label>
|
||||
<ModuleLevelSelector
|
||||
levels={desiredLevels}
|
||||
setLevels={
|
||||
setDesiredLevels as Dispatch<
|
||||
SetStateAction<{ [key in Module]: number }>
|
||||
>
|
||||
}
|
||||
setLevels={setDesiredLevels as Dispatch<SetStateAction<{[key in Module]: number}>>}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Focus</label>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-y-4 gap-x-16 w-full">
|
||||
<button
|
||||
onClick={() => setFocus("academic")}
|
||||
className={clsx(
|
||||
"w-full border border-mti-gray-platinum rounded-full px-6 py-4 flex justify-center items-center gap-12 bg-white",
|
||||
"hover:bg-mti-purple-light hover:text-white",
|
||||
focus === "academic" && "!bg-mti-purple-light !text-white",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}>
|
||||
Academic
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setFocus("general")}
|
||||
className={clsx(
|
||||
"w-full border border-mti-gray-platinum rounded-full px-6 py-4 flex justify-center items-center gap-12 bg-white",
|
||||
"hover:bg-mti-purple-light hover:text-white",
|
||||
focus === "general" && "!bg-mti-purple-light !text-white",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}>
|
||||
General
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{preferredGender &&
|
||||
["developer", "student"].includes(user.type) && (
|
||||
{preferredGender && ["developer", "student"].includes(user.type) && (
|
||||
<>
|
||||
<Divider />
|
||||
<DoubleColumnRow>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Speaking Instructor's Gender
|
||||
</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Speaking Instructor's Gender</label>
|
||||
<Select
|
||||
value={{
|
||||
value: preferredGender,
|
||||
label: capitalize(preferredGender),
|
||||
}}
|
||||
onChange={(value) =>
|
||||
value
|
||||
? setPreferredGender(
|
||||
value.value as InstructorGender,
|
||||
)
|
||||
: null
|
||||
}
|
||||
onChange={(value) => (value ? setPreferredGender(value.value as InstructorGender) : null)}
|
||||
options={[
|
||||
{ value: "male", label: "Male" },
|
||||
{ value: "female", label: "Female" },
|
||||
{ value: "varied", label: "Varied" },
|
||||
{value: "male", label: "Male"},
|
||||
{value: "female", label: "Female"},
|
||||
{value: "varied", label: "Varied"},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
@@ -493,18 +429,12 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
Preferred Topics{" "}
|
||||
<span
|
||||
className="tooltip"
|
||||
data-tip="These topics will be considered for speaking and writing modules, aiming to include at least one exercise containing of the these in the selected exams."
|
||||
>
|
||||
data-tip="These topics will be considered for speaking and writing modules, aiming to include at least one exercise containing of the these in the selected exams.">
|
||||
<BsQuestionCircleFill />
|
||||
</span>
|
||||
</label>
|
||||
<Button
|
||||
className="w-full"
|
||||
variant="outline"
|
||||
onClick={() => setIsPreferredTopicsOpen(true)}
|
||||
>
|
||||
Select Topics ({preferredTopics?.length || "All"}{" "}
|
||||
selected)
|
||||
<Button className="w-full" variant="outline" onClick={() => setIsPreferredTopicsOpen(true)}>
|
||||
Select Topics ({preferredTopics?.length || "All"} selected)
|
||||
</Button>
|
||||
</div>
|
||||
</DoubleColumnRow>
|
||||
@@ -529,9 +459,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
name="companyUsers"
|
||||
onChange={() => null}
|
||||
label="Number of users"
|
||||
defaultValue={
|
||||
user.corporateInformation.companyInformation.userAmount
|
||||
}
|
||||
defaultValue={user.corporateInformation.companyInformation.userAmount}
|
||||
disabled
|
||||
required
|
||||
/>
|
||||
@@ -575,20 +503,14 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
</>
|
||||
)}
|
||||
|
||||
{user.type === "corporate" &&
|
||||
user.corporateInformation.referralAgent && (
|
||||
{user.type === "corporate" && user.corporateInformation.referralAgent && (
|
||||
<>
|
||||
<Divider />
|
||||
<DoubleColumnRow>
|
||||
<Input
|
||||
name="agentName"
|
||||
onChange={() => null}
|
||||
defaultValue={
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent,
|
||||
)?.name
|
||||
}
|
||||
defaultValue={users.find((x) => x.id === user.corporateInformation.referralAgent)?.name}
|
||||
type="text"
|
||||
label="Country Manager's Name"
|
||||
placeholder="Not available"
|
||||
@@ -598,12 +520,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
<Input
|
||||
name="agentEmail"
|
||||
onChange={() => null}
|
||||
defaultValue={
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent,
|
||||
)?.email
|
||||
}
|
||||
defaultValue={users.find((x) => x.id === user.corporateInformation.referralAgent)?.email}
|
||||
type="text"
|
||||
label="Country Manager's E-mail"
|
||||
placeholder="Not available"
|
||||
@@ -613,16 +530,11 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
</DoubleColumnRow>
|
||||
<DoubleColumnRow>
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Country Manager's Country *
|
||||
</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Country Manager's Country *</label>
|
||||
<CountrySelect
|
||||
value={
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id ===
|
||||
user.corporateInformation.referralAgent,
|
||||
)?.demographicInformation?.country
|
||||
users.find((x) => x.id === user.corporateInformation.referralAgent)?.demographicInformation
|
||||
?.country
|
||||
}
|
||||
onChange={() => null}
|
||||
disabled
|
||||
@@ -636,10 +548,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
onChange={() => null}
|
||||
placeholder="Not available"
|
||||
defaultValue={
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent,
|
||||
)?.demographicInformation?.phone
|
||||
users.find((x) => x.id === user.corporateInformation.referralAgent)?.demographicInformation?.phone
|
||||
}
|
||||
disabled
|
||||
required
|
||||
@@ -650,10 +559,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
|
||||
{user.type !== "corporate" && (
|
||||
<DoubleColumnRow>
|
||||
<EmploymentStatusInput
|
||||
value={employment}
|
||||
onChange={setEmployment}
|
||||
/>
|
||||
<EmploymentStatusInput value={employment} onChange={setEmployment} />
|
||||
|
||||
<div className="flex flex-col gap-8 w-full">
|
||||
<GenderInput value={gender} onChange={setGender} />
|
||||
@@ -666,62 +572,37 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
<div className="flex flex-col gap-6 w-48">
|
||||
<div
|
||||
className="flex flex-col gap-3 items-center h-fit cursor-pointer group"
|
||||
onClick={() => (profilePictureInput.current as any)?.click()}
|
||||
>
|
||||
onClick={() => (profilePictureInput.current as any)?.click()}>
|
||||
<div className="relative overflow-hidden h-48 w-48 rounded-full">
|
||||
<div
|
||||
className={clsx(
|
||||
"absolute top-0 left-0 bg-mti-purple-light/60 w-full h-full z-20 flex items-center justify-center opacity-0 group-hover:opacity-100",
|
||||
"transition ease-in-out duration-300",
|
||||
)}
|
||||
>
|
||||
)}>
|
||||
<BsCamera className="text-6xl text-mti-purple-ultralight/80" />
|
||||
</div>
|
||||
<img
|
||||
src={profilePicture}
|
||||
alt={user.name}
|
||||
className="aspect-square drop-shadow-xl self-end object-cover"
|
||||
/>
|
||||
<img src={profilePicture} alt={user.name} className="aspect-square drop-shadow-xl self-end object-cover" />
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
className="hidden"
|
||||
onChange={uploadProfilePicture}
|
||||
accept="image/*"
|
||||
ref={profilePictureInput}
|
||||
/>
|
||||
<input type="file" className="hidden" onChange={uploadProfilePicture} accept="image/*" ref={profilePictureInput} />
|
||||
<span
|
||||
onClick={() => (profilePictureInput.current as any)?.click()}
|
||||
className="cursor-pointer text-mti-purple-light text-sm"
|
||||
>
|
||||
className="cursor-pointer text-mti-purple-light text-sm">
|
||||
Change picture
|
||||
</span>
|
||||
<h6 className="font-normal text-base text-mti-gray-taupe">
|
||||
{USER_TYPE_LABELS[user.type]}
|
||||
</h6>
|
||||
<h6 className="font-normal text-base text-mti-gray-taupe">{USER_TYPE_LABELS[user.type]}</h6>
|
||||
</div>
|
||||
{user.type === "agent" && (
|
||||
<div className="flag items-center h-fit">
|
||||
<img
|
||||
alt={
|
||||
user.demographicInformation?.country.toLowerCase() + "_flag"
|
||||
}
|
||||
alt={user.demographicInformation?.country.toLowerCase() + "_flag"}
|
||||
src={`https://flagcdn.com/w320/${user.demographicInformation?.country.toLowerCase()}.png`}
|
||||
width="320"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{manualDownloadLink && (
|
||||
<a
|
||||
href={manualDownloadLink}
|
||||
className="max-w-[200px] self-end w-full"
|
||||
download
|
||||
>
|
||||
<Button
|
||||
color="purple"
|
||||
variant="outline"
|
||||
className="max-w-[200px] self-end w-full"
|
||||
>
|
||||
<a href={manualDownloadLink} className="max-w-[200px] self-end w-full" download>
|
||||
<Button color="purple" variant="outline" className="max-w-[200px] self-end w-full">
|
||||
Download Manual
|
||||
</Button>
|
||||
</a>
|
||||
@@ -740,20 +621,11 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
|
||||
<div className="self-end flex justify-between w-full gap-8 absolute bottom-8 left-0 px-8">
|
||||
<Link href="/" className="max-w-[200px] self-end w-full">
|
||||
<Button
|
||||
color="purple"
|
||||
variant="outline"
|
||||
className="max-w-[200px] self-end w-full"
|
||||
>
|
||||
<Button color="purple" variant="outline" className="max-w-[200px] self-end w-full">
|
||||
Back
|
||||
</Button>
|
||||
</Link>
|
||||
<Button
|
||||
color="purple"
|
||||
className="max-w-[200px] self-end w-full"
|
||||
onClick={updateUser}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Button color="purple" className="max-w-[200px] self-end w-full" onClick={updateUser} disabled={isLoading}>
|
||||
Save Changes
|
||||
</Button>
|
||||
</div>
|
||||
@@ -763,7 +635,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
const { user, mutateUser } = useUser({ redirectTo: "/login" });
|
||||
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -45,10 +45,11 @@ export const evaluateSpeakingAnswer = async (
|
||||
exercise: SpeakingExercise | InteractiveSpeakingExercise,
|
||||
solution: UserSolution,
|
||||
id: string,
|
||||
task: number,
|
||||
): Promise<UserSolution | undefined> => {
|
||||
switch (exercise?.type) {
|
||||
case "speaking":
|
||||
return {...(await evaluateSpeakingExercise(exercise, exercise.id, solution, id)), id} as UserSolution;
|
||||
return {...(await evaluateSpeakingExercise(exercise, exercise.id, solution, id, task)), id} as UserSolution;
|
||||
case "interactiveSpeaking":
|
||||
return {...(await evaluateInteractiveSpeakingExercise(exercise.id, solution, id)), id} as UserSolution;
|
||||
default:
|
||||
@@ -66,6 +67,7 @@ const evaluateSpeakingExercise = async (
|
||||
exerciseId: string,
|
||||
solution: UserSolution,
|
||||
id: string,
|
||||
task: number,
|
||||
): Promise<UserSolution | undefined> => {
|
||||
const formData = new FormData();
|
||||
|
||||
@@ -81,6 +83,7 @@ const evaluateSpeakingExercise = async (
|
||||
`${exercise.text.replaceAll("\n", "")}` + (exercise.prompts.length > 0 ? `You should talk about: ${exercise.prompts.join(", ")}` : "");
|
||||
formData.append("question", evaluationQuestion);
|
||||
formData.append("id", id);
|
||||
formData.append("task", task.toString());
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
|
||||
@@ -67,7 +67,7 @@ export const propagateStatusChange = (userId: string, status: UserStatus) =>
|
||||
});
|
||||
});
|
||||
|
||||
export const propagateExpiryDateChanges = (userId: string, initialExpiryDate: Date | null, subscriptionExpirationDate: Date | null) =>
|
||||
export const propagateExpiryDateChanges = (userId: string, initialExpiryDate: Date | null | undefined, subscriptionExpirationDate: Date | null) =>
|
||||
new Promise((resolve, reject) => {
|
||||
getDoc(doc(db, "users", userId))
|
||||
.then((docUser) => {
|
||||
@@ -93,6 +93,7 @@ export const propagateExpiryDateChanges = (userId: string, initialExpiryDate: Da
|
||||
.then(async (data) => {
|
||||
const filtered = data.filter((x) => {
|
||||
if (x === null) return false;
|
||||
if (!x.subscriptionExpirationDate && !initialExpiryDate) return true;
|
||||
if (x.subscriptionExpirationDate !== initialExpiryDate) return false;
|
||||
return true;
|
||||
}) as User[];
|
||||
|
||||
Reference in New Issue
Block a user