import {Session} from "@/hooks/useSessions"; import useExamStore from "@/stores/examStore"; import {sortByModuleName} from "@/utils/moduleUtils"; import axios from "axios"; import clsx from "clsx"; import {capitalize} from "lodash"; import moment from "moment"; import {useState} from "react"; import {BsArrowRepeat, BsBook, BsClipboard, BsHeadphones, BsMegaphone, BsPen} from "react-icons/bs"; import {toast} from "react-toastify"; export default function SessionCard({ session, reload, loadSession, disableDelete = false }: { session: Session; reload: () => void; loadSession: (session: Session) => Promise; disableDelete?: boolean }) { const [isLoading, setIsLoading] = useState(false); const deleteSession = async () => { if (!confirm("Are you sure you want to delete this session?")) return; setIsLoading(true); await axios .delete(`/api/sessions/${session.sessionId}`) .then(() => { toast.success(`Successfully delete session "${session.sessionId}"`); }) .catch((e) => { console.log(e); toast.error("Something went wrong, please try again later"); }) .finally(() => { reload(); setIsLoading(false); }); }; return (
ID: {session.sessionId} Date: {moment(session.date).format("DD/MM/YYYY - HH:mm")} {session.assignment && ( Assignment: {session.assignment.name} )}
{session.selectedModules.sort(sortByModuleName).map((module) => (
{module === "reading" && } {module === "listening" && } {module === "writing" && } {module === "speaking" && } {module === "level" && }
))}
); }