Updated the assignments active filter to work with the startDate
This commit is contained in:
@@ -18,26 +18,39 @@ import ExamEditor from "@/components/ExamEditor";
|
|||||||
import MultipleAudioUploader from "@/components/ExamEditor/Shared/AudioEdit";
|
import MultipleAudioUploader from "@/components/ExamEditor/Shared/AudioEdit";
|
||||||
import { redirect, serialize } from "@/utils";
|
import { redirect, serialize } from "@/utils";
|
||||||
import { requestUser } from "@/utils/api";
|
import { requestUser } from "@/utils/api";
|
||||||
|
import { Module } from "@/interfaces";
|
||||||
|
import { getExam, getExams } from "@/utils/exams.be";
|
||||||
|
import { Exam } from "@/interfaces/exam";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
export const getServerSideProps = withIronSessionSsr(async ({ req, res, query }) => {
|
||||||
const user = await requestUser(req, res)
|
const user = await requestUser(req, res)
|
||||||
if (!user) return redirect("/login")
|
if (!user) return redirect("/login")
|
||||||
|
|
||||||
if (shouldRedirectHome(user) || !checkAccess(user, ["admin", "mastercorporate", "developer", "corporate"]))
|
if (shouldRedirectHome(user) || !checkAccess(user, ["admin", "mastercorporate", "developer", "corporate"]))
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
const { id, module } = query as { id?: string, module?: Module }
|
||||||
|
if (!id || !module) return { props: serialize({ user }) };
|
||||||
|
|
||||||
|
const exam = await getExam(module, id)
|
||||||
|
if (!exam) return redirect("/generation")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: serialize({user}),
|
props: serialize({ user, exam }),
|
||||||
};
|
};
|
||||||
}, sessionOptions);
|
}, sessionOptions);
|
||||||
|
|
||||||
export default function Generation({ user }: { user: User; }) {
|
export default function Generation({ user, exam }: { user: User; exam?: Exam }) {
|
||||||
const { title, currentModule, dispatch } = useExamEditorStore();
|
const { title, currentModule, dispatch } = useExamEditorStore();
|
||||||
|
|
||||||
const updateRoot = (updates: Partial<ExamEditorStore>) => {
|
const updateRoot = (updates: Partial<ExamEditorStore>) => {
|
||||||
dispatch({ type: 'UPDATE_ROOT', payload: { updates } });
|
dispatch({ type: 'UPDATE_ROOT', payload: { updates } });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (exam) { }
|
||||||
|
}, [exam])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -41,17 +41,12 @@ export const archivedAssignmentFilter = (a: Assignment) => a.archived;
|
|||||||
|
|
||||||
export const activeAssignmentFilter = (a: Assignment) => {
|
export const activeAssignmentFilter = (a: Assignment) => {
|
||||||
const currentDate = moment();
|
const currentDate = moment();
|
||||||
if(moment(a.endDate).isBefore(currentDate)) return false;
|
if (moment(a.endDate).isBefore(currentDate) || a.archived) return false;
|
||||||
if(a.archived) return false;
|
|
||||||
|
|
||||||
if (a.start) return true;
|
if (a.start) return true;
|
||||||
|
if (a.autoStart && a.autoStartDate) return moment(a.autoStartDate).isBefore(currentDate);
|
||||||
|
|
||||||
if(a.autoStart && a.autoStartDate) {
|
return currentDate.isAfter(moment(a.startDate));
|
||||||
return moment(a.autoStartDate).isBefore(currentDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if(currentDate.isAfter(moment(a.startDate))) return true;
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// export const unstartedAssignmentFilter = (a: Assignment) => {
|
// export const unstartedAssignmentFilter = (a: Assignment) => {
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ export async function getSpecificExams(ids: string[]) {
|
|||||||
return exams;
|
return exams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getExam = async (module: Module, id: string) => {
|
||||||
|
return await db.collection(module).findOne<Exam>({ id }) ?? undefined
|
||||||
|
};
|
||||||
|
|
||||||
export const getExamsByIds = async (ids: { module: Module; id: string }[]) => {
|
export const getExamsByIds = async (ids: { module: Module; id: string }[]) => {
|
||||||
const groupedByModule = groupBy(ids, "module");
|
const groupedByModule = groupBy(ids, "module");
|
||||||
const exams: Exam[] = (
|
const exams: Exam[] = (
|
||||||
|
|||||||
Reference in New Issue
Block a user