import ProgressBar from "@/components/Low/ProgressBar"; import useUsers from "@/hooks/useUsers"; import { Module } from "@/interfaces"; import { Assignment } from "@/interfaces/results"; import { calculateBandScore } from "@/utils/score"; import clsx from "clsx"; import moment from "moment"; import { BsBook, BsClipboard, BsHeadphones, BsMegaphone, BsPen, } from "react-icons/bs"; import { usePDFDownload } from "@/hooks/usePDFDownload"; import { useAssignmentArchive } from "@/hooks/useAssignmentArchive"; import { uniqBy } from "lodash"; interface Props { onClick?: () => void; allowDownload?: boolean; reload?: Function; allowArchive?: boolean; } export default function AssignmentCard({ id, name, assigner, startDate, endDate, assignees, results, exams, archived, onClick, allowDownload, reload, allowArchive, }: Assignment & Props) { const renderPdfIcon = usePDFDownload("assignments"); const renderArchiveIcon = useAssignmentArchive(id, reload); const calculateAverageModuleScore = (module: Module) => { const resultModuleBandScores = results.map((r) => { const moduleStats = r.stats.filter((s) => s.module === module); const correct = moduleStats.reduce( (acc, curr) => acc + curr.score.correct, 0 ); const total = moduleStats.reduce( (acc, curr) => acc + curr.score.total, 0 ); return calculateBandScore(correct, total, module, r.type); }); return resultModuleBandScores.length === 0 ? -1 : resultModuleBandScores.reduce((acc, curr) => acc + curr, 0) / results.length; }; return (

{name}

{allowDownload && renderPdfIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")} {allowArchive && !archived && renderArchiveIcon("text-mti-gray-dim", "text-mti-gray-dim")}
{moment(startDate).format("DD/MM/YY, HH:mm")} - {moment(endDate).format("DD/MM/YY, HH:mm")}
{uniqBy(exams, (x) => x.module).map(({ module }) => (
{module === "reading" && } {module === "listening" && } {module === "writing" && } {module === "speaking" && } {module === "level" && } {calculateAverageModuleScore(module) > -1 && ( {calculateAverageModuleScore(module).toFixed(1)} )}
))}
); }