import Button from "@/components/Low/Button"; import { Module } from "@/interfaces"; import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react"; import { capitalize } from "lodash"; import React, { Fragment, useCallback, useEffect, useState } from "react"; import { FaFileDownload } from "react-icons/fa"; import { HiOutlineDocumentText } from "react-icons/hi"; import { IoInformationCircleOutline } from "react-icons/io5"; interface Props { module: Module; state: { isOpen: boolean, type: "exam" | "solutions" }; setState: React.Dispatch>; } const Templates: React.FC = ({ module, state, setState }) => { const [isClosing, setIsClosing] = useState(false); const [mounted, setMounted] = useState(false); useEffect(() => { if (state.isOpen) { setMounted(true); } }, [state]); useEffect(() => { if (!state.isOpen && mounted) { const timer = setTimeout(() => { setMounted(false); setIsClosing(false); }, 300); return () => clearTimeout(timer); } }, [state, mounted]); const blockMultipleClicksClose = useCallback(() => { if (isClosing) return; setIsClosing(true); setState({ isOpen: false, type: state.type }); const timer = setTimeout(() => { setIsClosing(false); }, 300); return () => clearTimeout(timer); }, [isClosing, setState, state]); if (!mounted && !state.isOpen) return null; const moduleExercises = { "reading": [ "Multiple Choice", "Write Blanks", "True False", "Paragraph Match", "Idea Match" ], "listening": [ "Multiple Choice", "True False", "Write Blanks: Questions", "Write Blanks: Fill", "Write Blanks: Form", ], "level": [ "Fill Blanks: Multiple Choice", "Multiple Choice: Blank Space", "Multiple Choice: Underline", "Multiple Choice: Reading Passage" ], "writing": [], "speaking": [], } const handleTemplateDownload = () => { const fileName = `${capitalize(module)}${state.type === "exam" ? "Exam" : "Solutions"}Template`; const url = `https://firebasestorage.googleapis.com/v0/b/encoach-staging.appspot.com/o/import_templates%2F${fileName}.docx?alt=media&token=b771a535-bf95-4060-889c-a086df65d480`; const link = document.createElement('a'); link.href = url; link.download = `${fileName}.docx`; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; return ( setIsClosing(false)} beforeLeave={() => setIsClosing(true)} afterLeave={() => { setIsClosing(false); setMounted(false); }} > blockMultipleClicksClose()} className="relative z-50">
{`${capitalize(module)} ${state.type === "exam" ? 'Exam' : 'Solutions'} Import`}
{state.type === "exam" ? ( <>

The {module} exam import accepts the following exercise types:

    {moduleExercises[module].map((item, index) => (
  • {item}
  • ))}

The uploaded document must:

  • be a Word .docx document.
  • have clear part and exercise delineation (e.g. Part 1, ... , Part X, Question 1 - 10, ... , Question y - x).
  • {["reading", "level"].includes(module) && (
  • a part must only contain a single reading passage and it must be between the part delineator (e.g. Part 1) and the part exercises.
  • )}
  • if solutions are going to be uploaded, the exercise numbers/id's must match the ones in the solutions.
) : <>

The uploaded document must:

  • be a Word .docx document.
  • match the exercise numbers/id's that are in the exam document.
}

{`The downloadable template is an example of a file that can be imported. Your document doesn't need to be a carbon copy of the template - it can have different styling and formatting but it must adhere to the previous requirements${state.type === "exam" ? " and exercises of the same type should have the same formatting" : ""}.`}

); } export default Templates;