diff --git a/package.json b/package.json index 0b92e7ff..b8266c65 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "formidable": "^3.5.0", "formidable-serverless": "^1.1.1", "framer-motion": "^9.0.2", + "howler": "^2.2.4", "iron-session": "^6.3.1", "lodash": "^4.17.21", "moment": "^2.29.4", @@ -73,6 +74,7 @@ }, "devDependencies": { "@types/formidable": "^3.4.0", + "@types/howler": "^2.2.11", "@types/lodash": "^4.14.191", "@types/nodemailer": "^6.4.11", "@types/nodemailer-express-handlebars": "^4.0.3", diff --git a/public/audio/check.mp3 b/public/audio/check.mp3 new file mode 100644 index 00000000..dde3b8af Binary files /dev/null and b/public/audio/check.mp3 differ diff --git a/public/audio/sent.mp3 b/public/audio/sent.mp3 new file mode 100644 index 00000000..49bfa573 Binary files /dev/null and b/public/audio/sent.mp3 differ diff --git a/src/components/DemographicInformationInput.tsx b/src/components/DemographicInformationInput.tsx index dcbe16bf..222dc546 100644 --- a/src/components/DemographicInformationInput.tsx +++ b/src/components/DemographicInformationInput.tsx @@ -21,6 +21,7 @@ export default function DemographicInformationInput({user, mutateUser}: Props) { const [phone, setPhone] = useState(); const [gender, setGender] = useState(); const [employment, setEmployment] = useState(); + const [position, setPosition] = useState(); const [isLoading, setIsLoading] = useState(false); const [companyName, setCompanyName] = useState(); @@ -36,7 +37,8 @@ export default function DemographicInformationInput({user, mutateUser}: Props) { country, phone: `+${countryCodes.findOne("countryCode" as any, country!).countryCallingCode}${phone}`, gender, - employment, + employment: user.type === "corporate" ? undefined : employment, + position: user.type === "corporate" ? position : undefined, }, agentInformation: user.type === "agent" ? {companyName, commercialRegistration} : undefined, }) @@ -116,25 +118,32 @@ export default function DemographicInformationInput({user, mutateUser}: Props) { -
- - - {EMPLOYMENT_STATUS.map(({status, label}) => ( - - {({checked}) => ( - - {label} - - )} - - ))} - -
+ {user.type === "corporate" && ( + + )} + {user.type !== "corporate" && ( +
+ + + {EMPLOYMENT_STATUS.map(({status, label}) => ( + + {({checked}) => ( + + {label} + + )} + + ))} + +
+ )}
@@ -147,7 +156,7 @@ export default function DemographicInformationInput({user, mutateUser}: Props) { !country || !phone || !gender || - !employment || + (user.type === "corporate" ? !position : !employment) || (user.type === "agent" ? !companyName || !commercialRegistration : false) }> {!isLoading && "Save information"} diff --git a/src/components/UserCard.tsx b/src/components/UserCard.tsx index d1cb6209..931fe24a 100644 --- a/src/components/UserCard.tsx +++ b/src/components/UserCard.tsx @@ -42,6 +42,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers}: const [type, setType] = useState(user.type); const [status, setStatus] = useState(user.status); const [referralAgentLabel, setReferralAgentLabel] = useState(); + const [position, setPosition] = useState(user.type === "corporate" ? user.demographicInformation?.position : undefined); const [referralAgent, setReferralAgent] = useState(user.type === "corporate" ? user.corporateInformation?.referralAgent : undefined); const [companyName, setCompanyName] = useState( @@ -177,11 +178,11 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers}: defaultValue={companyName} /> setUserAmount(e ? parseInt(e) : undefined)} - placeholder="Enter amount of users" + placeholder="Enter number of users" defaultValue={userAmount} /> setMonthlyDuration(e ? parseInt(e) : undefined)} placeholder="Enter monthly duration" - defaultValue={userAmount} + defaultValue={monthlyDuration} />
@@ -292,29 +293,43 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers}:
-
- - - {EMPLOYMENT_STATUS.map(({status, label}) => ( - - {({checked}) => ( - - {label} - - )} - - ))} - -
+ {user.type !== "corporate" && ( +
+ + + {EMPLOYMENT_STATUS.map(({status, label}) => ( + + {({checked}) => ( + + {label} + + )} + + ))} + +
+ )} + {user.type === "corporate" && ( + + )}
diff --git a/src/interfaces/user.ts b/src/interfaces/user.ts index 3e223fca..5594f273 100644 --- a/src/interfaces/user.ts +++ b/src/interfaces/user.ts @@ -14,7 +14,6 @@ export interface BasicUser { type: Type; bio: string; isVerified: boolean; - demographicInformation?: DemographicInformation; subscriptionExpirationDate?: null | Date; registrationDate?: Date; status: "active" | "disabled" | "paymentDue"; @@ -22,28 +21,34 @@ export interface BasicUser { export interface StudentUser extends BasicUser { type: "student"; + demographicInformation?: DemographicInformation; } export interface TeacherUser extends BasicUser { type: "teacher"; + demographicInformation?: DemographicInformation; } export interface CorporateUser extends BasicUser { type: "corporate"; corporateInformation: CorporateInformation; + demographicInformation?: DemographicCorporateInformation; } export interface AgentUser extends BasicUser { type: "agent"; agentInformation: AgentInformation; + demographicInformation?: DemographicInformation; } export interface AdminUser extends BasicUser { type: "admin"; + demographicInformation?: DemographicInformation; } export interface DeveloperUser extends BasicUser { type: "developer"; + demographicInformation?: DemographicInformation; } export interface CorporateInformation { @@ -73,6 +78,13 @@ export interface DemographicInformation { employment: EmploymentStatus; } +export interface DemographicCorporateInformation { + country: string; + phone: string; + gender: Gender; + position: string; +} + export type Gender = "male" | "female" | "other"; export type EmploymentStatus = "employed" | "student" | "self-employed" | "unemployed" | "retired" | "other"; export const EMPLOYMENT_STATUS: {status: EmploymentStatus; label: string}[] = [ diff --git a/src/pages/(admin)/Lists/UserList.tsx b/src/pages/(admin)/Lists/UserList.tsx index 790fc686..7ed40bee 100644 --- a/src/pages/(admin)/Lists/UserList.tsx +++ b/src/pages/(admin)/Lists/UserList.tsx @@ -242,14 +242,15 @@ export default function UserList({user, filter}: {user: User; filter?: (user: Us cell: (info) => info.getValue() || "Not available", enableSorting: true, }), - columnHelper.accessor("demographicInformation.employment", { + columnHelper.accessor((x) => (x.type === "corporate" ? x.demographicInformation?.position : x.demographicInformation?.employment), { + id: "employment", header: ( ) as any, - cell: (info) => capitalize(info.getValue()) || "Not available", + cell: (info) => (info.row.original.type === "corporate" ? info.getValue() : capitalize(info.getValue())) || "Not available", enableSorting: true, }), columnHelper.accessor("demographicInformation.gender", { @@ -419,13 +420,14 @@ export default function UserList({user, filter}: {user: User; filter?: (user: Us } if (sorter === "employment" || sorter === reverseString("employment")) { - if (!a.demographicInformation?.employment && b.demographicInformation?.employment) return sorter === "employment" ? -1 : 1; - if (a.demographicInformation?.employment && !b.demographicInformation?.employment) return sorter === "employment" ? 1 : -1; - if (!a.demographicInformation?.employment && !b.demographicInformation?.employment) return 0; + const aSortingItem = a.type === "corporate" ? a.demographicInformation?.position : a.demographicInformation?.employment; + const bSortingItem = b.type === "corporate" ? b.demographicInformation?.position : b.demographicInformation?.employment; - return sorter === "employment" - ? a.demographicInformation!.employment.localeCompare(b.demographicInformation!.employment) - : b.demographicInformation!.employment.localeCompare(a.demographicInformation!.employment); + if (!aSortingItem && bSortingItem) return sorter === "employment" ? -1 : 1; + if (aSortingItem && !bSortingItem) return sorter === "employment" ? 1 : -1; + if (!aSortingItem && !bSortingItem) return 0; + + return sorter === "employment" ? aSortingItem!.localeCompare(bSortingItem!) : bSortingItem!.localeCompare(aSortingItem!); } if (sorter === "gender" || sorter === reverseString("gender")) { diff --git a/src/pages/(generation)/LevelGeneration.tsx b/src/pages/(generation)/LevelGeneration.tsx index 52e81c5a..1b02373d 100644 --- a/src/pages/(generation)/LevelGeneration.tsx +++ b/src/pages/(generation)/LevelGeneration.tsx @@ -1,6 +1,7 @@ import {LevelExam, MultipleChoiceExercise} from "@/interfaces/exam"; import useExamStore from "@/stores/examStore"; import {getExamById} from "@/utils/exams"; +import {playSound} from "@/utils/sound"; import {Tab} from "@headlessui/react"; import axios from "axios"; import clsx from "clsx"; @@ -18,6 +19,7 @@ const TaskTab = ({exam, setExam}: {exam?: LevelExam; setExam: (exam: LevelExam) axios .get(`/api/exam/level/generate/level`) .then((result) => { + playSound("check"); console.log(result.data); setExam(result.data); }) @@ -135,6 +137,7 @@ const LevelGeneration = () => { axios .post(`/api/exam/level`, exam) .then((result) => { + playSound("sent"); console.log(`Generated Exam ID: ${result.data.id}`); toast.success("This new exam has been generated successfully! Check the ID in our browser's console."); setResultingExam(result.data); diff --git a/src/pages/(generation)/ListeningGeneration.tsx b/src/pages/(generation)/ListeningGeneration.tsx index e0a6b012..143d7223 100644 --- a/src/pages/(generation)/ListeningGeneration.tsx +++ b/src/pages/(generation)/ListeningGeneration.tsx @@ -1,9 +1,13 @@ import Input from "@/components/Low/Input"; -import {ListeningPart} from "@/interfaces/exam"; +import {Exercise, ListeningExam} from "@/interfaces/exam"; +import useExamStore from "@/stores/examStore"; +import {getExamById} from "@/utils/exams"; +import {playSound} from "@/utils/sound"; import {convertCamelCaseToReadable} from "@/utils/string"; import {Tab} from "@headlessui/react"; import axios from "axios"; import clsx from "clsx"; +import {useRouter} from "next/router"; import {useState} from "react"; import {BsArrowRepeat} from "react-icons/bs"; import {toast} from "react-toastify"; @@ -20,8 +24,11 @@ const PartTab = ({part, types, index, setPart}: {part?: ListeningPart; types: st setPart(undefined); setIsLoading(true); axios - .get(`/api/exam/listening/generate/listening_passage_${index}${topic || types ? `?${url.toString()}` : ""}`) - .then((result) => setPart(result.data)) + .get(`/api/exam/listening/generate/listening_section_${index}${topic || types ? `?${url.toString()}` : ""}`) + .then((result) => { + playSound("check"); + setPart(result.data); + }) .catch((error) => { console.log(error); toast.error("Something went wrong!"); @@ -67,27 +74,101 @@ const PartTab = ({part, types, index, setPart}: {part?: ListeningPart; types: st ))}
+ {typeof part.text === "string" && {part.text.replaceAll("\n\n", " ")}} + {typeof part.text !== "string" && ( +
+ {part.text.conversation.map((x, index) => ( + + {x.name}: + {x.text.replaceAll("\n\n", " ")} + + ))} +
+ )}
)} ); }; +interface ListeningPart { + exercises: Exercise[]; + text: + | { + conversation: { + gender: string; + name: string; + text: string; + voice: string; + }[]; + } + | string; +} + const ListeningGeneration = () => { const [part1, setPart1] = useState(); const [part2, setPart2] = useState(); const [part3, setPart3] = useState(); + const [part4, setPart4] = useState(); + const [isLoading, setIsLoading] = useState(false); + const [resultingExam, setResultingExam] = useState(); const [types, setTypes] = useState([]); const availableTypes = [ - {type: "fillBlanks", label: "Fill the Blanks"}, {type: "multipleChoice", label: "Multiple Choice"}, - {type: "trueFalse", label: "True or False"}, - {type: "writeBlanks", label: "Write the Blanks"}, + {type: "writeBlanksQuestions", label: "Write the Blanks: Questions"}, + {type: "writeBlanksFill", label: "Write the Blanks: Fill"}, + {type: "writeBlanksForm", label: "Write the Blanks: Form"}, ]; + const router = useRouter(); + + const setExams = useExamStore((state) => state.setExams); + const setSelectedModules = useExamStore((state) => state.setSelectedModules); + const toggleType = (type: string) => setTypes((prev) => (prev.includes(type) ? [...prev.filter((x) => x !== type)] : [...prev, type])); + const submitExam = () => { + if (!part1 || !part2 || !part3 || !part4) return toast.error("Please generate all for sections!"); + + setIsLoading(true); + + axios + .post(`/api/exam/listening/generate/listening`, {parts: [part1, part2, part3, part4]}) + .then((result) => { + playSound("sent"); + console.log(`Generated Exam ID: ${result.data.id}`); + toast.success("This new exam has been generated successfully! Check the ID in our browser's console."); + setResultingExam(result.data); + + setPart1(undefined); + setPart2(undefined); + setPart3(undefined); + setTypes([]); + }) + .catch((error) => { + console.log(error); + toast.error("Something went wrong!"); + }) + .finally(() => setIsLoading(false)); + }; + + const loadExam = async (examId: string) => { + const exam = await getExamById("listening", examId.trim()); + if (!exam) { + toast.error("Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID", { + toastId: "invalid-exam-id", + }); + + return; + } + + setExams([exam]); + setSelectedModules(["listening"]); + + router.push("/exercises"); + }; + return ( <>
@@ -121,7 +202,7 @@ const ListeningGeneration = () => { selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-listening", ) }> - Passage 1 + Section 1 @@ -132,7 +213,7 @@ const ListeningGeneration = () => { selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-listening", ) }> - Passage 2 + Section 2 @@ -143,7 +224,18 @@ const ListeningGeneration = () => { selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-listening", ) }> - Passage 3 + Section 3 + + + clsx( + "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-listening/70", + "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-listening focus:outline-none focus:ring-2", + "transition duration-300 ease-in-out", + selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-listening", + ) + }> + Section 4 @@ -151,22 +243,44 @@ const ListeningGeneration = () => { {part: part1, setPart: setPart1}, {part: part2, setPart: setPart2}, {part: part3, setPart: setPart3}, + {part: part4, setPart: setPart4}, ].map(({part, setPart}, index) => ( ))} - +
+ {resultingExam && ( + + )} + +
); }; diff --git a/src/pages/(generation)/ReadingGeneration.tsx b/src/pages/(generation)/ReadingGeneration.tsx index fd293a79..cbc49d15 100644 --- a/src/pages/(generation)/ReadingGeneration.tsx +++ b/src/pages/(generation)/ReadingGeneration.tsx @@ -2,6 +2,7 @@ import Input from "@/components/Low/Input"; import {ReadingExam, ReadingPart} from "@/interfaces/exam"; import useExamStore from "@/stores/examStore"; import {getExamById} from "@/utils/exams"; +import {playSound} from "@/utils/sound"; import {convertCamelCaseToReadable} from "@/utils/string"; import {Tab} from "@headlessui/react"; import axios from "axios"; @@ -25,7 +26,10 @@ const PartTab = ({part, types, index, setPart}: {part?: ReadingPart; types: stri setIsLoading(true); axios .get(`/api/exam/reading/generate/reading_passage_${index}${topic || types ? `?${url.toString()}` : ""}`) - .then((result) => setPart(result.data)) + .then((result) => { + playSound("check"); + setPart(result.data); + }) .catch((error) => { console.log(error); toast.error("Something went wrong!"); @@ -136,6 +140,7 @@ const ReadingGeneration = () => { axios .post(`/api/exam/reading`, exam) .then((result) => { + playSound("sent"); console.log(`Generated Exam ID: ${result.data.id}`); toast.success("This new exam has been generated successfully! Check the ID in our browser's console."); setResultingExam(result.data); diff --git a/src/pages/(generation)/SpeakingGeneration.tsx b/src/pages/(generation)/SpeakingGeneration.tsx new file mode 100644 index 00000000..3a10cb48 --- /dev/null +++ b/src/pages/(generation)/SpeakingGeneration.tsx @@ -0,0 +1,234 @@ +import Input from "@/components/Low/Input"; +import {Exercise, SpeakingExam} from "@/interfaces/exam"; +import useExamStore from "@/stores/examStore"; +import {getExamById} from "@/utils/exams"; +import {playSound} from "@/utils/sound"; +import {convertCamelCaseToReadable} from "@/utils/string"; +import {Tab} from "@headlessui/react"; +import axios from "axios"; +import clsx from "clsx"; +import {useRouter} from "next/router"; +import {useState} from "react"; +import {BsArrowRepeat} from "react-icons/bs"; +import {toast} from "react-toastify"; + +const PartTab = ({part, index, setPart}: {part?: SpeakingPart; index: number; setPart: (part?: SpeakingPart) => void}) => { + const [isLoading, setIsLoading] = useState(false); + + const generate = () => { + setPart(undefined); + setIsLoading(true); + axios + .get(`/api/exam/speaking/generate/speaking_task_${index}`) + .then((result) => { + playSound("check"); + setPart(result.data); + }) + .catch((error) => { + console.log(error); + toast.error("Something went wrong!"); + }) + .finally(() => setIsLoading(false)); + }; + + return ( + +
+ +
+ {isLoading && ( +
+ + Generating... +
+ )} + {part && ( +
+

{part.topic}

+ {part.question && {part.question}} + {part.questions && ( +
+ {part.questions.map((question, index) => ( + + - {question} + + ))} +
+ )} + {part.prompts && ( +
+ You should talk about the following things: + {part.prompts.map((prompt, index) => ( + + - {prompt} + + ))} +
+ )} +
+ )} +
+ ); +}; + +interface SpeakingPart { + prompts?: string[]; + question?: string; + questions?: string[]; + topic: string; +} + +const SpeakingGeneration = () => { + const [part1, setPart1] = useState(); + const [part2, setPart2] = useState(); + const [part3, setPart3] = useState(); + const [isLoading, setIsLoading] = useState(false); + const [resultingExam, setResultingExam] = useState(); + + const router = useRouter(); + + const setExams = useExamStore((state) => state.setExams); + const setSelectedModules = useExamStore((state) => state.setSelectedModules); + + const submitExam = () => { + if (!part1 || !part2 || !part3) return toast.error("Please generate all for tasks!"); + + setIsLoading(true); + + axios + .post(`/api/exam/speaking/generate/speaking`, {exercises: [part1, part2, part3]}) + .then((result) => { + playSound("sent"); + console.log(`Generated Exam ID: ${result.data.id}`); + toast.success("This new exam has been generated successfully! Check the ID in our browser's console."); + setResultingExam(result.data); + + setPart1(undefined); + setPart2(undefined); + setPart3(undefined); + }) + .catch((error) => { + console.log(error); + toast.error("Something went wrong!"); + }) + .finally(() => setIsLoading(false)); + }; + + const loadExam = async (examId: string) => { + const exam = await getExamById("speaking", examId.trim()); + if (!exam) { + toast.error("Unknown Exam ID! Please make sure you selected the right module and entered the right exam ID", { + toastId: "invalid-exam-id", + }); + + return; + } + + setExams([exam]); + setSelectedModules(["speaking"]); + + router.push("/exercises"); + }; + + return ( + <> + + + + clsx( + "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-speaking/70", + "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-speaking focus:outline-none focus:ring-2", + "transition duration-300 ease-in-out", + selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-speaking", + ) + }> + Task 1 + + + clsx( + "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-speaking/70", + "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-speaking focus:outline-none focus:ring-2", + "transition duration-300 ease-in-out", + selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-speaking", + ) + }> + Task 2 + + + clsx( + "w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-ielts-speaking/70", + "ring-white ring-opacity-60 ring-offset-2 ring-offset-ielts-speaking focus:outline-none focus:ring-2", + "transition duration-300 ease-in-out", + selected ? "bg-white shadow" : "text-blue-100 hover:bg-white/[0.12] hover:text-ielts-speaking", + ) + }> + Task 3 + + + + {[ + {part: part1, setPart: setPart1}, + {part: part2, setPart: setPart2}, + {part: part3, setPart: setPart3}, + ].map(({part, setPart}, index) => ( + + ))} + + +
+ {resultingExam && ( + + )} + +
+ + ); +}; + +export default SpeakingGeneration; diff --git a/src/pages/(generation)/WritingGeneration.tsx b/src/pages/(generation)/WritingGeneration.tsx index e528bd9e..18e5ae2b 100644 --- a/src/pages/(generation)/WritingGeneration.tsx +++ b/src/pages/(generation)/WritingGeneration.tsx @@ -2,6 +2,7 @@ import Input from "@/components/Low/Input"; import {WritingExam} from "@/interfaces/exam"; import useExamStore from "@/stores/examStore"; import {getExamById} from "@/utils/exams"; +import {playSound} from "@/utils/sound"; import {Tab} from "@headlessui/react"; import axios from "axios"; import clsx from "clsx"; @@ -18,7 +19,10 @@ const TaskTab = ({task, index, setTask}: {task?: string; index: number; setTask: setIsLoading(true); axios .get(`/api/exam/writing/generate/writing_task${index}_general`) - .then((result) => setTask(result.data.question)) + .then((result) => { + playSound("check"); + setTask(result.data.question); + }) .catch((error) => { console.log(error); toast.error("Something went wrong!"); @@ -132,6 +136,7 @@ const WritingGeneration = () => { .post(`/api/exam/writing`, exam) .then((result) => { console.log(`Generated Exam ID: ${result.data.id}`); + playSound("sent"); toast.success("This new exam has been generated successfully! Check the ID in our browser's console."); setResultingExam(result.data); diff --git a/src/pages/api/exam/[module]/generate/[endpoint].ts b/src/pages/api/exam/[module]/generate/[endpoint].ts index 1a6b4118..a84a3933 100644 --- a/src/pages/api/exam/[module]/generate/[endpoint].ts +++ b/src/pages/api/exam/[module]/generate/[endpoint].ts @@ -15,15 +15,15 @@ const db = getFirestore(app); export default withIronSessionApiRoute(handler, sessionOptions); async function handler(req: NextApiRequest, res: NextApiResponse) { - if (!req.session.user) { - res.status(401).json({ok: false}); - return; - } + if (req.method === "GET") return get(req, res); + if (req.method === "POST") return post(req, res); - if (req.session.user.type !== "developer") { - res.status(403).json({ok: false}); - return; - } + return res.status(404).json({ok: false}); +} + +async function get(req: NextApiRequest, res: NextApiResponse) { + if (!req.session.user) return res.status(401).json({ok: false}); + if (req.session.user.type !== "developer") return res.status(403).json({ok: false}); const {endpoint, topic, exercises} = req.query as {module: Module; endpoint: string; topic?: string; exercises?: string[]}; const url = `${process.env.BACKEND_URL}/${endpoint}`; @@ -34,3 +34,21 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { res.status(200).json(result.data); } + +async function post(req: NextApiRequest, res: NextApiResponse) { + if (!req.session.user) return res.status(401).json({ok: false}); + if (req.session.user.type !== "developer") return res.status(403).json({ok: false}); + + const {endpoint, topic, exercises} = req.query as {module: Module; endpoint: string; topic?: string; exercises?: string[]}; + const url = `${process.env.BACKEND_URL}/${endpoint}`; + + const result = await axios.post( + `${url}${topic && exercises ? `?topic=${topic.toLowerCase()}&exercises=${exercises.join("&exercises=")}` : ""}`, + req.body, + { + headers: {Authorization: `Bearer ${process.env.BACKEND_JWT}`}, + }, + ); + + res.status(200).json(result.data); +} diff --git a/src/pages/generation.tsx b/src/pages/generation.tsx index 62828726..cd905767 100644 --- a/src/pages/generation.tsx +++ b/src/pages/generation.tsx @@ -20,6 +20,7 @@ import ReadingGeneration from "./(generation)/ReadingGeneration"; import ListeningGeneration from "./(generation)/ListeningGeneration"; import WritingGeneration from "./(generation)/WritingGeneration"; import LevelGeneration from "./(generation)/LevelGeneration"; +import SpeakingGeneration from "./(generation)/SpeakingGeneration"; export const getServerSideProps = withIronSessionSsr(({req, res}) => { const user = req.session.user; @@ -115,6 +116,7 @@ export default function Generation() { {module === "reading" && } {module === "listening" && } {module === "writing" && } + {module === "speaking" && } {module === "level" && } )} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index bc6d44af..0e19d918 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -68,7 +68,7 @@ export default function Home({envVariables}: {envVariables: {[key: string]: stri useEffect(() => { if (user) { setShowDemographicInput(!user.demographicInformation); - setShowDiagnostics(user.isFirstLogin); + setShowDiagnostics(user.isFirstLogin && user.type === "student"); } }, [user]); diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx index c41248d9..b9aa8289 100644 --- a/src/pages/profile.tsx +++ b/src/pages/profile.tsx @@ -63,6 +63,7 @@ export default function Home() { const [phone, setPhone] = useState(); const [gender, setGender] = useState(); const [employment, setEmployment] = useState(); + const [position, setPosition] = useState(); const profilePictureInput = useRef(null); @@ -86,7 +87,8 @@ export default function Home() { setCountry(user.demographicInformation?.country); setPhone(user.demographicInformation?.phone); setGender(user.demographicInformation?.gender); - setEmployment(user.demographicInformation?.employment); + setEmployment(user.type === "corporate" ? undefined : user.demographicInformation?.employment); + setPosition(user.type === "corporate" ? user.demographicInformation?.position : undefined); } }, [user]); @@ -135,7 +137,8 @@ export default function Home() { demographicInformation: { phone, country, - employment, + employment: user?.type === "corporate" ? undefined : employment, + position: user?.type === "corporate" ? position : undefined, gender, }, }); @@ -247,30 +250,43 @@ export default function Home() { />
-
- - - {EMPLOYMENT_STATUS.map(({status, label}) => ( - - {({checked}) => ( - - {label} - - )} - - ))} - -
+ {user.type === "corporate" && ( + + )} + {user.type !== "corporate" && ( +
+ + + {EMPLOYMENT_STATUS.map(({status, label}) => ( + + {({checked}) => ( + + {label} + + )} + + ))} + +
+ )}
diff --git a/src/utils/sound.ts b/src/utils/sound.ts new file mode 100644 index 00000000..d4bc5a84 --- /dev/null +++ b/src/utils/sound.ts @@ -0,0 +1,10 @@ +import {Howl, Howler} from "howler"; + +export type Sound = "check" | "sent"; +export const playSound = (path: Sound) => { + const sound = new Howl({ + src: [`audio/${path}.mp3`], + }); + + sound.play(); +}; diff --git a/yarn.lock b/yarn.lock index 4d9d4192..6b4aa13c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1144,6 +1144,11 @@ "@types/minimatch" "^5.1.2" "@types/node" "*" +"@types/howler@^2.2.11": + version "2.2.11" + resolved "https://registry.yarnpkg.com/@types/howler/-/howler-2.2.11.tgz#a75c4ab5666aee5fcfbd5de15d35dbaaa3d3f070" + integrity sha512-7aBoUL6RbSIrqKnpEgfa1wSNUBK06mn08siP2QI0zYk7MXfEJAaORc4tohamQYqCqVESoDyRWSdQn2BOKWj2Qw== + "@types/http-assert@*": version "1.5.3" resolved "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.3.tgz" @@ -3149,6 +3154,11 @@ hoist-non-react-statics@^3.3.1: dependencies: react-is "^16.7.0" +howler@^2.2.4: + version "2.2.4" + resolved "https://registry.yarnpkg.com/howler/-/howler-2.2.4.tgz#bd3df4a4f68a0118a51e4bd84a2bfc2e93e6e5a1" + integrity sha512-iARIBPgcQrwtEr+tALF+rapJ8qSc+Set2GJQl7xT1MQzWaVkFebdJhR3alVlSiUf5U7nAANKuj3aWpwerocD5w== + http-parser-js@>=0.5.1: version "0.5.8" resolved "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.8.tgz"