Added more lists related to the expired accounts
This commit is contained in:
@@ -128,7 +128,7 @@ export default function BatchCodeGenerator({user}: {user: User}) {
|
||||
variant="outline"
|
||||
onClick={() => generateCode("corporate")}
|
||||
disabled={emails.length === 0 || isLoading || !PERMISSIONS.generateCode.corporate.includes(user.type)}>
|
||||
Admin
|
||||
Corporate
|
||||
</Button>
|
||||
<Button
|
||||
className="w-44 2xl:w-48"
|
||||
|
||||
@@ -77,7 +77,7 @@ export default function CodeGenerator({user}: {user: User}) {
|
||||
variant="outline"
|
||||
onClick={() => generateCode("corporate")}
|
||||
disabled={!PERMISSIONS.generateCode.corporate.includes(user.type) || (isExpiryDateEnabled && expiryDate === null)}>
|
||||
Admin
|
||||
Corporate
|
||||
</Button>
|
||||
<Button
|
||||
className="w-44 md:w-48"
|
||||
|
||||
50
src/pages/(admin)/ExamGenerator.tsx
Normal file
50
src/pages/(admin)/ExamGenerator.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import Button from "@/components/Low/Button";
|
||||
import Input from "@/components/Low/Input";
|
||||
import {Module} from "@/interfaces";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import {getExamById} from "@/utils/exams";
|
||||
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
||||
import {RadioGroup} from "@headlessui/react";
|
||||
import axios from "axios";
|
||||
import clsx from "clsx";
|
||||
import {capitalize} from "lodash";
|
||||
import {useRouter} from "next/router";
|
||||
import {FormEvent, useState} from "react";
|
||||
import {toast} from "react-toastify";
|
||||
|
||||
export default function ExamGenerator() {
|
||||
const [selectedModule, setSelectedModule] = useState<Module>();
|
||||
const [examId, setExamId] = useState<string>();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const setExams = useExamStore((state) => state.setExams);
|
||||
const setSelectedModules = useExamStore((state) => state.setSelectedModules);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const generateExam = (module: Module) => {
|
||||
axios.get(`/api/exam/${module}/generate`).then((result) => console.log(result.data));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 border p-4 border-mti-gray-platinum rounded-xl">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Exam Generator</label>
|
||||
<div className="w-full grid grid-cols-2 gap-2">
|
||||
{MODULE_ARRAY.map((module) => (
|
||||
<Button
|
||||
onClick={() => generateExam(module)}
|
||||
key={module}
|
||||
className={clsx(
|
||||
"w-full min-w-[200px]",
|
||||
module === "reading" && "!bg-ielts-reading/80 !border-ielts-reading hover:!bg-ielts-reading",
|
||||
module === "listening" && "!bg-ielts-listening/80 !border-ielts-listening hover:!bg-ielts-listening",
|
||||
module === "writing" && "!bg-ielts-writing/80 !border-ielts-writing hover:!bg-ielts-writing",
|
||||
module === "speaking" && "!bg-ielts-speaking/80 !border-ielts-speaking hover:!bg-ielts-speaking",
|
||||
)}>
|
||||
{capitalize(module)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import clsx from "clsx";
|
||||
import Lists from "./(admin)/Lists";
|
||||
import BatchCodeGenerator from "./(admin)/BatchCodeGenerator";
|
||||
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||
import ExamGenerator from "./(admin)/ExamGenerator";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
const user = req.session.user;
|
||||
@@ -61,7 +62,7 @@ export default function Admin() {
|
||||
{user && (
|
||||
<Layout user={user} className="gap-6">
|
||||
<section className="w-full flex -md:flex-col -xl:gap-2 gap-8 justify-between">
|
||||
<ExamLoader />
|
||||
{user.type === "developer" ? <ExamGenerator /> : <ExamLoader />}
|
||||
<CodeGenerator user={user} />
|
||||
<BatchCodeGenerator user={user} />
|
||||
</section>
|
||||
|
||||
41
src/pages/api/exam/[module]/generate.tsx
Normal file
41
src/pages/api/exam/[module]/generate.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {app} from "@/firebase";
|
||||
import {getFirestore, collection, getDocs, query, where} from "firebase/firestore";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {shuffle} from "lodash";
|
||||
import {Exam} from "@/interfaces/exam";
|
||||
import {Stat} from "@/interfaces/user";
|
||||
import {Module} from "@/interfaces";
|
||||
import axios from "axios";
|
||||
|
||||
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.session.user.type !== "developer") {
|
||||
res.status(403).json({ok: false});
|
||||
return;
|
||||
}
|
||||
|
||||
const {module} = req.query as {module: Module};
|
||||
|
||||
switch (module) {
|
||||
case "reading":
|
||||
const result = await axios.get(
|
||||
`${process.env.BACKEND_URL}/reading_passage_1?topic=football manager video game&exercises=multipleChoice&exercises=trueFalse&exercises=fillBlanks&exercises=writeBlanks`,
|
||||
{headers: {Authorization: `Bearer ${process.env.BACKEND_JWT}`}},
|
||||
);
|
||||
res.status(200).json(result.data);
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).json({ok: true});
|
||||
}
|
||||
Reference in New Issue
Block a user