exam api | 245

main
alireza khaji 2 years ago
parent 578a025af5
commit 3e9308ed62
  1. 69
      src/components/Stepper/index.js
  2. 4
      src/redux/actions/exam.js
  3. 42
      src/redux/reducers/exam.js
  4. 8
      src/redux/reducers/exam2.js
  5. 9
      src/view/addExam/components/question.js
  6. 23
      src/view/addExam/views/AddQuestionsFromBank.js
  7. 289
      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 ${
@ -23,31 +21,56 @@ function Stepper({
<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="flex items-center justify-start w-full">
<div <div
className="w-8 h-8 text-white text-sm rounded-full flex justify-center items-center" className="w-8 h-8 text-white text-sm rounded-full flex justify-center items-center"
style={{ style={{
backgroundColor: backgroundColor: item.active ? activeColor : "#fff",
item.active ? activeColor : '#fff', border: item.active ? "" : "1px solid #c8c8c8",
border: item.active ? '' : '1px solid #c8c8c8'
}} }}
> >
{ {item.active ? (
item.active ? <svg width="37" height="37" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg
<path d="M7.75 12L10.58 14.83L16.25 9.17004" stroke="#fff" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/> width="37"
height="37"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.75 12L10.58 14.83L16.25 9.17004"
stroke="#fff"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg> </svg>
: null ) : null}
}
</div> </div>
<div className="flex justify-center items-center"> <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
<p className={` giveMeEllipsis font-bold ${item.active ? 'text-red26' : 'text-gray-400'} ${direction === 'horizontal' && 'text-xs' }`}> {item.title}</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"
@ -55,7 +78,7 @@ function Stepper({
: "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
@ -63,26 +86,24 @@ function Stepper({
// borderRight: direction === "vertical" ? `3px solid ${ // borderRight: direction === "vertical" ? `3px solid ${
// currentStep === Number(index) ? activeColor : deactiveColor // currentStep === Number(index) ? activeColor : deactiveColor
// }` : '', // }` : '',
transform : `${direction === "horizontal" ? 'translateY(1px)' : 'translateX(70px)'}` transform: `${
direction === "horizontal"
? "translateY(1px)"
: "translateX(70px)"
}`,
}} }}
></span> ></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: [
{ {
@ -258,8 +258,8 @@ 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 = []; optionsList = [];
for (let i = 0; i < data.type; i++) { for (let i = 0; i < data.type; i++) {
optionsList.push(data[`option${i + 1}`]); optionsList.push(data[`option${i + 1}`]);
} }
}) // console.log("==|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
console.log("==|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") // console.log(optionsList);
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,6 +335,8 @@ const AddQuestionsFromBank = ({
> >
{addExamState?.courses?.length > 0 && {addExamState?.courses?.length > 0 &&
addExamState.courses.map((item, index) => ( addExamState.courses.map((item, index) => (
<>
{console.log(item)}
<Draggable <Draggable
draggableId={`COURSE_${item.id}`} draggableId={`COURSE_${item.id}`}
index={index} index={index}
@ -373,7 +382,7 @@ const AddQuestionsFromBank = ({
</p> </p>
</div> </div>
<p className="text-red52">{item.title}</p> <p className="text-red52">{item?.name}</p>
<div className="w-full flex justify-between px-2 pb-2"> <div className="w-full flex justify-between px-2 pb-2">
<p <p
className={`w-1/2 border-l text-center text-xs ${ className={`w-1/2 border-l text-center text-xs ${
@ -392,6 +401,7 @@ const AddQuestionsFromBank = ({
</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 = [
"", "",
"اول", "اول",
@ -53,135 +71,86 @@ const ViewExam = ({ addExamState, stepClick, backStep, parentAdd }) => {
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) => (
>
<h1 className="text-xl">سوالات {item.title}</h1>
<p className="text-gray-500 pt-2">ضریب {item.coefficient}</p>
{item.selectedQuestions.map((question, idx) => (
<div <div
className={`flex flex-col w-full py-4 ${ key={index}
item.selectedQuestions.length !== idx + 1 && className="w-full mb-4 border-b border-[#d3d3d3]"
"border-b border-gray-200"
}`}
key={`PISHNAMAYESH__${question.questionId}`}
> >
{console.log(item.selectedQuestions.length)} <div className="w-full flex items-center">
{console.log(idx + 1)} <div className="w-8 h-8 bg-gray-300 flex items-center justify-center rounded-md ml-2">
<div className="flex items-start pb-4"> {index + 1}
<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>
))} ))}
</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>
<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>
)
)}
<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"
@ -202,11 +171,115 @@ 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