diff --git a/src/constants/serviceAccountKey.json b/src/constants/serviceAccountKey.json index 7022844b..2e8fe016 100644 --- a/src/constants/serviceAccountKey.json +++ b/src/constants/serviceAccountKey.json @@ -1,13 +1,13 @@ { "type": "service_account", - "project_id": "mti-ielts", - "private_key_id": "22b783a14c760d1215a8d1f5de0fa40a33a840e7", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDoNkd7s/izUBRb\nlmJYWl0xk4X9wEVJU4LKA4HPeha8RFDse4T4suVP08oCP9ODSXF5A83+IqXNMs/N\na7PtFABBAx433JrB7I4NsAUrDSjI4LeYEIqh6YzHsQvBU53HAmPChX525S4i0IBy\ncNnyXut0nmlHz5ZwCPXgqg4eN44C+m0f7sxzivcnPth/zLupnMiDAHFZrxQolWO2\n6JfozMWGw0TmCkUxngzeGBMVYmsGiKRIxEi3MWeuwjYjGO4nR1krEUlcpjCbx4UX\nxYXicJb17HOs9LTcSh9bpDWZPHKXR48hxd2cMLr+XQzw7Otwu2p8fEUOJ+CiTyNz\nlkN9p7OhAgMBAAECggEAB5DsMZdGu1X4wdazr+AK4RCG2UKkZ0wbqvgkCMX4O2xo\n7BmmtqFCmEAk+P+KJWEVW81wTu9jUl0tWOrBVzBThUrEF2seVkL+SmshsfpI6cmr\npb5lO/sTgZau1L7kGU3GQRpvKVHUl+EODFyJt2xZFOjL8qFsjAw4sbgsw1aJT6a4\nFilm6Gapi1qSKOPSlXVmi0NJ9DUtNbKaQK8/coqEJRizeXs9MORvzyKQaV8PBmWI\noEnkxahKOD48U2kmI7rT9/YsCuaP2BlGdLxvANXLjAKcrDccVZkYEH82tPtCicED\noow3i956HPdWSXQgUOU65MfGccjOmqGaGa4zUTICyQKBgQD6zLMwL9YS+n9EKZaK\nEbzRybN2d+eKbXyDJzkDi6FnSGVre2ndShsimoOtwZDLmOF/XhN79YOLJVbI124p\npAWO+WxAfe9Xy3iFEBmL4kSREA873Sd8EN5OfYS2DsN7IbjZkoaLuM8QlyXL9ZRS\nBJDVGjx+wFKRjnClcBNbVMMXiQKBgQDtBumKZS0ZCtJuBeuwLGJ1ZJtYECykIrsD\nUtQ7zxwXJzPGqZ2c5JLpHdDm/bb9nllpLsh4SpDRqxFa2H2FF8x5KWaS7JQUsS8e\ner6x5wUt6wAJqV/ZvttVrLZCa8VYn+K7bTANnkPNJZHTqBTJbxkXMDTtkwWXUN2z\nQP3N9lodWQKBgFBHiewYw9ubV3WIImnbt6cne0ymoPUMitioi3V5Epcu81fuTzrI\nZ9sxvoi19xVUwIm2oWICerLlptvvKZImsKjNajtSlHRz6wYc2zCNowkULOwqpGLw\nO1jAkOR94VDewH7UikDbTVywJSceWvXOBFZSaZ7hDQ0OnTw3ndqUTUaRAoGAd2BG\n2PPyDa28o7sJpBYGlJdSAb1LrnLre1YJHAJIZITS99hPUEhykUP6BYx80CkjYO01\n/BeZ7m9Y80cbmJ+O1Or8BT1vqyg90f0B8/mlSyYTQ8pxQupz7ydoN/WtU+BawgjQ\n7drqzPSCCHab2YPBwEMANTMZ2sbYkcJG0aekZSkCgYBbnFJm8kUy57isxHyvrci+\nR30KQl2Y9okPytF8PpLH+yNjLDoduTOHL/hZoFC0M4Gklx4wPKpsEhImIrWmG9VC\n0UrQC6TT1WoY6/S3YehVmTXo/nBPD1XTUcbF/xxUrWDjmMjnt1IlXBbIzUPD3U4P\niRXzHnXb7yi+/iRxSDts2w==\n-----END PRIVATE KEY-----\n", - "client_email": "firebase-adminsdk-dyg6p@mti-ielts.iam.gserviceaccount.com", - "client_id": "104980563453519094431", + "project_id": "storied-phalanx-349916", + "private_key_id": "c9e05f6fe413b1031a71f981160075ff4b044444", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDdgavFB63nMHyb\n38ncwijTrUmqU9UyzNJ8wlZCWAWuoz25Gng988fkKNDXnHY+ap9esHyNYg9IdSA7\nAuZeHpzTZmKiWZzFWq61KWSTgIn1JwKHGHJJdmVhTYfCe9I51cFLa5q2lTFzJ0ce\nbP7/X/7kw53odgva+M8AhDTbe60akpemgZc+LFwO0Abm7erH2HiNyjoNZzNw525L\n933PCaQwhZan04s1u0oRdVlBIBwMk+J0ojgVEpUiJOzF7gkN+UpDXujalLYdlR4q\nhkGgScXQhDYJkECC3GuvOnEo1YXGNjW9D73S6sSH+Lvqta4wW1+sTn0kB6goiQBI\n7cA1G6x3AgMBAAECggEAZPMwAX/adb7XS4LWUNH8IVyccg/63kgSteErxtiu3kRv\nYOj7W+C6fPVNGLap/RBCybjNSvIh3PfkVICh1MtG1eGXmj4VAKyvaskOmVq/hQbe\nVAuEKo7W7V2UPcKIsOsGSQUlYYjlHIIOG4O5Q1HQrRmp4cPK62Txkl6uaEkZPz4u\nbvIK2BJI8aHRwxE3Phw09blwlLqQQQ8nrhK29x5puaN+ft++IlzIOVsLz+n4kTdB\n6qkG/dhenn3K8o3+NkmSN6eNRbdJd36zXTo4Oatbvqb7r0E8vYn/3Llawo2X75zn\nec7jMHrOmcwtiu9H3PsrTWtzdSjxPHy0UtEn1HWK4QKBgQD+c/V8tAvbaUGVoZf6\ntKtDSKF6IHuY2vUO33v950mVdjrTursqOG2d+SLfSnKpc+sjDlj7/S5u4uRP+qUN\ng1rb2U7oIA7tsDa2ZTSkIx6HkPUzS+fBOxELLrbgMoJ2RLzgkiPhS95YgXJ/rYG5\nWQTehzCT5roes0RvtgM0gl3EhQKBgQDe2m7PRIU4g3RJ8HTx92B4ja8W9FVCYDG5\nPOAdZB8WB6Bvu4BJHBDLr8vDi930pKj+vYObRqBDQuILW4t8wZQJ834dnoq6EpUz\nhbVEURVBP4A/nEHrQHfq0Lp+cxThy2rw7obRQOLPETtC7p3WFgSHT6PRTcpGzCCX\n+76a30yrywKBgC/5JNtyBppDaf4QDVtTHMb+tpMT9LmI7pLzR6lDJfhr5gNtPURk\nhyY1hoGaw6t3E2n0lopL3alCVdFObDfz//lbKylQggAGLQqOYjJf/K2KgvA862Df\nBgOZtxjl7PrnUsT0SJd9elotbazsxXxwcB6UVnBMG+MV4V0+b7RCr/MRAoGBAIfp\nTcVIs7roqOZjKN9dEE/VkR/9uXW2tvyS/NfP9Ql5c0ZRYwazgCbJOwsyZRZLyek6\naWYsp5b91mA435QhdwiuoI6t30tmA+qdNBTLIpxdfvjMcoNoGPpzfBmcU/L1HW58\n+mnqGalRiAPlBQvI99ASKQWAXMnaulIWrYNEhj0LAoGBALi+QZ2pp+hDeC59ezWr\nbP1zbbONceHKGgJcevChP2k1OJyIOIqmBYeTuM4cPc5ofZYQNaMC31cs8SVeSRX1\nNTxQZmvCjMyTe/WYWYNFXdgkVz4egFXbeochCGzMYo57HV1PCkPBrARRZO8OfdDD\n8sDu//ohb7nCzceEI0DnWs13\n-----END PRIVATE KEY-----\n", + "client_email": "firebase-adminsdk-3ml0u@storied-phalanx-349916.iam.gserviceaccount.com", + "client_id": "114163760341944984396", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-dyg6p%40mti-ielts.iam.gserviceaccount.com", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-3ml0u%40storied-phalanx-349916.iam.gserviceaccount.com", "universe_domain": "googleapis.com" } diff --git a/src/exams/Selection.tsx b/src/exams/Selection.tsx index 02dcb681..d35cc855 100644 --- a/src/exams/Selection.tsx +++ b/src/exams/Selection.tsx @@ -1,261 +1,384 @@ /* eslint-disable @next/next/no-img-element */ -import {useState} from "react"; -import {Module} from "@/interfaces"; +import { useState } from "react"; +import { Module } from "@/interfaces"; import clsx from "clsx"; -import {User} from "@/interfaces/user"; +import { User } from "@/interfaces/user"; import ProgressBar from "@/components/Low/ProgressBar"; -import {BsBook, BsCheck, BsCheckCircle, BsClipboard, BsHeadphones, BsMegaphone, BsPen, BsXCircle} from "react-icons/bs"; -import {totalExamsByModule} from "@/utils/stats"; +import { + BsBook, + BsCheck, + BsCheckCircle, + BsClipboard, + BsHeadphones, + BsMegaphone, + BsPen, + BsXCircle, +} from "react-icons/bs"; +import { totalExamsByModule } from "@/utils/stats"; import useStats from "@/hooks/useStats"; import Button from "@/components/Low/Button"; -import {calculateAverageLevel} from "@/utils/score"; -import {sortByModuleName} from "@/utils/moduleUtils"; -import {capitalize} from "lodash"; +import { calculateAverageLevel } from "@/utils/score"; +import { sortByModuleName } from "@/utils/moduleUtils"; +import { capitalize } from "lodash"; import ProfileSummary from "@/components/ProfileSummary"; -import {Variant} from "@/interfaces/exam"; +import { Variant } from "@/interfaces/exam"; interface Props { - user: User; - page: "exercises" | "exams"; - onStart: (modules: Module[], avoidRepeated: boolean, variant: Variant) => void; - disableSelection?: boolean; + user: User; + page: "exercises" | "exams"; + onStart: ( + modules: Module[], + avoidRepeated: boolean, + variant: Variant, + ) => void; + disableSelection?: boolean; } -export default function Selection({user, page, onStart, disableSelection = false}: Props) { - const [selectedModules, setSelectedModules] = useState([]); - const [avoidRepeatedExams, setAvoidRepeatedExams] = useState(true); - const [variant, setVariant] = useState("full"); - const {stats} = useStats(user?.id); +export default function Selection({ + user, + page, + onStart, + disableSelection = false, +}: Props) { + const [selectedModules, setSelectedModules] = useState([]); + const [avoidRepeatedExams, setAvoidRepeatedExams] = useState(true); + const [variant, setVariant] = useState("full"); + const { stats } = useStats(user?.id); - const toggleModule = (module: Module) => { - const modules = selectedModules.filter((x) => x !== module); - setSelectedModules((prev) => (prev.includes(module) ? modules : [...modules, module])); - }; + const toggleModule = (module: Module) => { + const modules = selectedModules.filter((x) => x !== module); + setSelectedModules((prev) => + prev.includes(module) ? modules : [...modules, module], + ); + }; - return ( - <> -
- {user && ( - , - label: "Reading", - value: totalExamsByModule(stats, "reading"), - }, - { - icon: , - label: "Listening", - value: totalExamsByModule(stats, "listening"), - }, - { - icon: , - label: "Writing", - value: totalExamsByModule(stats, "writing"), - }, - { - icon: , - label: "Speaking", - value: totalExamsByModule(stats, "speaking"), - }, - { - icon: , - label: "Level", - value: totalExamsByModule(stats, "level"), - }, - ]} - /> - )} + return ( + <> +
+ {user && ( + + ), + label: "Reading", + value: totalExamsByModule(stats, "reading"), + }, + { + icon: ( + + ), + label: "Listening", + value: totalExamsByModule(stats, "listening"), + }, + { + icon: ( + + ), + label: "Writing", + value: totalExamsByModule(stats, "writing"), + }, + { + icon: ( + + ), + label: "Speaking", + value: totalExamsByModule(stats, "speaking"), + }, + { + icon: ( + + ), + label: "Level", + value: totalExamsByModule(stats, "level"), + }, + ]} + /> + )} -
- About {capitalize(page)} - - {page === "exercises" && ( - <> - In the realm of language acquisition, practice makes perfect, and our exercises are the key to unlocking your full - potential. Dive into a world of interactive and engaging exercises that cater to diverse learning styles. From grammar - drills that build a strong foundation to vocabulary challenges that broaden your lexicon, our exercises are carefully - designed to make learning English both enjoyable and effective. Whether you're looking to reinforce specific - skills or embark on a holistic language journey, our exercises are your companions in the pursuit of excellence. - Embrace the joy of learning as you navigate through a variety of activities that cater to every facet of language - acquisition. Your linguistic adventure starts here! - - )} - {page === "exams" && ( - <> - Welcome to the heart of success on your English language journey! Our exams are crafted with precision to assess and - enhance your language skills. Each test is a passport to your linguistic prowess, designed to challenge and elevate - your abilities. Whether you're a beginner or a seasoned learner, our exams cater to all levels, providing a - comprehensive evaluation of your reading, writing, speaking, and listening skills. Prepare to embark on a journey of - self-discovery and language mastery as you navigate through our thoughtfully curated exams. Your success is not just a - destination; it's a testament to your dedication and our commitment to empowering you with the English language. - - )} - -
-
-
toggleModule("reading") : undefined} - className={clsx( - "relative w-64 max-w-xs flex flex-col items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-2 pt-12 cursor-pointer", - selectedModules.includes("reading") || disableSelection ? "border-mti-purple-light" : "border-mti-gray-platinum", - )}> -
- -
- Reading: -

- Expand your vocabulary, improve your reading comprehension and improve your ability to interpret texts in English. -

- {!selectedModules.includes("reading") && !selectedModules.includes("level") && !disableSelection && ( -
- )} - {(selectedModules.includes("reading") || disableSelection) && ( - - )} - {selectedModules.includes("level") && } -
-
toggleModule("listening") : undefined} - className={clsx( - "relative w-64 max-w-xs flex flex-col items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-2 pt-12 cursor-pointer", - selectedModules.includes("listening") || disableSelection ? "border-mti-purple-light" : "border-mti-gray-platinum", - )}> -
- -
- Listening: -

- Improve your ability to follow conversations in English and your ability to understand different accents and intonations. -

- {!selectedModules.includes("listening") && !selectedModules.includes("level") && !disableSelection && ( -
- )} - {(selectedModules.includes("listening") || disableSelection) && ( - - )} - {selectedModules.includes("level") && } -
-
toggleModule("writing") : undefined} - className={clsx( - "relative w-64 max-w-xs flex flex-col items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-2 pt-12 cursor-pointer", - selectedModules.includes("writing") || disableSelection ? "border-mti-purple-light" : "border-mti-gray-platinum", - )}> -
- -
- Writing: -

- Allow you to practice writing in a variety of formats, from simple paragraphs to complex essays. -

- {!selectedModules.includes("writing") && !selectedModules.includes("level") && !disableSelection && ( -
- )} - {(selectedModules.includes("writing") || disableSelection) && ( - - )} - {selectedModules.includes("level") && } -
-
toggleModule("speaking") : undefined} - className={clsx( - "relative w-64 max-w-xs flex flex-col items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-2 pt-12 cursor-pointer", - selectedModules.includes("speaking") || disableSelection ? "border-mti-purple-light" : "border-mti-gray-platinum", - )}> -
- -
- Speaking: -

- You'll have access to interactive dialogs, pronunciation exercises and speech recordings. -

- {!selectedModules.includes("speaking") && !selectedModules.includes("level") && !disableSelection && ( -
- )} - {(selectedModules.includes("speaking") || disableSelection) && ( - - )} - {selectedModules.includes("level") && } -
- {!disableSelection && ( -
toggleModule("level") : undefined} - className={clsx( - "relative w-64 max-w-xs flex flex-col items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-2 pt-12 cursor-pointer", - selectedModules.includes("level") || disableSelection ? "border-mti-purple-light" : "border-mti-gray-platinum", - )}> -
- -
- Level: -

You'll be able to test your english level with multiple choice questions.

- {!selectedModules.includes("level") && selectedModules.length === 0 && !disableSelection && ( -
- )} - {(selectedModules.includes("level") || disableSelection) && ( - - )} - {!selectedModules.includes("level") && selectedModules.length > 0 && ( - - )} -
- )} -
-
-
-
setAvoidRepeatedExams((prev) => !prev)}> - -
- -
- - Avoid Repeated Questions - -
-
setVariant((prev) => (prev === "full" ? "partial" : "full"))}> - -
- -
- Full length exams -
-
-
- -
- -
-
- - ); +
+ About {capitalize(page)} + + {page === "exercises" && ( + <> + In the realm of language acquisition, practice makes perfect, + and our exercises are the key to unlocking your full potential. + Dive into a world of interactive and engaging exercises that + cater to diverse learning styles. From grammar drills that build + a strong foundation to vocabulary challenges that broaden your + lexicon, our exercises are carefully designed to make learning + English both enjoyable and effective. Whether you're + looking to reinforce specific skills or embark on a holistic + language journey, our exercises are your companions in the + pursuit of excellence. Embrace the joy of learning as you + navigate through a variety of activities that cater to every + facet of language acquisition. Your linguistic adventure starts + here! + + )} + {page === "exams" && ( + <> + Welcome to the heart of success on your English language + journey! Our exams are crafted with precision to assess and + enhance your language skills. Each test is a passport to your + linguistic prowess, designed to challenge and elevate your + abilities. Whether you're a beginner or a seasoned learner, + our exams cater to all levels, providing a comprehensive + evaluation of your reading, writing, speaking, and listening + skills. Prepare to embark on a journey of self-discovery and + language mastery as you navigate through our thoughtfully + curated exams. Your success is not just a destination; it's + a testament to your dedication and our commitment to empowering + you with the English language. + + )} + +
+
+
toggleModule("reading") + : undefined + } + className={clsx( + "bg-mti-white-alt relative flex w-64 max-w-xs cursor-pointer flex-col items-center gap-2 rounded-xl border p-5 pt-12 transition duration-300 ease-in-out", + selectedModules.includes("reading") || disableSelection + ? "border-mti-purple-light" + : "border-mti-gray-platinum", + )} + > +
+ +
+ Reading: +

+ Expand your vocabulary, improve your reading comprehension and + improve your ability to interpret texts in English. +

+ {!selectedModules.includes("reading") && + !selectedModules.includes("level") && + !disableSelection && ( +
+ )} + {(selectedModules.includes("reading") || disableSelection) && ( + + )} + {selectedModules.includes("level") && ( + + )} +
+
toggleModule("listening") + : undefined + } + className={clsx( + "bg-mti-white-alt relative flex w-64 max-w-xs cursor-pointer flex-col items-center gap-2 rounded-xl border p-5 pt-12 transition duration-300 ease-in-out", + selectedModules.includes("listening") || disableSelection + ? "border-mti-purple-light" + : "border-mti-gray-platinum", + )} + > +
+ +
+ Listening: +

+ Improve your ability to follow conversations in English and your + ability to understand different accents and intonations. +

+ {!selectedModules.includes("listening") && + !selectedModules.includes("level") && + !disableSelection && ( +
+ )} + {(selectedModules.includes("listening") || disableSelection) && ( + + )} + {selectedModules.includes("level") && ( + + )} +
+
toggleModule("writing") + : undefined + } + className={clsx( + "bg-mti-white-alt relative flex w-64 max-w-xs cursor-pointer flex-col items-center gap-2 rounded-xl border p-5 pt-12 transition duration-300 ease-in-out", + selectedModules.includes("writing") || disableSelection + ? "border-mti-purple-light" + : "border-mti-gray-platinum", + )} + > +
+ +
+ Writing: +

+ Allow you to practice writing in a variety of formats, from simple + paragraphs to complex essays. +

+ {!selectedModules.includes("writing") && + !selectedModules.includes("level") && + !disableSelection && ( +
+ )} + {(selectedModules.includes("writing") || disableSelection) && ( + + )} + {selectedModules.includes("level") && ( + + )} +
+
toggleModule("speaking") + : undefined + } + className={clsx( + "bg-mti-white-alt relative flex w-64 max-w-xs cursor-pointer flex-col items-center gap-2 rounded-xl border p-5 pt-12 transition duration-300 ease-in-out", + selectedModules.includes("speaking") || disableSelection + ? "border-mti-purple-light" + : "border-mti-gray-platinum", + )} + > +
+ +
+ Speaking: +

+ You'll have access to interactive dialogs, pronunciation + exercises and speech recordings. +

+ {!selectedModules.includes("speaking") && + !selectedModules.includes("level") && + !disableSelection && ( +
+ )} + {(selectedModules.includes("speaking") || disableSelection) && ( + + )} + {selectedModules.includes("level") && ( + + )} +
+ {!disableSelection && ( +
toggleModule("level") + : undefined + } + className={clsx( + "bg-mti-white-alt relative flex w-64 max-w-xs cursor-pointer flex-col items-center gap-2 rounded-xl border p-5 pt-12 transition duration-300 ease-in-out", + selectedModules.includes("level") || disableSelection + ? "border-mti-purple-light" + : "border-mti-gray-platinum", + )} + > +
+ +
+ Level: +

+ You'll be able to test your english level with multiple + choice questions. +

+ {!selectedModules.includes("level") && + selectedModules.length === 0 && + !disableSelection && ( +
+ )} + {(selectedModules.includes("level") || disableSelection) && ( + + )} + {!selectedModules.includes("level") && + selectedModules.length > 0 && ( + + )} +
+ )} +
+
+
+
setAvoidRepeatedExams((prev) => !prev)} + > + +
+ +
+ + Avoid Repeated Questions + +
+
+ setVariant((prev) => (prev === "full" ? "partial" : "full")) + } + > + +
+ +
+ Full length exams +
+
+
+ +
+ +
+
+ + ); } diff --git a/src/pages/action.tsx b/src/pages/action.tsx index ea1d9687..71551c04 100644 --- a/src/pages/action.tsx +++ b/src/pages/action.tsx @@ -1,157 +1,227 @@ /* eslint-disable @next/next/no-img-element */ -import {toast, ToastContainer} from "react-toastify"; +import { toast, ToastContainer } from "react-toastify"; import axios from "axios"; -import {FormEvent, useEffect, useState} from "react"; +import { FormEvent, useEffect, useState } from "react"; import Head from "next/head"; import useUser from "@/hooks/useUser"; -import {Divider} from "primereact/divider"; +import { Divider } from "primereact/divider"; import Button from "@/components/Low/Button"; -import {BsArrowRepeat} from "react-icons/bs"; +import { BsArrowRepeat } from "react-icons/bs"; import Link from "next/link"; import Input from "@/components/Low/Input"; -import {useRouter} from "next/router"; +import { useRouter } from "next/router"; -export function getServerSideProps({query, res}: {query: {oobCode: string; mode: string; apiKey?: string; continueUrl?: string}; res: any}) { - if (!query || !query.oobCode || !query.mode) { - res.setHeader("location", "/login"); - res.statusCode = 302; - res.end(); - return { - props: {}, - }; - } +export function getServerSideProps({ + query, + res, +}: { + query: { + oobCode: string; + mode: string; + continueUrl?: string; + }; + res: any; +}) { + if (!query || !query.oobCode || !query.mode) { + res.setHeader("location", "/login"); + res.statusCode = 302; + res.end(); + return { + props: {}, + }; + } - return { - props: { - code: query.oobCode, - mode: query.mode, - apiKey: query.apiKey, - ...query.continueUrl ? { continueUrl: query.continueUrl } : {}, - }, - }; + return { + props: { + code: query.oobCode, + mode: query.mode, + ...(query.continueUrl ? { continueUrl: query.continueUrl } : {}), + }, + }; } -export default function Reset({code, mode, apiKey, continueUrl}: {code: string; mode: string; apiKey?: string; continueUrl?: string}) { - const [password, setPassword] = useState(""); - const [isLoading, setIsLoading] = useState(false); +export default function Reset({ + code, + mode, + continueUrl, +}: { + code: string; + mode: string; + continueUrl?: string; +}) { + const [password, setPassword] = useState(""); + const [isLoading, setIsLoading] = useState(false); - const router = useRouter(); + const router = useRouter(); - useUser({ - redirectTo: "/", - redirectIfFound: true, - }); + useUser({ + redirectTo: "/", + redirectIfFound: true, + }); - useEffect(() => { - if (mode === "signIn") { - axios - .post<{ok: boolean}>("/api/reset/verify", { - email: continueUrl?.replace("https://platform.encoach.com/", ""), - }) - .then((response) => { - if (response.data.ok) { - toast.success("Your account has been verified!", {toastId: "verify-successful"}); - setTimeout(() => { - router.reload(); - }, 1000); - return; - } + useEffect(() => { + if (mode === "signIn") { + axios + .post<{ ok: boolean }>("/api/reset/verify", { + email: continueUrl?.replace("https://platform.encoach.com/", ""), + }) + .then((response) => { + if (response.data.ok) { + toast.success("Your account has been verified!", { + toastId: "verify-successful", + }); + setTimeout(() => { + router.reload(); + }, 1000); + return; + } - toast.error("Something went wrong! Please make sure to click the link in your e-mail again and input the correct e-mail!", { - toastId: "verify-error", - }); - }) - .catch(() => { - toast.error("Something went wrong! Please make sure to click the link in your e-mail again and input the correct e-mail!", { - toastId: "verify-error", - }); - setIsLoading(false); - }); - } - }); + toast.error( + "Something went wrong! Please make sure to click the link in your e-mail again and input the correct e-mail!", + { + toastId: "verify-error", + }, + ); + }) + .catch(() => { + toast.error( + "Something went wrong! Please make sure to click the link in your e-mail again and input the correct e-mail!", + { + toastId: "verify-error", + }, + ); + setIsLoading(false); + }); + } + }); - const login = (e: FormEvent) => { - e.preventDefault(); + const login = (e: FormEvent) => { + e.preventDefault(); - setIsLoading(true); - axios - .post<{ok: boolean}>("/api/reset/confirm", {code, password}) - .then((response) => { - if (response.data.ok) { - toast.success("Your password has been reset!", {toastId: "reset-successful"}); - setTimeout(() => { - router.push("/login"); - }, 1000); - return; - } + setIsLoading(true); + axios + .post<{ ok: boolean }>("/api/reset/confirm", { code, password }) + .then((response) => { + if (response.data.ok) { + toast.success("Your password has been reset!", { + toastId: "reset-successful", + }); + setTimeout(() => { + router.push("/login"); + }, 1000); + return; + } - toast.error("Something went wrong! Please make sure to click the link in your e-mail again!", {toastId: "reset-error"}); - }) - .catch(() => { - toast.error("Something went wrong! Please make sure to click the link in your e-mail again!", {toastId: "reset-error"}); - }) - .finally(() => setIsLoading(false)); - }; + toast.error( + "Something went wrong! Please make sure to click the link in your e-mail again!", + { toastId: "reset-error" }, + ); + }) + .catch(() => { + toast.error( + "Something went wrong! Please make sure to click the link in your e-mail again!", + { toastId: "reset-error" }, + ); + }) + .finally(() => setIsLoading(false)); + }; - return ( - <> - - Reset | EnCoach - - - - -
- -
-
- People smiling looking at a tablet -
- {mode === "resetPassword" && ( -
-
- EnCoach's Logo -

Reset your password

-

to your registered Email Address

-
- -
- setPassword(e)} placeholder="Password" /> + return ( + <> + + Reset | EnCoach + + + + +
+ +
+
+ People smiling looking at a tablet +
+ {mode === "resetPassword" && ( +
+
+ EnCoach's Logo +

+ Reset your password +

+

+ to your registered Email Address +

+
+ + + setPassword(e)} + placeholder="Password" + /> - - - - Don't have an account?{" "} - - Sign up - - -
- )} - {mode === "signIn" && ( -
-
- EnCoach's Logo -

Confirm your account

-

to your registered Email Address

-
- -
- - Your e-mail is currently being verified, please wait a second.

- Once it has been verified, you will be redirected to the home page. -
-
-
- )} -
- - ); + + + + Don't have an account?{" "} + + Sign up + + +
+ )} + {mode === "signIn" && ( +
+
+ EnCoach's Logo +

+ Confirm your account +

+

+ to your registered Email Address +

+
+ +
+ + Your e-mail is currently being verified, please wait a second.{" "} +

+ Once it has been verified, you will be redirected to the home + page. +
+
+
+ )} +
+ + ); }