ENCOA-111: Change Modules Assignment Display

This commit is contained in:
Tiago Ribeiro
2024-08-27 09:42:14 +01:00
parent 65dc3e92d0
commit 82233c7d53

View File

@@ -1,593 +1,422 @@
import Input from "@/components/Low/Input"; import Input from "@/components/Low/Input";
import Modal from "@/components/Modal"; import Modal from "@/components/Modal";
import { Module } from "@/interfaces"; import {Module} from "@/interfaces";
import clsx from "clsx"; import clsx from "clsx";
import { useEffect, useState } from "react"; import {useEffect, useState} from "react";
import { import {BsBook, BsCheckCircle, BsClipboard, BsHeadphones, BsMegaphone, BsPen, BsXCircle} from "react-icons/bs";
BsBook, import {generate} from "random-words";
BsCheckCircle, import {capitalize} from "lodash";
BsClipboard,
BsHeadphones,
BsMegaphone,
BsPen,
BsXCircle,
} from "react-icons/bs";
import { generate } from "random-words";
import { capitalize } from "lodash";
import useUsers from "@/hooks/useUsers"; import useUsers from "@/hooks/useUsers";
import { Group, User } from "@/interfaces/user"; import {Group, User} from "@/interfaces/user";
import ProgressBar from "@/components/Low/ProgressBar"; import ProgressBar from "@/components/Low/ProgressBar";
import { calculateAverageLevel } from "@/utils/score"; import {calculateAverageLevel} from "@/utils/score";
import Button from "@/components/Low/Button"; import Button from "@/components/Low/Button";
import ReactDatePicker from "react-datepicker"; import ReactDatePicker from "react-datepicker";
import moment from "moment"; import moment from "moment";
import axios from "axios"; import axios from "axios";
import { getExam } from "@/utils/exams"; import {getExam} from "@/utils/exams";
import { toast } from "react-toastify"; import {toast} from "react-toastify";
import { Assignment } from "@/interfaces/results"; import {Assignment} from "@/interfaces/results";
import Checkbox from "@/components/Low/Checkbox"; import Checkbox from "@/components/Low/Checkbox";
import { InstructorGender, Variant } from "@/interfaces/exam"; import {InstructorGender, Variant} from "@/interfaces/exam";
import Select from "@/components/Low/Select"; import Select from "@/components/Low/Select";
import useExams from "@/hooks/useExams"; import useExams from "@/hooks/useExams";
interface Props { interface Props {
isCreating: boolean; isCreating: boolean;
assigner: string; assigner: string;
users: User[]; users: User[];
groups: Group[]; groups: Group[];
assignment?: Assignment; assignment?: Assignment;
cancelCreation: () => void; cancelCreation: () => void;
} }
export default function AssignmentCreator({ export default function AssignmentCreator({isCreating, assignment, assigner, groups, users, cancelCreation}: Props) {
isCreating, const [selectedModules, setSelectedModules] = useState<Module[]>(assignment?.exams.map((e) => e.module) || []);
assignment, const [assignees, setAssignees] = useState<string[]>(assignment?.assignees || []);
assigner, const [name, setName] = useState(
groups, assignment?.name ||
users, generate({
cancelCreation, minLength: 6,
}: Props) { maxLength: 8,
const [selectedModules, setSelectedModules] = useState<Module[]>( min: 2,
assignment?.exams.map((e) => e.module) || [] max: 3,
); join: " ",
const [assignees, setAssignees] = useState<string[]>( formatter: capitalize,
assignment?.assignees || [] }),
); );
const [name, setName] = useState( const [isLoading, setIsLoading] = useState(false);
assignment?.name || const [startDate, setStartDate] = useState<Date | null>(assignment ? moment(assignment.startDate).toDate() : new Date());
generate({ const [endDate, setEndDate] = useState<Date | null>(
minLength: 6, assignment ? moment(assignment.endDate).toDate() : moment().hours(23).minutes(59).add(8, "day").toDate(),
maxLength: 8, );
min: 2, const [variant, setVariant] = useState<Variant>("full");
max: 3, const [instructorGender, setInstructorGender] = useState<InstructorGender>(assignment?.instructorGender || "varied");
join: " ", // creates a new exam for each assignee or just one exam for all assignees
formatter: capitalize, const [generateMultiple, setGenerateMultiple] = useState<boolean>(false);
}) const [useRandomExams, setUseRandomExams] = useState(true);
); const [examIDs, setExamIDs] = useState<{id: string; module: Module}[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [startDate, setStartDate] = useState<Date | null>(
assignment ? moment(assignment.startDate).toDate() : new Date()
);
const [endDate, setEndDate] = useState<Date | null>(
assignment
? moment(assignment.endDate).toDate()
: moment().hours(23).minutes(59).add(8, "day").toDate()
);
const [variant, setVariant] = useState<Variant>("full");
const [instructorGender, setInstructorGender] = useState<InstructorGender>(
assignment?.instructorGender || "varied"
);
// creates a new exam for each assignee or just one exam for all assignees
const [generateMultiple, setGenerateMultiple] = useState<boolean>(false);
const [useRandomExams, setUseRandomExams] = useState(true);
const [examIDs, setExamIDs] = useState<{ id: string; module: Module }[]>([]);
const { exams } = useExams(); const {exams} = useExams();
useEffect(() => { useEffect(() => {
setExamIDs((prev) => setExamIDs((prev) => prev.filter((x) => selectedModules.includes(x.module)));
prev.filter((x) => selectedModules.includes(x.module)) }, [selectedModules]);
);
}, [selectedModules]);
const toggleModule = (module: Module) => { const toggleModule = (module: Module) => {
const modules = selectedModules.filter((x) => x !== module); const modules = selectedModules.filter((x) => x !== module);
setSelectedModules((prev) => setSelectedModules((prev) => (prev.includes(module) ? modules : [...modules, module]));
prev.includes(module) ? modules : [...modules, module] };
);
};
const toggleAssignee = (user: User) => { const toggleAssignee = (user: User) => {
setAssignees((prev) => setAssignees((prev) => (prev.includes(user.id) ? prev.filter((a) => a !== user.id) : [...prev, user.id]));
prev.includes(user.id) };
? prev.filter((a) => a !== user.id)
: [...prev, user.id]
);
};
const createAssignment = () => { const createAssignment = () => {
setIsLoading(true); setIsLoading(true);
(assignment ? axios.patch : axios.post)( (assignment ? axios.patch : axios.post)(`/api/assignments${assignment ? `/${assignment.id}` : ""}`, {
`/api/assignments${assignment ? `/${assignment.id}` : ""}`, assignees,
{ name,
assignees, startDate,
name, examIDs: !useRandomExams ? examIDs : undefined,
startDate, endDate,
examIDs: !useRandomExams ? examIDs : undefined, selectedModules,
endDate, generateMultiple,
selectedModules, variant,
generateMultiple, instructorGender,
variant,
instructorGender,
}
)
.then(() => {
toast.success(
`The assignment "${name}" has been ${
assignment ? "updated" : "created"
} successfully!`
);
cancelCreation();
})
.catch((e) => {
console.log(e);
toast.error("Something went wrong, please try again later!");
})
.finally(() => setIsLoading(false));
};
const deleteAssignment = () => {
if (assignment) {
setIsLoading(true);
if (
!confirm(
`Are you sure you want to delete the "${assignment.name}" assignment?`
)
)
return;
axios
.delete(`api/assignments/${assignment.id}`)
.then(() => {
toast.success(
`The assignment "${name}" has been deleted successfully!`
);
cancelCreation();
})
.catch((e) => {
console.log(e);
toast.error("Something went wrong, please try again later!");
})
.finally(() => setIsLoading(false));
}
};
const startAssignment = () => {
if (assignment) {
setIsLoading(true);
axios
.post(`/api/assignments/${assignment.id}/start`)
.then(() => {
toast.success(
`The assignment "${name}" has been started successfully!`
);
cancelCreation();
}) })
.catch((e) => { .then(() => {
console.log(e); toast.success(`The assignment "${name}" has been ${assignment ? "updated" : "created"} successfully!`);
toast.error("Something went wrong, please try again later!"); cancelCreation();
}) })
.finally(() => setIsLoading(false)); .catch((e) => {
} console.log(e);
} toast.error("Something went wrong, please try again later!");
})
.finally(() => setIsLoading(false));
};
return ( const deleteAssignment = () => {
<Modal isOpen={isCreating} onClose={cancelCreation} title="New Assignment"> if (assignment) {
<div className="w-full flex flex-col gap-4"> setIsLoading(true);
<section className="w-full grid -md:grid-cols-1 md:grid-cols-2 place-items-center lg:grid-cols-6 -md:flex-col -md:items-center -md:gap-12 justify-between gap-8 mt-8 px-8">
<div
onClick={
!selectedModules.includes("level")
? () => toggleModule("reading")
: undefined
}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
"lg:col-span-2",
selectedModules.includes("reading")
? "border-mti-purple-light"
: "border-mti-gray-platinum"
)}
>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-reading top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsBook className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Reading</span>
{!selectedModules.includes("reading") &&
!selectedModules.includes("level") && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{selectedModules.includes("level") && (
<BsXCircle className="text-mti-red-light w-8 h-8" />
)}
{selectedModules.includes("reading") && (
<BsCheckCircle className="text-mti-purple-light w-8 h-8" />
)}
</div>
<div
onClick={
!selectedModules.includes("level")
? () => toggleModule("listening")
: undefined
}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
"lg:col-span-2",
selectedModules.includes("listening")
? "border-mti-purple-light"
: "border-mti-gray-platinum"
)}
>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-listening top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsHeadphones className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Listening</span>
{!selectedModules.includes("listening") &&
!selectedModules.includes("level") && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{selectedModules.includes("level") && (
<BsXCircle className="text-mti-red-light w-8 h-8" />
)}
{selectedModules.includes("listening") && (
<BsCheckCircle className="text-mti-purple-light w-8 h-8" />
)}
</div>
<div
onClick={
!selectedModules.includes("level")
? () => toggleModule("writing")
: undefined
}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
"lg:col-span-2",
selectedModules.includes("writing")
? "border-mti-purple-light"
: "border-mti-gray-platinum"
)}
>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-writing top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsPen className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Writing</span>
{!selectedModules.includes("writing") &&
!selectedModules.includes("level") && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{selectedModules.includes("level") && (
<BsXCircle className="text-mti-red-light w-8 h-8" />
)}
{selectedModules.includes("writing") && (
<BsCheckCircle className="text-mti-purple-light w-8 h-8" />
)}
</div>
<div
onClick={
!selectedModules.includes("level")
? () => toggleModule("speaking")
: undefined
}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
"lg:col-span-3",
selectedModules.includes("speaking")
? "border-mti-purple-light"
: "border-mti-gray-platinum"
)}
>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-speaking top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsMegaphone className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Speaking</span>
{!selectedModules.includes("speaking") &&
!selectedModules.includes("level") && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{selectedModules.includes("level") && (
<BsXCircle className="text-mti-red-light w-8 h-8" />
)}
{selectedModules.includes("speaking") && (
<BsCheckCircle className="text-mti-purple-light w-8 h-8" />
)}
</div>
<div
onClick={
(!selectedModules.includes("level") &&
selectedModules.length === 0) ||
selectedModules.includes("level")
? () => toggleModule("level")
: undefined
}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
"lg:col-span-3",
selectedModules.includes("level")
? "border-mti-purple-light"
: "border-mti-gray-platinum"
)}
>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-level top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsClipboard className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Level</span>
{!selectedModules.includes("level") &&
selectedModules.length === 0 && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{!selectedModules.includes("level") &&
selectedModules.length > 0 && (
<BsXCircle className="text-mti-red-light w-8 h-8" />
)}
{selectedModules.includes("level") && (
<BsCheckCircle className="text-mti-purple-light w-8 h-8" />
)}
</div>
</section>
<Input if (!confirm(`Are you sure you want to delete the "${assignment.name}" assignment?`)) return;
type="text" axios
name="name" .delete(`api/assignments/${assignment.id}`)
onChange={(e) => setName(e)} .then(() => {
defaultValue={name} toast.success(`The assignment "${name}" has been deleted successfully!`);
label="Assignment Name" cancelCreation();
required })
/> .catch((e) => {
console.log(e);
toast.error("Something went wrong, please try again later!");
})
.finally(() => setIsLoading(false));
}
};
<div className="w-full grid -md:grid-cols-1 md:grid-cols-2 gap-8"> const startAssignment = () => {
<div className="flex flex-col gap-2"> if (assignment) {
<label className="font-normal text-base text-mti-gray-dim"> setIsLoading(true);
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={startDate}
showTimeSelect
onChange={(date) => setStartDate(date)}
/>
</div>
<div className="flex flex-col gap-2">
<label className="font-normal text-base text-mti-gray-dim">
End 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).isAfter(startDate)}
dateFormat="dd/MM/yyyy HH:mm"
selected={endDate}
showTimeSelect
onChange={(date) => setEndDate(date)}
/>
</div>
</div>
{selectedModules.includes("speaking") && ( axios
<div className="flex flex-col gap-3 w-full"> .post(`/api/assignments/${assignment.id}/start`)
<label className="font-normal text-base text-mti-gray-dim"> .then(() => {
Speaking Instructor&apos;s Gender toast.success(`The assignment "${name}" has been started successfully!`);
</label> cancelCreation();
<Select })
value={{ .catch((e) => {
value: instructorGender, console.log(e);
label: capitalize(instructorGender), toast.error("Something went wrong, please try again later!");
}} })
onChange={(value) => .finally(() => setIsLoading(false));
value }
? setInstructorGender(value.value as InstructorGender) };
: null
}
disabled={!selectedModules.includes("speaking") || !!assignment}
options={[
{ value: "male", label: "Male" },
{ value: "female", label: "Female" },
{ value: "varied", label: "Varied" },
]}
/>
</div>
)}
{selectedModules.length > 0 && ( return (
<div className="flex flex-col gap-3 w-full"> <Modal isOpen={isCreating} onClose={cancelCreation} title="New Assignment">
<Checkbox isChecked={useRandomExams} onChange={setUseRandomExams}> <div className="w-full flex flex-col gap-4">
Random Exams <section className="w-full grid -md:grid-cols-1 md:grid-cols-3 place-items-center -md:flex-col -md:items-center -md:gap-12 justify-between gap-8 mt-8 px-8">
</Checkbox> <div
{!useRandomExams && ( onClick={!selectedModules.includes("level") ? () => toggleModule("reading") : undefined}
<div className="grid md:grid-cols-2 w-full gap-4"> className={clsx(
{selectedModules.map((module) => ( "w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
<div key={module} className="flex flex-col gap-3 w-full"> selectedModules.includes("reading") ? "border-mti-purple-light" : "border-mti-gray-platinum",
<label className="font-normal text-base text-mti-gray-dim"> )}>
{capitalize(module)} Exam <div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-reading top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
</label> <BsBook className="text-white w-7 h-7" />
<Select </div>
value={{ <span className="ml-8 font-semibold">Reading</span>
value: {!selectedModules.includes("reading") && !selectedModules.includes("level") && (
examIDs.find((e) => e.module === module)?.id || null, <div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
label: )}
examIDs.find((e) => e.module === module)?.id || "", {selectedModules.includes("level") && <BsXCircle className="text-mti-red-light w-8 h-8" />}
}} {selectedModules.includes("reading") && <BsCheckCircle className="text-mti-purple-light w-8 h-8" />}
onChange={(value) => </div>
value <div
? setExamIDs((prev) => [ onClick={!selectedModules.includes("level") ? () => toggleModule("listening") : undefined}
...prev.filter((x) => x.module !== module), className={clsx(
{ id: value.value!, module }, "w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
]) selectedModules.includes("listening") ? "border-mti-purple-light" : "border-mti-gray-platinum",
: setExamIDs((prev) => )}>
prev.filter((x) => x.module !== module) <div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-listening top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
) <BsHeadphones className="text-white w-7 h-7" />
} </div>
options={exams <span className="ml-8 font-semibold">Listening</span>
.filter((x) => !x.isDiagnostic && x.module === module) {!selectedModules.includes("listening") && !selectedModules.includes("level") && (
.map((x) => ({ value: x.id, label: x.id }))} <div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
/> )}
</div> {selectedModules.includes("level") && <BsXCircle className="text-mti-red-light w-8 h-8" />}
))} {selectedModules.includes("listening") && <BsCheckCircle className="text-mti-purple-light w-8 h-8" />}
</div> </div>
)} <div
</div> onClick={
)} (!selectedModules.includes("level") && selectedModules.length === 0) || selectedModules.includes("level")
? () => toggleModule("level")
: undefined
}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
selectedModules.includes("level") ? "border-mti-purple-light" : "border-mti-gray-platinum",
)}>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-level top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsClipboard className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Level</span>
{!selectedModules.includes("level") && selectedModules.length === 0 && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{!selectedModules.includes("level") && selectedModules.length > 0 && <BsXCircle className="text-mti-red-light w-8 h-8" />}
{selectedModules.includes("level") && <BsCheckCircle className="text-mti-purple-light w-8 h-8" />}
</div>
<div
onClick={!selectedModules.includes("level") ? () => toggleModule("writing") : undefined}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
selectedModules.includes("writing") ? "border-mti-purple-light" : "border-mti-gray-platinum",
)}>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-writing top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsPen className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Writing</span>
{!selectedModules.includes("writing") && !selectedModules.includes("level") && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{selectedModules.includes("level") && <BsXCircle className="text-mti-red-light w-8 h-8" />}
{selectedModules.includes("writing") && <BsCheckCircle className="text-mti-purple-light w-8 h-8" />}
</div>
<div
onClick={!selectedModules.includes("level") ? () => toggleModule("speaking") : undefined}
className={clsx(
"w-52 relative max-w-xs flex items-center bg-mti-white-alt transition duration-300 ease-in-out border p-5 rounded-xl gap-8 cursor-pointer",
selectedModules.includes("speaking") ? "border-mti-purple-light" : "border-mti-gray-platinum",
)}>
<div className="absolute w-16 h-16 flex items-center justify-center rounded-full bg-ielts-speaking top-1/2 -translate-y-1/2 left-0 -translate-x-1/2">
<BsMegaphone className="text-white w-7 h-7" />
</div>
<span className="ml-8 font-semibold">Speaking</span>
{!selectedModules.includes("speaking") && !selectedModules.includes("level") && (
<div className="border border-mti-gray-platinum w-8 h-8 rounded-full" />
)}
{selectedModules.includes("level") && <BsXCircle className="text-mti-red-light w-8 h-8" />}
{selectedModules.includes("speaking") && <BsCheckCircle className="text-mti-purple-light w-8 h-8" />}
</div>
</section>
<section className="w-full flex flex-col gap-3"> <Input type="text" name="name" onChange={(e) => setName(e)} defaultValue={name} label="Assignment Name" required />
<span className="font-semibold">
Assignees ({assignees.length} selected) <div className="w-full grid -md:grid-cols-1 md:grid-cols-2 gap-8">
</span> <div className="flex flex-col gap-2">
<div className="flex gap-4 overflow-x-scroll scrollbar-hide"> <label className="font-normal text-base text-mti-gray-dim">Start Date *</label>
{groups.map((g) => ( <ReactDatePicker
<button className={clsx(
key={g.id} "p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
onClick={() => { "hover:border-mti-purple tooltip z-10",
const groupStudentIds = users "transition duration-300 ease-in-out",
.filter((u) => g.participants.includes(u.id)) )}
.map((u) => u.id); popperClassName="!z-20"
if (groupStudentIds.every((u) => assignees.includes(u))) { filterTime={(date) => moment(date).isSameOrAfter(new Date())}
setAssignees((prev) => dateFormat="dd/MM/yyyy HH:mm"
prev.filter((a) => !groupStudentIds.includes(a)) selected={startDate}
); showTimeSelect
} else { onChange={(date) => setStartDate(date)}
setAssignees((prev) => [ />
...prev.filter((a) => !groupStudentIds.includes(a)), </div>
...groupStudentIds, <div className="flex flex-col gap-2">
]); <label className="font-normal text-base text-mti-gray-dim">End Date *</label>
} <ReactDatePicker
}} className={clsx(
className={clsx( "p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
"bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light", "hover:border-mti-purple tooltip z-10",
"transition duration-300 ease-in-out", "transition duration-300 ease-in-out",
users )}
.filter((u) => g.participants.includes(u.id)) popperClassName="!z-20"
.every((u) => assignees.includes(u.id)) && filterTime={(date) => moment(date).isAfter(startDate)}
"!bg-mti-purple-light !text-white" dateFormat="dd/MM/yyyy HH:mm"
)} selected={endDate}
> showTimeSelect
{g.name} onChange={(date) => setEndDate(date)}
</button> />
))} </div>
</div> </div>
<div className="flex flex-wrap -md:justify-center gap-4">
{users.map((user) => ( {selectedModules.includes("speaking") && (
<div <div className="flex flex-col gap-3 w-full">
onClick={() => toggleAssignee(user)} <label className="font-normal text-base text-mti-gray-dim">Speaking Instructor&apos;s Gender</label>
className={clsx( <Select
"p-4 flex flex-col gap-2 rounded-xl border cursor-pointer w-72", value={{
"transition ease-in-out duration-300", value: instructorGender,
assignees.includes(user.id) label: capitalize(instructorGender),
? "border-mti-purple" }}
: "border-mti-gray-platinum" onChange={(value) => (value ? setInstructorGender(value.value as InstructorGender) : null)}
)} disabled={!selectedModules.includes("speaking") || !!assignment}
key={user.id} options={[
> {value: "male", label: "Male"},
<span className="flex flex-col gap-0 justify-center"> {value: "female", label: "Female"},
<span className="font-semibold">{user.name}</span> {value: "varied", label: "Varied"},
<span className="text-sm opacity-80">{user.email}</span> ]}
</span> />
<ProgressBar </div>
color="purple" )}
textClassName="!text-mti-black/80"
label={`Level ${calculateAverageLevel(user.levels)}`} {selectedModules.length > 0 && (
percentage={(calculateAverageLevel(user.levels) / 9) * 100} <div className="flex flex-col gap-3 w-full">
className="h-6" <Checkbox isChecked={useRandomExams} onChange={setUseRandomExams}>
/> Random Exams
<span className="text-mti-black/80 text-sm whitespace-pre-wrap mt-2"> </Checkbox>
Groups:{" "} {!useRandomExams && (
{groups <div className="grid md:grid-cols-2 w-full gap-4">
.filter((g) => g.participants.includes(user.id)) {selectedModules.map((module) => (
.map((g) => g.name) <div key={module} className="flex flex-col gap-3 w-full">
.join(", ")} <label className="font-normal text-base text-mti-gray-dim">{capitalize(module)} Exam</label>
</span> <Select
</div> value={{
))} value: examIDs.find((e) => e.module === module)?.id || null,
</div> label: examIDs.find((e) => e.module === module)?.id || "",
</section> }}
<div className="flex flex-col gap-4 w-full items-end"> onChange={(value) =>
<Checkbox value
isChecked={variant === "full"} ? setExamIDs((prev) => [...prev.filter((x) => x.module !== module), {id: value.value!, module}])
onChange={() => : setExamIDs((prev) => prev.filter((x) => x.module !== module))
setVariant((prev) => (prev === "full" ? "partial" : "full")) }
} options={exams
> .filter((x) => !x.isDiagnostic && x.module === module)
Full length exams .map((x) => ({value: x.id, label: x.id}))}
</Checkbox> />
<Checkbox </div>
isChecked={generateMultiple} ))}
onChange={() => setGenerateMultiple((d) => !d)} </div>
> )}
Generate different exams </div>
</Checkbox> )}
</div>
<div className="flex gap-4 w-full justify-end"> <section className="w-full flex flex-col gap-3">
<Button <span className="font-semibold">Assignees ({assignees.length} selected)</span>
className="w-full max-w-[200px]" <div className="flex gap-4 overflow-x-scroll scrollbar-hide">
variant="outline" {groups.map((g) => (
onClick={cancelCreation} <button
disabled={isLoading} key={g.id}
isLoading={isLoading} onClick={() => {
> const groupStudentIds = users.filter((u) => g.participants.includes(u.id)).map((u) => u.id);
Cancel if (groupStudentIds.every((u) => assignees.includes(u))) {
</Button> setAssignees((prev) => prev.filter((a) => !groupStudentIds.includes(a)));
{assignment && ( } else {
<> setAssignees((prev) => [...prev.filter((a) => !groupStudentIds.includes(a)), ...groupStudentIds]);
<Button }
className="w-full max-w-[200px]" }}
color="green" className={clsx(
variant="outline" "bg-mti-purple-ultralight text-mti-purple px-4 py-2 rounded-full hover:text-white hover:bg-mti-purple-light",
onClick={startAssignment} "transition duration-300 ease-in-out",
disabled={isLoading || moment().isAfter(startDate)} users.filter((u) => g.participants.includes(u.id)).every((u) => assignees.includes(u.id)) &&
isLoading={isLoading} "!bg-mti-purple-light !text-white",
> )}>
Start {g.name}
</Button> </button>
<Button ))}
className="w-full max-w-[200px]" </div>
color="red" <div className="flex flex-wrap -md:justify-center gap-4">
variant="outline" {users.map((user) => (
onClick={deleteAssignment} <div
disabled={isLoading} onClick={() => toggleAssignee(user)}
isLoading={isLoading} className={clsx(
> "p-4 flex flex-col gap-2 rounded-xl border cursor-pointer w-72",
Delete "transition ease-in-out duration-300",
</Button> assignees.includes(user.id) ? "border-mti-purple" : "border-mti-gray-platinum",
</> )}
)} key={user.id}>
<Button <span className="flex flex-col gap-0 justify-center">
disabled={ <span className="font-semibold">{user.name}</span>
selectedModules.length === 0 || <span className="text-sm opacity-80">{user.email}</span>
!name || </span>
!startDate || <ProgressBar
!endDate || color="purple"
assignees.length === 0 || textClassName="!text-mti-black/80"
(!useRandomExams && examIDs.length < selectedModules.length) label={`Level ${calculateAverageLevel(user.levels)}`}
} percentage={(calculateAverageLevel(user.levels) / 9) * 100}
className="w-full max-w-[200px]" className="h-6"
onClick={createAssignment} />
isLoading={isLoading} <span className="text-mti-black/80 text-sm whitespace-pre-wrap mt-2">
> Groups:{" "}
{assignment ? "Update" : "Create"} {groups
</Button> .filter((g) => g.participants.includes(user.id))
</div> .map((g) => g.name)
</div> .join(", ")}
</Modal> </span>
); </div>
))}
</div>
</section>
<div className="flex flex-col gap-4 w-full items-end">
<Checkbox isChecked={variant === "full"} onChange={() => setVariant((prev) => (prev === "full" ? "partial" : "full"))}>
Full length exams
</Checkbox>
<Checkbox isChecked={generateMultiple} onChange={() => setGenerateMultiple((d) => !d)}>
Generate different exams
</Checkbox>
</div>
<div className="flex gap-4 w-full justify-end">
<Button className="w-full max-w-[200px]" variant="outline" onClick={cancelCreation} disabled={isLoading} isLoading={isLoading}>
Cancel
</Button>
{assignment && (
<>
<Button
className="w-full max-w-[200px]"
color="green"
variant="outline"
onClick={startAssignment}
disabled={isLoading || moment().isAfter(startDate)}
isLoading={isLoading}>
Start
</Button>
<Button
className="w-full max-w-[200px]"
color="red"
variant="outline"
onClick={deleteAssignment}
disabled={isLoading}
isLoading={isLoading}>
Delete
</Button>
</>
)}
<Button
disabled={
selectedModules.length === 0 ||
!name ||
!startDate ||
!endDate ||
assignees.length === 0 ||
(!useRandomExams && examIDs.length < selectedModules.length)
}
className="w-full max-w-[200px]"
onClick={createAssignment}
isLoading={isLoading}>
{assignment ? "Update" : "Create"}
</Button>
</div>
</div>
</Modal>
);
} }