exam api | 245

main
alireza khaji 2 years ago
parent 578a025af5
commit 3e9308ed62
  1. 137
      src/components/Stepper/index.js
  2. 4
      src/redux/actions/exam.js
  3. 44
      src/redux/reducers/exam.js
  4. 8
      src/redux/reducers/exam2.js
  5. 17
      src/view/addExam/components/question.js
  6. 135
      src/view/addExam/views/AddQuestionsFromBank.js
  7. 309
      src/view/addExam/views/ViewExam.js
  8. 47
      src/view/addExam/views/addQuestions.js

@ -1,6 +1,6 @@
import React, {useState} from "react"; import React, { useState } from "react";
import separate from "../../utils/separate"; import separate from "../../utils/separate";
import './index.css' import "./index.css";
function Stepper({ function Stepper({
direction, direction,
@ -9,10 +9,8 @@ function Stepper({
count, count,
currentStep, currentStep,
steps, steps,
onStepClick onStepClick,
}) { }) {
return ( return (
<div <div
className={`flex items-center ${ className={`flex items-center ${
@ -20,69 +18,92 @@ function Stepper({
}`} }`}
> >
{steps.map((item, index) => ( {steps.map((item, index) => (
<div <div
key={index} key={index}
className={`flex items-center w-full relative ${ className={`flex items-center w-full relative ${
direction === "horizontal" ? "flex-row justify-between" : "flex-col justify-start" direction === "horizontal"
}`} ? "flex-row justify-between"
> : "flex-col justify-start"
<div className="flex items-center justify-start w-full"> }`}
<div >
className="w-8 h-8 text-white text-sm rounded-full flex justify-center items-center" <div className="flex items-center justify-start w-full">
style={{ <div
backgroundColor: className="w-8 h-8 text-white text-sm rounded-full flex justify-center items-center"
item.active ? activeColor : '#fff', style={{
border: item.active ? '' : '1px solid #c8c8c8' backgroundColor: item.active ? activeColor : "#fff",
}} border: item.active ? "" : "1px solid #c8c8c8",
> }}
{ >
item.active ? <svg width="37" height="37" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> {item.active ? (
<path d="M7.75 12L10.58 14.83L16.25 9.17004" stroke="#fff" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/> <svg
</svg> width="37"
: null height="37"
} viewBox="0 0 24 24"
</div> fill="none"
<div className="flex justify-center items-center"> xmlns="http://www.w3.org/2000/svg"
<p className={`mr-3 ml-1 text-xl font-bold ${item.active ? 'text-red-500' : 'text-gray-400'} text-opacity-50`}>{index + 1}</p> >
<p className={` giveMeEllipsis font-bold ${item.active ? 'text-red26' : 'text-gray-400'} ${direction === 'horizontal' && 'text-xs' }`}> {item.title}</p> <path
d="M7.75 12L10.58 14.83L16.25 9.17004"
stroke="#fff"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
) : null}
</div>
<div className="flex justify-center items-center">
<p
className={`mr-3 ml-1 text-xl font-bold ${
item.active ? "text-red-500" : "text-gray-400"
} text-opacity-50`}
>
{index + 1}
</p>
<p
className={` giveMeEllipsis font-bold ${
item.active ? "text-red26" : "text-gray-400"
} ${direction === "horizontal" && "text-xs"}`}
>
{" "}
{item.title}
</p>
</div>
</div> </div>
</div> {count !== Number(index) + 1 && (
{count !== (Number(index) + 1) && ( <span
<span className={`transform my-1 ${
className={`transform my-1 ${ direction === "horizontal"
direction === "horizontal" ? "w-full h-2 mx-4"
? "w-full h-2 mx-4" : "h-8 w-1 rounded-xl"
: "h-8 w-1 rounded-xl" }`}
}`} style={{
style={{ opacity: "0.5",
opacity: '0.5', background: item.active ? activeColor : deactiveColor,
background: item.active ? activeColor : deactiveColor, // borderTop: direction === "horizontal" ? `3px solid ${
// borderTop: direction === "horizontal" ? `3px solid ${ // currentStep === Number(index) ? activeColor : deactiveColor
// currentStep === Number(index) ? activeColor : deactiveColor // }` : '',
// }` : '', // borderRight: direction === "vertical" ? `3px solid ${
// borderRight: direction === "vertical" ? `3px solid ${ // currentStep === Number(index) ? activeColor : deactiveColor
// currentStep === Number(index) ? activeColor : deactiveColor // }` : '',
// }` : '', transform: `${
transform : `${direction === "horizontal" ? 'translateY(1px)' : 'translateX(70px)'}` direction === "horizontal"
}} ? "translateY(1px)"
></span> : "translateX(70px)"
}`,
)} }}
></span>
</div> )}
</div>
))} ))}
</div> </div>
); );
} }
export default Stepper; export default Stepper;
Stepper.defaultProps = { Stepper.defaultProps = {
direction: "vertical", direction: "vertical",
activeColor: "#df1452", activeColor: "#df1452",
deactiveColor: "#DBDBDB", deactiveColor: "#DBDBDB",
}; };

@ -9,6 +9,10 @@ const exam = {
(data = {}) => (data = {}) =>
async (dispatch) => async (dispatch) =>
await proxy.post("exam/parentAdd", data, { dispatch }), await proxy.post("exam/parentAdd", data, { dispatch }),
preview:
(data = {}) =>
async (dispatch) =>
await proxy.get("exam/preview", data, { dispatch }),
addExamDescription: (data = {}) => { addExamDescription: (data = {}) => {
return (dispatch) => { return (dispatch) => {
dispatch({ dispatch({

@ -52,20 +52,20 @@ const initialState = {
], ],
courseBank: [ courseBank: [
{ // {
id: 1, // id: 1,
title: 'ریاضی', // title: 'ریاضی',
coefficient: 4, // coefficient: 4,
numberOfOptions: 4, // numberOfOptions: 4,
selectedQuestions: [] // selectedQuestions: []
}, // },
{ // {
id: 2, // id: 2,
title: 'شیمی', // title: 'شیمی',
coefficient: 3, // coefficient: 3,
numberOfOptions: 3, // numberOfOptions: 3,
selectedQuestions: [] // selectedQuestions: []
}, // },
], ],
questionBank: [ questionBank: [
{ {
@ -257,9 +257,9 @@ export default function addExamReduser(state = initialState, { type, payload })
case 'ADD_EXAM_COURSE': case 'ADD_EXAM_COURSE':
return { return {
...state, ...state,
courses: [...state.courses, payload] courses: [...state.courses, { ...payload, selectedQuestions:[]}],
} };
case 'REMOVE_EXAM_COURSE': case 'REMOVE_EXAM_COURSE':
return { return {
...state, ...state,
@ -267,9 +267,15 @@ export default function addExamReduser(state = initialState, { type, payload })
} }
case 'ADD_EXAM_QUESTIONS': case 'ADD_EXAM_QUESTIONS':
console.log("??????????????");
console.log(payload) console.log(payload)
const othercourses = state.courses.filter(itm => itm.id !== payload.courseId) console.log(state.courses);
const selectedC = state.courses.filter(itm => itm.id == payload.courseId) const othercourses = state.courses.filter(
(itm) => itm.id !== payload.lessonId
);
const selectedC = state.courses.filter(
(itm) => itm.id == payload.lessonId
);
selectedC[0] = { ...selectedC[0], selectedQuestions: [payload, ...selectedC[0].selectedQuestions] } selectedC[0] = { ...selectedC[0], selectedQuestions: [payload, ...selectedC[0].selectedQuestions] }
const newCourses = [...othercourses, ...selectedC] const newCourses = [...othercourses, ...selectedC]

@ -5,16 +5,20 @@ import { toast } from "react-toastify";
const initialState = { const initialState = {
loading: false, loading: false,
error: null, error: null,
info:null info: null,
lastExamAdd: null,
preview : null
}; };
export default function exam2(state = initialState, action) { export default function exam2(state = initialState, action) {
let { type, data } = action; let { type, data } = action;
switch (type) { switch (type) {
case "exam/info": case "exam/info":
return { ...state, loading: false, info: data, error: null }; return { ...state, loading: false, info: data, error: null };
case "exam/preview":
return { ...state, loading: false, preview: data, error: null };
case "exam/parentAdd": case "exam/parentAdd":
toast.success("آزمون شما با موفقیت ثبت شد"); toast.success("آزمون شما با موفقیت ثبت شد");
return { ...state, loading: false, error: null }; return { ...state, loading: false, error: null, lastExamAdd: data.id };
default: default:
return state; return state;
} }

@ -4,14 +4,15 @@ import React, { useEffect } from 'react';
let optionsList = []; let optionsList = [];
const Question = ({data}) => { const Question = ({data}) => {
useEffect(()=>{ // useEffect(()=>{
optionsList=[];
for (let i = 0; i < data.type; i++) { // })
optionsList.push(data[`option${i + 1}`]); optionsList = [];
} for (let i = 0; i < data.type; i++) {
}) optionsList.push(data[`option${i + 1}`]);
console.log("==|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") }
console.log(optionsList); // console.log("==|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
// console.log(optionsList);
const gozine = [ const gozine = [
'الف', 'الف',
'ب', 'ب',

@ -32,6 +32,7 @@ const AddQuestionsFromBank = ({
removeQuestionFromBank, removeQuestionFromBank,
removeExamQuestions, removeExamQuestions,
getQuestionBackToBank, getQuestionBackToBank,
submitHandler,
}) => { }) => {
const [name, setName] = useState(null); const [name, setName] = useState(null);
const [type, setType] = useState(null); const [type, setType] = useState(null);
@ -171,6 +172,11 @@ const AddQuestionsFromBank = ({
let name = document.querySelector("#addLessonPartInput").value; let name = document.querySelector("#addLessonPartInput").value;
addLesson({ name }); addLesson({ name });
}; };
const nextStephandler=()=>{
submitHandler();
stepClick();
}
return ( return (
<div className="flex flex-col h-screen relative"> <div className="flex flex-col h-screen relative">
{questionarePopUp && ( {questionarePopUp && (
@ -281,6 +287,7 @@ const AddQuestionsFromBank = ({
)} )}
</div> </div>
)} )}
{/* ====================================================================================== */}
<div className="flex py-3 items-center px-10 border-b border-gray-200"> <div className="flex py-3 items-center px-10 border-b border-gray-200">
<div className="flex flex-col w-1/6"> <div className="flex flex-col w-1/6">
<div className="text-blue3A text-lg font-bold text-right px-4 border-r-4 border-blue65"> <div className="text-blue3A text-lg font-bold text-right px-4 border-r-4 border-blue65">
@ -328,70 +335,73 @@ const AddQuestionsFromBank = ({
> >
{addExamState?.courses?.length > 0 && {addExamState?.courses?.length > 0 &&
addExamState.courses.map((item, index) => ( addExamState.courses.map((item, index) => (
<Draggable <>
draggableId={`COURSE_${item.id}`} {console.log(item)}
index={index} <Draggable
key={`CHOOSED_COURSE_${item.id}`} draggableId={`COURSE_${item.id}`}
> index={index}
{(provided) => ( key={`CHOOSED_COURSE_${item.id}`}
<div >
{...provided.draggableProps} {(provided) => (
{...provided.dragHandleProps}
ref={provided.innerRef}
className={`flex flex-col ${
selectedCourse.id === item.id
? "bg-pinkF5 border border-red52 text-red52"
: "bg-white border border-gray-300 text-blue3A"
} items-center justify-between pt-4 w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`}
onClick={() => {
setSelectedCourse(item);
setActiveCourse(item.id);
}}
>
<div <div
className="w-full flex justify-between items-center " {...provided.draggableProps}
style={{ direction: "ltr" }} {...provided.dragHandleProps}
ref={provided.innerRef}
className={`flex flex-col ${
selectedCourse.id === item.id
? "bg-pinkF5 border border-red52 text-red52"
: "bg-white border border-gray-300 text-blue3A"
} items-center justify-between pt-4 w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`}
onClick={() => {
setSelectedCourse(item);
setActiveCourse(item.id);
}}
> >
<div className=" rtl px-2 text-white bg-red52"> <div
{item?.selectedQuestions?.length} سوال className="w-full flex justify-between items-center "
style={{ direction: "ltr" }}
>
<div className=" rtl px-2 text-white bg-red52">
{item?.selectedQuestions?.length} سوال
</div>
<p className=" text-left px-4">
<span
onClick={() => {
dispatch({
type: "REMOVE_EXAM_COURSE",
payload: item,
});
setSelectedCourse(null);
setFakeState(fakeState + 24);
}}
>
{" "}
x{" "}
</span>
</p>
</div> </div>
<p className=" text-left px-4"> <p className="text-red52">{item?.name}</p>
<span <div className="w-full flex justify-between px-2 pb-2">
onClick={() => { <p
dispatch({ className={`w-1/2 border-l text-center text-xs ${
type: "REMOVE_EXAM_COURSE", selectedCourse.id === item.id
payload: item, ? "border-red52"
}); : "border-gray-300"
setSelectedCourse(null); } text-gray-400`}
setFakeState(fakeState + 24);
}}
> >
{" "} {" "}
x{" "} ضریب {item.coefficient}
</span> </p>
</p> <p className="w-1/2 text-center text-xs font-light text-gray-400">
</div> {item.numberOfOptions} گزینه
</p>
<p className="text-red52">{item.title}</p> </div>
<div className="w-full flex justify-between px-2 pb-2">
<p
className={`w-1/2 border-l text-center text-xs ${
selectedCourse.id === item.id
? "border-red52"
: "border-gray-300"
} text-gray-400`}
>
{" "}
ضریب {item.coefficient}
</p>
<p className="w-1/2 text-center text-xs font-light text-gray-400">
{item.numberOfOptions} گزینه
</p>
</div> </div>
</div> )}
)} </Draggable>
</Draggable> </>
))} ))}
</div> </div>
</div> </div>
@ -409,6 +419,7 @@ const AddQuestionsFromBank = ({
</div> </div>
</div> </div>
</div> </div>
{/* ====================================================================================== */}
{/* Picking Question Container */} {/* Picking Question Container */}
<DragDropContext <DragDropContext
onDragEnd={(result) => handleOnDragEnd(result)} onDragEnd={(result) => handleOnDragEnd(result)}
@ -421,10 +432,10 @@ const AddQuestionsFromBank = ({
)[0]?.selectedQuestions[result.source.index] )[0]?.selectedQuestions[result.source.index]
); );
} else { } else {
console.log("MMMMMMMMMMMMMMMMMMMM");
console.log(result);
seChoosedQuestion( seChoosedQuestion(
addExamState.questionBank.find( questionList?.find((itm) => itm.id == result.source.index)
(itm) => itm.questionId == result.source.index
)
); );
} }
}} }}
@ -776,9 +787,7 @@ const AddQuestionsFromBank = ({
<Button <Button
title="مرحله بعدی" title="مرحله بعدی"
className="w-1/12" className="w-1/12"
onClick={() => { onClick={nextStephandler}
stepClick();
}}
/> />
</div> </div>
</div> </div>

@ -11,13 +11,31 @@ import '@react-pdf-viewer/core/lib/styles/index.css';
import Preview from "../../../components/AnswerSheet/preview"; import Preview from "../../../components/AnswerSheet/preview";
import { exam } from "../../../redux/actions"; import { exam } from "../../../redux/actions";
import moment from "jalali-moment"; import moment from "jalali-moment";
import preview from "../../../components/AnswerSheet/preview";
const ViewExam = ({ addExamState, stepClick, backStep, parentAdd }) => { const ViewExam = ({
addExamState,
stepClick,
backStep,
parentAdd,
examPreview,
examId,
getExamPreview,
}) => {
useEffect(() => { useEffect(() => {
window.scrollTo(0, 0); window.scrollTo(0, 0);
console.log("oooooooooooooooooooooooooooooo"); console.log("oooooooooooooooooooooooooooooo");
console.log(addExamState); console.log(addExamState);
console.log(examId);
}, []); }, []);
useEffect(() => {
getExamPreview({ id: examId });
// getExamPreview({ id: 9 });
}, [examId]);
console.log(examPreview);
const grades = [ const grades = [
"", "",
"اول", "اول",
@ -46,142 +64,93 @@ const ViewExam = ({ addExamState, stepClick, backStep, parentAdd }) => {
} }
let questionCount = 0; let questionCount = 0;
for(let i=0;i<addExamState.courses.length;i++){ for (let i = 0; i < addExamState.courses.length; i++) {
questionCount += addExamState.courses[i].selectedQuestions.length; questionCount += addExamState.courses[i].selectedQuestions.length;
} }
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>"); console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
console.log(addExamState.startDate.month); console.log(addExamState.startDate.month);
const submitHandler=()=>{ const submitHandler = () => {
parentAdd({
name: addExamState.name,
description: addExamState.description,
// startDate: moment(
// `${addExamState.startDate?.year}/${addExamState.startDate?.month}/${addExamState.startDate?.day} ${addExamState.startDate?.hour}:${addExamState.startDate?.minute}`
// )
// .locale("en")
// .format("YYYY-MM-DD HH:mm"),
startDate: moment
.from(
`${addExamState.startDate?.year}/${addExamState.startDate?.month}/${addExamState.startDate?.day} ${addExamState.startDate?.hour}:${addExamState.startDate?.minute}`,
"fa",
"YYYY/MM/DD HH:mm"
)
.format("YYYY-MM-DD HH:mm"),
endDate: moment
.from(
`${addExamState.endDate?.year}/${addExamState.endDate?.month}/${addExamState.endDate?.day} ${addExamState.endDate?.hour}:${addExamState.endDate?.minute}`,
"fa",
"YYYY/MM/DD HH:mm"
)
.format("YYYY-MM-DD HH:mm"),
duration: addExamState?.duration || 60,
// duration:30,
type: addExamState.type,
//questionCount: addExamState.questions.length,
questionCount,
examGroupId: addExamState.groupId,
levelCriterion: null,
budgetFileId: addExamState.budgetFileId,
});
// stepClick(); // stepClick();
} };
const createOptions = (item) => {
let optionsList = [];
for (let i = 0; i < item.type; i++) {
optionsList.push(item[`option${i + 1}`]);
}
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
console.log(optionsList);
return optionsList;
};
return ( return (
<div className="w-[95%] flex flex-col mx-10"> <div className="w-[95%] flex flex-col mx-10">
<div className="w-4/5 py-6 flex items-center"> <div className="w-4/5 py-6 flex items-center">
<h1 className="text-2xl font-bold ml-6">آزمون {addExamState.name}</h1> <h1 className="text-2xl font-bold ml-6">
<h3 className="text-gray-500"> پایه {grades[addExamState.grade]}</h3> آزمون {examPreview?.exam?.name}
</h1>
<h3 className="text-gray-500">
{" "}
پایه {grades[examPreview?.exam?.gradeId]}
</h3>
</div> </div>
{addExamState.type !== "pdf" ? (
<div className="w-full flex flex-col text-right"> <div className="w-full mt-6 pb-6 border-b">
{addExamState.courses.map((item, index) => ( {examPreview?.exam?.type && (
<div <div className="w-full">
className={`flex flex-col w-full py-6 border-b-2 border-gray-400`} {examPreview?.questions?.map((item, index) => (
> <div
<h1 className="text-xl">سوالات {item.title}</h1> key={index}
<p className="text-gray-500 pt-2">ضریب {item.coefficient}</p> className="w-full mb-4 border-b border-[#d3d3d3]"
{item.selectedQuestions.map((question, idx) => ( >
<div <div className="w-full flex items-center">
className={`flex flex-col w-full py-4 ${ <div className="w-8 h-8 bg-gray-300 flex items-center justify-center rounded-md ml-2">
item.selectedQuestions.length !== idx + 1 && {index + 1}
"border-b border-gray-200"
}`}
key={`PISHNAMAYESH__${question.questionId}`}
>
{console.log(item.selectedQuestions.length)}
{console.log(idx + 1)}
<div className="flex items-start pb-4">
<h1 className="text-xl">{question.title}</h1>
<p className="w-1/12 pr-4">{question.score} نمره</p>
</div> </div>
{question.options.map((option) => ( <div className="w-full text-lg text-right">
<div className="flex w-full my-2 items-center"> {item?.text}{" "}
<span className="text-sm">{`(نمره : ${
item?.score || 1
})`}</span>
</div>
</div>
<div className="w-full mt-4">
{createOptions(item).map((choice, index2) => (
<div key={index2} className="w-full flex items-stretch mb-2">
<div <div
className={`${ className="w-12 py-3 rounded-r-md flex items-center justify-center bg-gray-300"
option.isAnswer style={
? "bg-green-400 text-white" choice === item.answer
: "bg-gray-300" ? { backgroundColor: "#65A30D", color: "#fff" }
} w-16 h-14 text-xl flex items-center justify-center rounded-xl rounded-l-none`} : null
}
> >
{optionNum[option.id]} {optionNum[index2 + 1]}
</div> </div>
<div <div
className={`w-1/4 flex items-center px-6 ${ className="py-3 rounded-l-md flex items-center px-2 bg-gray-200"
option.isAnswer ? "bg-green-200" : "bg-gray-200" style={
} h-14 rounded-xl rounded-r-none`} choice === item.answer
? {
backgroundColor: "#84CC16",
color: "#fff",
width: "calc(100% - 48px)",
}
: { width: "calc(100% - 48px)" }
}
> >
{option.title} {choice}
</div> </div>
</div> </div>
))} ))}
</div> </div>
))}
</div>
))}
</div>
) : (
addExamState.type === "pdf" && (
<div className="flex flex-col w-full items-center">
<h1 className="w-full text-right pb-4 text-lg font-bold">
دفترچه ها
</h1>
<div className="w-full flex flex-wrap">
{addExamState?.questionnaires?.map((item) => (
<div
className={`flex flex-col ${
selectedCourse.id === item?.id
? "bg-pinkF5 border border-red52 text-red52"
: "bg-white border border-gray-300 text-blue3A"
} items-center justify-center w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`}
onClick={() => setSelectedCourse(item)}
>
<p className="text-red52">{item.name}</p>
</div>
))}
</div>
<div className="flex w-full border-t border-gray-200 mt-10">
<div
className="w-1/2 border-l border-gray-200 py-20 "
style={{ height: "750px" }}
>
<Worker workerUrl="https://unpkg.com/pdfjs-dist@2.13.216/build/pdf.worker.min.js">
<Viewer fileUrl={selectedCourse.fileUrl} />
</Worker>
</div> </div>
<div ))}
className="w-1/2 my-20 flex justify-center overflow-x-hidden overflow-scroll"
style={{ height: "600px" }}
>
<div className="w-2/3">
<Preview answers={selectedCourse.answers} />
</div>
</div>
</div>
</div> </div>
) )}
)} </div>
<div className="w-full flex justify-end font-bold mt-6"> <div className="w-full flex justify-end font-bold mt-6">
<button <button
className="py-4 font-bold px-6 rounded-lg text-red52 mr-4" className="py-4 font-bold px-6 rounded-lg text-red52 mr-4"
@ -201,12 +170,116 @@ const ViewExam = ({ addExamState, stepClick, backStep, parentAdd }) => {
}; };
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
grades: state.publicApi.grades, grades: state.publicApi.grades,
addExamState: state.addExamReduser addExamState: state.addExamReduser,
}) examId: state.exam2.lastExamAdd,
examPreview:state.exam2.preview
});
const mapDispatchToProps = { const mapDispatchToProps = {
parentAdd: exam.parentAdd, parentAdd: exam.parentAdd,
getExamPreview : exam.preview
}; };
export default connect(mapStateToProps, mapDispatchToProps)(ViewExam); export default connect(mapStateToProps, mapDispatchToProps)(ViewExam);
// question.options;
// {
// addExamState.type !== "pdf" ? (
// <div className="w-full flex flex-col text-right">
// {addExamState.courses?.map((item, index) => (
// <div className={`flex flex-col w-full py-6 border-b-2 border-gray-400`}>
// <h1 className="text-xl">سوالات {item?.name}</h1>
// <p className="text-gray-500 pt-2">ضریب {item?.coefficient}</p>
// {item?.selectedQuestions?.map((question, idx) => (
// <div
// className={`flex flex-col w-full py-4 ${
// item.selectedQuestions.length !== idx + 1 &&
// "border-b border-gray-200"
// }`}
// key={`PISHNAMAYESH__${question.id}`}
// >
// {console.log(item.selectedQuestions.length)}
// {console.log(idx + 1)}
// <div className="flex items-start pb-4">
// <h1 className="text-xl">{question?.text}</h1>
// <p className="w-1/12 pr-4">{question?.score} نمره</p>
// </div>
// {createOptions(question).map((option, INDEX) => (
// <div className="flex w-full my-2 items-center">
// <div
// className={`${
// option.isAnswer
// ? "bg-green-400 text-white"
// : "bg-gray-300"
// } w-16 h-14 text-xl flex items-center justify-center rounded-xl rounded-l-none`}
// >
// {optionNum[INDEX + 1]}
// </div>
// <div
// className={`w-1/4 flex items-center px-6 ${
// option.isAnswer ? "bg-green-200" : "bg-gray-200"
// } h-14 rounded-xl rounded-r-none`}
// >
// {option}
// </div>
// </div>
// ))}
// </div>
// ))}
// </div>
// ))}
// </div>
// ) : (
// addExamState.type === "pdf" && (
// <div className="flex flex-col w-full items-center">
// <h1 className="w-full text-right pb-4 text-lg font-bold">دفترچه ها</h1>
// <div className="w-full flex flex-wrap">
// {addExamState?.questionnaires?.map((item) => (
// <div
// className={`flex flex-col ${
// selectedCourse.id === item?.id
// ? "bg-pinkF5 border border-red52 text-red52"
// : "bg-white border border-gray-300 text-blue3A"
// } items-center justify-center w-36 h-32 mx-2 font-bold rounded-xl cursor-pointer`}
// onClick={() => setSelectedCourse(item)}
// >
// <p className="text-red52">{item.name}</p>
// </div>
// ))}
// </div>
// <div className="flex w-full border-t border-gray-200 mt-10">
// <div
// className="w-1/2 border-l border-gray-200 py-20 "
// style={{ height: "750px" }}
// >
// <Worker workerUrl="https://unpkg.com/pdfjs-dist@2.13.216/build/pdf.worker.min.js">
// <Viewer fileUrl={selectedCourse.fileUrl} />
// </Worker>
// </div>
// <div
// className="w-1/2 my-20 flex justify-center overflow-x-hidden overflow-scroll"
// style={{ height: "600px" }}
// >
// <div className="w-2/3">
// <Preview answers={selectedCourse.answers} />
// </div>
// </div>
// </div>
// </div>
// )
// );
// }

@ -1,3 +1,4 @@
import moment from "jalali-moment";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import AnswerSheet from "../../../components/AnswerSheet"; import AnswerSheet from "../../../components/AnswerSheet";
@ -6,7 +7,7 @@ import DatePicker from "../../../components/Calendar/CalendarComponents/DatePick
import Checkbox from "../../../components/Checkbox"; import Checkbox from "../../../components/Checkbox";
import RangeDatePicker from "../../../components/RangeDatePicker"; import RangeDatePicker from "../../../components/RangeDatePicker";
import SelectedCourse from "../../../components/selectedCourse"; import SelectedCourse from "../../../components/selectedCourse";
import { lesson } from "../../../redux/actions"; import { exam, lesson } from "../../../redux/actions";
import AddQuestionnaireCourse from "../components/addQuestionnaireCourse"; import AddQuestionnaireCourse from "../components/addQuestionnaireCourse";
import AddQuestionnaireExam from "./addQuestionnaireExam"; import AddQuestionnaireExam from "./addQuestionnaireExam";
import AddQuestionsFromBank from "./AddQuestionsFromBank"; import AddQuestionsFromBank from "./AddQuestionsFromBank";
@ -19,11 +20,51 @@ const AddQuestions = ({
lessonList, lessonList,
addLesson, addLesson,
lastAdd, lastAdd,
parentAdd,
}) => { }) => {
useEffect(() => { useEffect(() => {
getLesson(); getLesson();
}, [lastAdd]); }, [lastAdd]);
const submitHandler = () => {
let questionCount = 0;
for (let i = 0; i < addExamState.courses.length; i++) {
questionCount += addExamState.courses[i].selectedQuestions.length;
}
parentAdd({
name: addExamState.name,
description: addExamState.description,
// startDate: moment(
// `${addExamState.startDate?.year}/${addExamState.startDate?.month}/${addExamState.startDate?.day} ${addExamState.startDate?.hour}:${addExamState.startDate?.minute}`
// )
// .locale("en")
// .format("YYYY-MM-DD HH:mm"),
startDate: moment
.from(
`${addExamState.startDate?.year}/${addExamState.startDate?.month}/${addExamState.startDate?.day} ${addExamState.startDate?.hour}:${addExamState.startDate?.minute}`,
"fa",
"YYYY/MM/DD HH:mm"
)
.format("YYYY-MM-DD HH:mm"),
endDate: moment
.from(
`${addExamState.endDate?.year}/${addExamState.endDate?.month}/${addExamState.endDate?.day} ${addExamState.endDate?.hour}:${addExamState.endDate?.minute}`,
"fa",
"YYYY/MM/DD HH:mm"
)
.format("YYYY-MM-DD HH:mm"),
duration: addExamState?.duration || 60,
// duration:30,
type: addExamState.type,
//questionCount: addExamState.questions.length,
questionCount :questionCount,
examGroupId: addExamState.groupId,
levelCriterion: null,
budgetFileId: addExamState.budgetFileId,
});
// stepClick();
};
return addExamState.type == 2 ? ( return addExamState.type == 2 ? (
<AddQuestionnaireExam stepClick={stepClick} backStep={backStep} /> <AddQuestionnaireExam stepClick={stepClick} backStep={backStep} />
) : ( ) : (
@ -32,6 +73,7 @@ const AddQuestions = ({
backStep={backStep} backStep={backStep}
lessonList={lessonList} lessonList={lessonList}
addLesson={addLesson} addLesson={addLesson}
submitHandler={submitHandler}
/> />
); );
}; };
@ -45,7 +87,8 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = { const mapDispatchToProps = {
getLesson: lesson.list, getLesson: lesson.list,
addLesson: lesson.add addLesson: lesson.add,
parentAdd: exam.parentAdd,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(AddQuestions); export default connect(mapStateToProps, mapDispatchToProps)(AddQuestions);

Loading…
Cancel
Save