Exam Edit on ExamList
This commit is contained in:
@@ -21,7 +21,7 @@ import { requestUser } from "@/utils/api";
|
||||
import { Module } from "@/interfaces";
|
||||
import { getExam, getExams } from "@/utils/exams.be";
|
||||
import { Exam, Exercise, InteractiveSpeakingExercise, ListeningPart, SpeakingExercise } from "@/interfaces/exam";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
import { isAdmin } from "@/utils/users";
|
||||
import axios from "axios";
|
||||
@@ -47,26 +47,38 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res, query })
|
||||
|
||||
if (Object.keys(permissions).every(p => !permissions[p as Module])) return redirect("/")
|
||||
|
||||
const { id, module } = query as { id?: string, module?: Module }
|
||||
if (!id || !module) return { props: serialize({ user, permissions }) };
|
||||
const { id, module: examModule } = query as { id?: string, module?: Module }
|
||||
if (!id || !examModule) return { props: serialize({ user, permissions }) };
|
||||
|
||||
if (!permissions[module]) return redirect("/generation")
|
||||
//if (!permissions[module]) return redirect("/generation")
|
||||
|
||||
const exam = await getExam(module, id)
|
||||
const exam = await getExam(examModule, id)
|
||||
if (!exam) return redirect("/generation")
|
||||
|
||||
return {
|
||||
props: serialize({ user, exam, permissions }),
|
||||
props: serialize({ id, user, exam, examModule, permissions }),
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Generation({ user, exam, permissions }: { user: User; exam?: Exam, permissions: Permission }) {
|
||||
export default function Generation({ id, user, exam, examModule, permissions }: { id: string, user: User; exam?: Exam, examModule?: Module, permissions: Permission }) {
|
||||
const { title, currentModule, modules, dispatch } = useExamEditorStore();
|
||||
const [examLevelParts, setExamLevelParts] = useState<number | undefined>(undefined);
|
||||
|
||||
const updateRoot = (updates: Partial<ExamEditorStore>) => {
|
||||
dispatch({ type: 'UPDATE_ROOT', payload: { updates } });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (id && exam && examModule) {
|
||||
if (examModule === "level" && exam.module === "level") {
|
||||
setExamLevelParts(exam.parts.length);
|
||||
}
|
||||
updateRoot({currentModule: examModule})
|
||||
dispatch({ type: "INIT_EXAM_EDIT", payload: { exam, id, examModule } })
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id, exam, module])
|
||||
|
||||
useEffect(() => {
|
||||
const fetchAvatars = async () => {
|
||||
const response = await axios.get("/api/exam/avatars");
|
||||
@@ -118,15 +130,11 @@ export default function Generation({ user, exam, permissions }: { user: User; ex
|
||||
})
|
||||
}
|
||||
});
|
||||
dispatch({type: 'FULL_RESET'});
|
||||
dispatch({ type: 'FULL_RESET' });
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (exam) { }
|
||||
}, [exam])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -150,6 +158,7 @@ export default function Generation({ user, exam, permissions }: { user: User; ex
|
||||
label="Title"
|
||||
onChange={(title) => updateRoot({ title })}
|
||||
roundness="xl"
|
||||
value={title}
|
||||
defaultValue={title}
|
||||
required
|
||||
/>
|
||||
@@ -194,7 +203,7 @@ export default function Generation({ user, exam, permissions }: { user: User; ex
|
||||
))}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
<ExamEditor />
|
||||
<ExamEditor levelParts={examLevelParts} />
|
||||
</Layout>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user