diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index 179464f..d190a25 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -149,7 +149,7 @@ const initialState = { ], questions: [ - + ] } @@ -175,16 +175,7 @@ export default function addExamReduser(state = initialState, { type, payload }) description: payload.description, type: payload.type } - case 'ADD_EXAM_QUESTIONS': - return { - ...state, - name: payload.name, - startDate: new Date(), - endDate: new Date(), - startTime: '19:0', - endTime: '', - description: payload.description, - } + case 'ADD_EXAM_QUESTIONAIRES': return { ...state, @@ -216,6 +207,18 @@ export default function addExamReduser(state = initialState, { type, payload }) ...state, courses: state.courses.filter(itm => itm.id !== payload.id) } + + case 'ADD_EXAM_QUESTIONS': + return { + ...state, + questions : [...state.questions, payload] + } + + case 'REMOVE_EXAM_QUESTIONS': + return { + ...state, + questions: state.questions.filter(itm => itm.questionId !== payload.questionId) + } default: return state; diff --git a/src/view/addExam/views/AddQuestionsFromBank.js b/src/view/addExam/views/AddQuestionsFromBank.js index dfb8917..f484fa6 100644 --- a/src/view/addExam/views/AddQuestionsFromBank.js +++ b/src/view/addExam/views/AddQuestionsFromBank.js @@ -24,14 +24,14 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS const [showCoursesInList, setShowCoursesInList] = useState([]); const [choosedQuestionaries, seChoosedQuestionaries] = useState([]); const [selectedCourse, setSelectedCourse] = useState({ - id: null, + id: null, title: '' }); const [answers, setAnswers] = useState(null); const [newCourse, setNewCourse] = useState({ id: addExamState.questionairesCourses.length + 1, questionnaireId: selectedCourse.id, - questionsQuantity:20, + questionsQuantity: 20, name: '', coefficient: 4 }) @@ -42,21 +42,21 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS console.log(addExamState.questionairesCourses) console.log(selectedCourse) console.log(answers) - + const [fakeState, setFakeState] = useState(2); useEffect(() => { // questoinaresLists.map(item => showCoursesInList.push(false)); - if(answers !== null && answers !== []) { - answers.map(item => dispatch({type: 'ADD_ANSWERS', payload : item})) + if (answers !== null && answers !== []) { + answers.map(item => dispatch({ type: 'ADD_ANSWERS', payload: item })) } - + }, [answers]) const payload = { name: name, description: description, type: type }; - + return ( <> @@ -78,31 +78,31 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
تعداد دروس: {item.courses.length}
*/} - {/*{ + {/*
{ let newArray = [...showCoursesInList]; newArray[index] = !newArray[index]; @@ -112,15 +112,15 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS }}>نمایش دروس
*/} -dispatch({type: 'REMOVE_EXAM_COURSE', payload: item})}> + onClick={() => setSelectedCourse(item)} + > +
dispatch({ type: 'REMOVE_EXAM_COURSE', payload: item })}> x -
- -- {item.title} -
-+ {item.title} +
+- افزودن درس + افزودن درس