From 6a9ec907046934d26eaa5b79c497f0fe59e67f02 Mon Sep 17 00:00:00 2001 From: Pkpedram Date: Wed, 9 Mar 2022 15:40:15 +0330 Subject: [PATCH] Questionnaire Exam Order Can Change Now! --- src/redux/reducers/exam.js | 7 + .../addExam/views/AddQuestionsFromBank.js | 5 +- .../addExam/views/addQuestionnaireExam.js | 159 ++++++++++++------ 3 files changed, 114 insertions(+), 57 deletions(-) diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index b52c3aa..3c793b3 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -326,6 +326,13 @@ export default function addExamReduser(state = initialState, { type, payload }) } + case 'CHANGE_QUESTIONNAIRES_ORDER': + return { + ...state, + questionnaires: payload + + } + default: return state; diff --git a/src/view/addExam/views/AddQuestionsFromBank.js b/src/view/addExam/views/AddQuestionsFromBank.js index fa8717b..fd96318 100644 --- a/src/view/addExam/views/AddQuestionsFromBank.js +++ b/src/view/addExam/views/AddQuestionsFromBank.js @@ -422,11 +422,12 @@ const AddQuestionsFromBank = ({ grades, addExamState, dispatch, stepClick, backS
- +
@@ -161,16 +164,16 @@ const AddQuestionnaireExam = ({ grades, addExamState, dispatch, stepClick, backS
} { - addCoursePopup && + addCoursePopup && setAddCoursePopup(false)} - nameOnChange={e => setNewCourse({...newCourse, name: e.target.value})} - coefficientOnChange={e => setNewCourse({...newCourse, coefficient: e.target.vlaue})} - questionQuantityOnChange={e => setNewCourse({...newCourse, questionsQuantity: e.target.value, questionnaireId: selectedQuestionare.id})} - submitOnClick={() => {dispatch({type: 'ADD_QUESTIONNAIRE_COURSES', payload : newCourse}); setAddCoursePopup(false); setFakeState(fakeState + 356)} } - /> - - + closeOnClick={() => setAddCoursePopup(false)} + nameOnChange={e => setNewCourse({ ...newCourse, name: e.target.value })} + coefficientOnChange={e => setNewCourse({ ...newCourse, coefficient: e.target.vlaue })} + questionQuantityOnChange={e => setNewCourse({ ...newCourse, questionsQuantity: e.target.value, questionnaireId: selectedQuestionare.id })} + submitOnClick={() => { dispatch({ type: 'ADD_QUESTIONNAIRE_COURSES', payload: newCourse }); setAddCoursePopup(false); setFakeState(fakeState + 356) }} + /> + + }
@@ -181,21 +184,67 @@ const AddQuestionnaireExam = ({ grades, addExamState, dispatch, stepClick, backS

لطفا مشخضات آزمون را تکمیل کنید

+ { + const { source, destination } = result; + if (source.droppableId == 'Choosed_Questionnaires') { + // const data = { + // startIndex: choosedQuestion, + // endIndex: destination.index + // } + // dispatch({type:'CHANGE_QUESTION_ORDER', payload : data}) + // console.log(data) + + const aaa = [...addExamState.questionnaires]; + const [removed] = aaa.splice(source.index, 1); + + aaa.splice(destination.index, 0, removed); + dispatch({ type: 'CHANGE_QUESTIONNAIRES_ORDER', payload: aaa }) + console.log(result) + console.log(source.index) + console.log(destination.index) + console.log(aaa) - { - addExamState.questionnaires.map( - (item => ( -
setSelectedQuestionare({id : item.id,name: item.name, courses: addExamState.questionairesCourses.filter(itm => itm.questionnaireId == item.id)})} - > - -

- دفترچه {item.name} -

-
- )) - ) - } + } + }} + > + + {(provided) => ( +
+ +
+ { + addExamState.questionnaires.map( + ((item, index) => ( + + {(provided) => ( + +
setSelectedQuestionare({ id: item.id, name: item.name, courses: addExamState.questionairesCourses.filter(itm => itm.questionnaireId == item.id) })} + > + +

+ دفترچه {item.name} +

+
+ + )} + +
+ )) + ) + + } + +
+ + {provided.placeholder} +
+ )} +
+
addExamState.type == 'bank' ? console.log('bank') : setQuestionairePopUp(true)}>

@@ -215,38 +264,38 @@ const AddQuestionnaireExam = ({ grades, addExamState, dispatch, stepClick, backS

{ selectedQuestionare.id !== null && (<> -

- دفترچه {selectedQuestionare.name} -

-
-
- - { - addExamState.questionairesCourses.filter(itm => itm.questionnaireId == selectedQuestionare.id).map( - (item) => ( - {setSelectedCourse(item); console.log(selectedCourse)}}/> - ) - ) - } -
-
+

+ دفترچه {selectedQuestionare.name} +

+
+
+ + { + addExamState.questionairesCourses.filter(itm => itm.questionnaireId == selectedQuestionare.id).map( + (item) => ( + { setSelectedCourse(item); console.log(selectedCourse) }} /> + ) + ) + } +
+
) } {selectedQuestionare.id !== null &&
- +
}
- {setAnswers(data); setFakeState(fakeState - 2)}}/> + { setAnswers(data); setFakeState(fakeState - 2) }} />
- +