From 53626d38da7e049661bb6b87edba740d7c4d57e9 Mon Sep 17 00:00:00 2001 From: lavanyagarg112 Date: Sun, 22 Jun 2025 07:43:34 +0200 Subject: [PATCH 1/6] Add question box --- .../organisation/courses/ModuleForm.tsx | 162 ++++++++++++++++-- 1 file changed, 143 insertions(+), 19 deletions(-) diff --git a/components/organisation/courses/ModuleForm.tsx b/components/organisation/courses/ModuleForm.tsx index ef7b55c..271920a 100644 --- a/components/organisation/courses/ModuleForm.tsx +++ b/components/organisation/courses/ModuleForm.tsx @@ -10,6 +10,12 @@ interface Props { moduleId?: string; } +interface Question { + question_text: string; + question_type: "multiple_choice" | "true_false"; + options: { option_text: string; is_correct: boolean }[]; +} + export default function ModuleForm({ mode, courseId, moduleId }: Props) { const [name, setName] = useState(""); const [description, setDescription] = useState(""); @@ -19,6 +25,14 @@ export default function ModuleForm({ mode, courseId, moduleId }: Props) { const [moduleType, setModuleType] = useState("pdf"); + const [questions, setQuestions] = useState([ + { + question_text: "", + question_type: "multiple_choice", + options: [{ option_text: "", is_correct: false }], + }, + ]); + useEffect(() => { async function fetchModuleDetails() { try { @@ -162,23 +176,132 @@ export default function ModuleForm({ mode, courseId, moduleId }: Props) { -
- {" "} - setUploadFile(e.target.files?.[0] || null)} - required={mode === "create"} - className=" + {moduleType === "quiz" ? ( +
+

Quiz Questions

+ {questions.map((q, qi) => ( +
+ { + const qs = [...questions]; + qs[qi].question_text = e.target.value; + setQuestions(qs); + }} + className="w-full mb-2 p-2 border rounded" + /> + + {q.options.map((opt, oi) => ( +
+ { + const qs = [...questions]; + qs[qi].options[oi].option_text = e.target.value; + setQuestions(qs); + }} + className="flex-1 p-2 border rounded" + /> + + +
+ ))} + +
+ +
+ ))} + +
+ ) : ( +
+ {" "} + setUploadFile(e.target.files?.[0] || null)} + required={mode === "create"} + className=" block w-full mt-1 p-3 text-gray-600 bg-white @@ -197,8 +320,9 @@ export default function ModuleForm({ mode, courseId, moduleId }: Props) { file:font-semibold hover:file:bg-purple-700 " - /> -
+ /> +
+ )}
{mode === "edit" && (

From 6091bb77360ab396df1f5ab11731572013f16ef4 Mon Sep 17 00:00:00 2001 From: lavanyagarg112 Date: Sun, 22 Jun 2025 07:48:05 +0200 Subject: [PATCH 2/6] Add true or false questions --- .../organisation/courses/ModuleForm.tsx | 121 ++++++++++++------ 1 file changed, 80 insertions(+), 41 deletions(-) diff --git a/components/organisation/courses/ModuleForm.tsx b/components/organisation/courses/ModuleForm.tsx index 271920a..3f8da46 100644 --- a/components/organisation/courses/ModuleForm.tsx +++ b/components/organisation/courses/ModuleForm.tsx @@ -204,55 +204,94 @@ export default function ModuleForm({ mode, courseId, moduleId }: Props) { - {q.options.map((opt, oi) => ( -

- { - const qs = [...questions]; - qs[qi].options[oi].option_text = e.target.value; - setQuestions(qs); - }} - className="flex-1 p-2 border rounded" - /> - + {q.question_type === "true_false" ? ( +
+ {["True", "False"].map((label) => ( + + ))} +
+ ) : ( + <> + {q.options.map((opt, oi) => ( +
+ { + const qs = [...questions]; + qs[qi].options[oi].option_text = e.target.value; + setQuestions(qs); + }} + className="flex-1 p-2 border rounded" + /> + + +
+ ))} -
- ))} - + + )}