Removed the autoStartDate and replaced it with the current startDate
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Session } from "@/hooks/useSessions";
|
||||
import { Assignment } from "@/interfaces/results";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { activeAssignmentFilter, futureAssignmentFilter } from "@/utils/assignments";
|
||||
import { sortByModuleName } from "@/utils/moduleUtils";
|
||||
import clsx from "clsx";
|
||||
import moment from "moment";
|
||||
@@ -44,7 +45,16 @@ export default function AssignmentCard({ user, assignment, session, startAssignm
|
||||
<ModuleBadge className="scale-110 w-full" key={module} module={module} />
|
||||
))}
|
||||
</div>
|
||||
{!assignment.results.map((r) => r.user).includes(user.id) && (
|
||||
{futureAssignmentFilter(assignment) && (
|
||||
<Button
|
||||
color="rose"
|
||||
className="-md:hidden h-full w-full max-w-[50%] !rounded-xl"
|
||||
disabled
|
||||
variant="outline">
|
||||
Not yet started
|
||||
</Button>
|
||||
)}
|
||||
{activeAssignmentFilter(assignment) && !assignment.results.map((r) => r.user).includes(user.id) && (
|
||||
<>
|
||||
<div
|
||||
className="tooltip flex h-full w-full items-center justify-end pl-8 md:hidden"
|
||||
@@ -88,6 +98,7 @@ export default function AssignmentCard({ user, assignment, session, startAssignm
|
||||
<Button
|
||||
color="green"
|
||||
className="-md:hidden h-full w-full max-w-[50%] !rounded-xl"
|
||||
disabled
|
||||
variant="outline">
|
||||
Submitted
|
||||
</Button>
|
||||
|
||||
@@ -65,7 +65,6 @@ export default function AssignmentCreator({isCreating, assignment, user, groups,
|
||||
const [released, setReleased] = useState<boolean>(assignment?.released || false);
|
||||
|
||||
const [autoStart, setAutostart] = useState<boolean>(assignment?.autoStart || false);
|
||||
const [autoStartDate, setAutoStartDate] = useState<Date | null>(assignment ? moment(assignment.autoStartDate).toDate() : new Date());
|
||||
|
||||
const [useRandomExams, setUseRandomExams] = useState(true);
|
||||
const [examIDs, setExamIDs] = useState<{ id: string; module: Module }[]>([]);
|
||||
@@ -131,7 +130,6 @@ export default function AssignmentCreator({isCreating, assignment, user, groups,
|
||||
instructorGender,
|
||||
released,
|
||||
autoStart,
|
||||
autoStartDate,
|
||||
})
|
||||
.then(() => {
|
||||
toast.success(`The assignment "${name}" has been ${assignment ? "updated" : "created"} successfully!`);
|
||||
@@ -306,24 +304,6 @@ export default function AssignmentCreator({isCreating, assignment, user, groups,
|
||||
onChange={(date) => setEndDate(date)}
|
||||
/>
|
||||
</div>
|
||||
{autoStart && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Automatic Start Date *</label>
|
||||
<ReactDatePicker
|
||||
className={clsx(
|
||||
"p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"hover:border-mti-purple tooltip z-10",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}
|
||||
popperClassName="!z-20"
|
||||
filterTime={(date) => moment(date).isSameOrAfter(new Date())}
|
||||
dateFormat="dd/MM/yyyy HH:mm"
|
||||
selected={autoStartDate}
|
||||
showTimeSelect
|
||||
onChange={(date) => setAutoStartDate(date)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedModules.includes("speaking") && (
|
||||
|
||||
@@ -32,7 +32,6 @@ export interface Assignment {
|
||||
// unless start is active, the assignment is not visible to the assignees
|
||||
// start date now works as a limit time to start the exam
|
||||
start?: boolean;
|
||||
autoStartDate?: Date;
|
||||
autoStart?: boolean;
|
||||
entity?: string;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,6 @@ export default function AssignmentsPage({assignment, user, users, entities, grou
|
||||
const [released, setReleased] = useState<boolean>(assignment.released || false);
|
||||
|
||||
const [autoStart, setAutostart] = useState<boolean>(assignment.autoStart || false);
|
||||
const [autoStartDate, setAutoStartDate] = useState<Date | null>(moment(assignment.autoStartDate).toDate());
|
||||
|
||||
const [useRandomExams, setUseRandomExams] = useState(true);
|
||||
const [examIDs, setExamIDs] = useState<{ id: string; module: Module }[]>([]);
|
||||
@@ -148,7 +147,6 @@ export default function AssignmentsPage({assignment, user, users, entities, grou
|
||||
instructorGender,
|
||||
released,
|
||||
autoStart,
|
||||
autoStartDate,
|
||||
})
|
||||
.then(() => {
|
||||
toast.success(`The assignment "${name}" has been updated successfully!`);
|
||||
@@ -355,24 +353,6 @@ export default function AssignmentsPage({assignment, user, users, entities, grou
|
||||
onChange={(date) => setEndDate(date)}
|
||||
/>
|
||||
</div>
|
||||
{autoStart && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Automatic Start Date *</label>
|
||||
<ReactDatePicker
|
||||
className={clsx(
|
||||
"p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"hover:border-mti-purple tooltip z-10",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}
|
||||
popperClassName="!z-20"
|
||||
filterTime={(date) => moment(date).isSameOrAfter(new Date())}
|
||||
dateFormat="dd/MM/yyyy HH:mm"
|
||||
selected={autoStartDate}
|
||||
showTimeSelect
|
||||
onChange={(date) => setAutoStartDate(date)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedModules.includes("speaking") && (
|
||||
|
||||
@@ -88,7 +88,6 @@ export default function AssignmentsPage({user, users, groups, entities}: Props)
|
||||
const [released, setReleased] = useState<boolean>(false);
|
||||
|
||||
const [autoStart, setAutostart] = useState<boolean>(false);
|
||||
const [autoStartDate, setAutoStartDate] = useState<Date | null>(new Date());
|
||||
|
||||
const [useRandomExams, setUseRandomExams] = useState(true);
|
||||
const [examIDs, setExamIDs] = useState<{ id: string; module: Module }[]>([]);
|
||||
@@ -148,7 +147,6 @@ export default function AssignmentsPage({user, users, groups, entities}: Props)
|
||||
instructorGender,
|
||||
released,
|
||||
autoStart,
|
||||
autoStartDate,
|
||||
})
|
||||
.then((result) => {
|
||||
toast.success(`The assignment "${name}" has been created successfully!`);
|
||||
@@ -313,24 +311,6 @@ export default function AssignmentsPage({user, users, groups, entities}: Props)
|
||||
onChange={(date) => setEndDate(date)}
|
||||
/>
|
||||
</div>
|
||||
{autoStart && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Automatic Start Date *</label>
|
||||
<ReactDatePicker
|
||||
className={clsx(
|
||||
"p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"hover:border-mti-purple tooltip z-10",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}
|
||||
popperClassName="!z-20"
|
||||
filterTime={(date) => moment(date).isSameOrAfter(new Date())}
|
||||
dateFormat="dd/MM/yyyy HH:mm"
|
||||
selected={autoStartDate}
|
||||
showTimeSelect
|
||||
onChange={(date) => setAutoStartDate(date)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedModules.includes("speaking") && (
|
||||
|
||||
@@ -15,7 +15,7 @@ import { sessionOptions } from "@/lib/session";
|
||||
import useExamStore from "@/stores/examStore";
|
||||
import { filterBy, findBy, mapBy, redirect, serialize } from "@/utils";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { activeAssignmentFilter } from "@/utils/assignments";
|
||||
import { activeAssignmentFilter, futureAssignmentFilter } from "@/utils/assignments";
|
||||
import { getAssignmentsByAssignee } from "@/utils/assignments.be";
|
||||
import { getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
import { getExamsByIds } from "@/utils/exams.be";
|
||||
@@ -29,7 +29,7 @@ import { uniqBy } from "lodash";
|
||||
import moment from "moment";
|
||||
import Head from "next/head";
|
||||
import { useRouter } from "next/router";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { BsArrowRepeat } from "react-icons/bs";
|
||||
import { ToastContainer } from "react-toastify";
|
||||
|
||||
@@ -74,6 +74,8 @@ const destination = Buffer.from("/official-exam").toString("base64")
|
||||
export default function OfficialExam({ user, entities, assignments, sessions, exams }: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
useEffect(() => console.log(assignments), [assignments])
|
||||
|
||||
const router = useRouter();
|
||||
const state = useExamStore((state) => state);
|
||||
const reload = () => {
|
||||
@@ -123,7 +125,11 @@ export default function OfficialExam({ user, entities, assignments, sessions, ex
|
||||
});
|
||||
};
|
||||
|
||||
const studentAssignments = useMemo(() => assignments.filter(activeAssignmentFilter), [assignments]);
|
||||
const studentAssignments = useMemo(() => [
|
||||
...assignments.filter(activeAssignmentFilter), ...assignments.filter(futureAssignmentFilter)],
|
||||
[assignments]
|
||||
);
|
||||
|
||||
const assignmentSessions = useMemo(() => sessions.filter(s => mapBy(studentAssignments, 'id').includes(s.assignment?.id || "")), [sessions, studentAssignments])
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,38 +1,20 @@
|
||||
import moment from "moment";
|
||||
import { Assignment } from "@/interfaces/results";
|
||||
|
||||
// export const futureAssignmentFilter = (a: Assignment) => {
|
||||
// if(a.archived) return false;
|
||||
// if(a.start) return false;
|
||||
|
||||
// const currentDate = moment();
|
||||
// const startDate = moment(a.startDate);
|
||||
// if(currentDate.isAfter(startDate)) return false;
|
||||
// if(a.autoStart && a.autoStartDate) {
|
||||
// return moment(a.autoStartDate).isAfter(currentDate);
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
export const futureAssignmentFilter = (a: Assignment) => {
|
||||
const currentDate = moment();
|
||||
if (moment(a.endDate).isBefore(currentDate)) return false;
|
||||
|
||||
if (a.archived) return false;
|
||||
if (moment(a.endDate).isBefore(currentDate)) return false;
|
||||
if (a.autoStart && moment(a.startDate).isBefore(currentDate)) return false;
|
||||
|
||||
if (a.autoStart && a.autoStartDate && moment(a.autoStartDate).isBefore(currentDate)) return false;
|
||||
|
||||
if (!a.start) {
|
||||
if (moment(a.startDate).isBefore(currentDate)) return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !a.start;
|
||||
}
|
||||
|
||||
export const pastAssignmentFilter = (a: Assignment) => {
|
||||
const currentDate = moment();
|
||||
if (a.archived) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a.archived) return false;
|
||||
|
||||
return moment(a.endDate).isBefore(currentDate);
|
||||
}
|
||||
@@ -44,25 +26,11 @@ export const activeAssignmentFilter = (a: Assignment) => {
|
||||
if (moment(a.endDate).isBefore(currentDate) || a.archived) return false;
|
||||
|
||||
if (a.start) return true;
|
||||
if (a.autoStart && a.autoStartDate) return moment(a.autoStartDate).isBefore(currentDate);
|
||||
if (a.autoStart) return currentDate.isAfter(moment(a.startDate));
|
||||
|
||||
return currentDate.isAfter(moment(a.startDate));
|
||||
return false
|
||||
};
|
||||
|
||||
// export const unstartedAssignmentFilter = (a: Assignment) => {
|
||||
// const currentDate = moment();
|
||||
// if(moment(a.endDate).isBefore(currentDate)) return false;
|
||||
// if(a.archived) return false;
|
||||
|
||||
// if(a.autoStart && a.autoStartDate && moment(a.autoStartDate).isBefore(currentDate)) return false;
|
||||
|
||||
// if(!a.start) {
|
||||
// if(moment(a.startDate).isBefore(currentDate)) return false;
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
export const startHasExpiredAssignmentFilter = (a: Assignment) => {
|
||||
const currentDate = moment();
|
||||
if (a.archived) return false;
|
||||
|
||||
Reference in New Issue
Block a user