From 3a7f53ca9b3004f67f734448721299fa9a065623 Mon Sep 17 00:00:00 2001 From: Alireza khaji Date: Tue, 28 Jun 2022 16:52:01 +0430 Subject: [PATCH] exam/parentAdd api | 330 --- src/components/Product/index.js | 30 --- src/redux/actions/exam.js | 4 + src/redux/reducers/exam.js | 22 +- src/redux/reducers/exam2.js | 2 + src/view/addExam/views/AddDescription.js | 256 +++++++++++-------- src/view/addExam/views/AddGradeGroup.js | 3 + src/view/addExam/views/OkExam.js | 4 + src/view/addExam/views/ViewExam.js | 304 +++++++++++++---------- src/view/services/service/index.js | 185 +++++++++----- 9 files changed, 465 insertions(+), 345 deletions(-) diff --git a/src/components/Product/index.js b/src/components/Product/index.js index bccfeed..d3331c0 100644 --- a/src/components/Product/index.js +++ b/src/components/Product/index.js @@ -54,36 +54,6 @@ const ProductDesign = ({ ); console.log(userInfo); let rulesAccepted = userInfo.rulesAccepted; - const emkanat = [ - { - title: "دستشویی", - isActive: true, - }, - { - title: "آب خوری", - isActive: true, - }, - { - title: "تخته هوشمند", - isActive: true, - }, - { - title: "کامپیوتر", - isActive: true, - }, - { - title: "کتابخانه", - isActive: true, - }, - { - title: "مشاوره تحصیلی", - isActive: true, - }, - { - title: "آزمایشگاه", - isActive: false, - }, - ]; //budgetHandler------------- const budgetHandler = (fileId) => { diff --git a/src/redux/actions/exam.js b/src/redux/actions/exam.js index 8e90ec5..fe01c92 100644 --- a/src/redux/actions/exam.js +++ b/src/redux/actions/exam.js @@ -5,6 +5,10 @@ const exam = { (data = {}) => async (dispatch) => await proxy.get("exam/info", data, { dispatch }), + parentAdd: + (data = {}) => + async (dispatch) => + await proxy.post("exam/parentAdd", data, { dispatch }), }; export default exam; \ No newline at end of file diff --git a/src/redux/reducers/exam.js b/src/redux/reducers/exam.js index 0cd6c2a..12dabd9 100644 --- a/src/redux/reducers/exam.js +++ b/src/redux/reducers/exam.js @@ -11,6 +11,7 @@ const initialState = { endTime: '', description: '', type: 'bank', + duration:null, questionnaires: [ { @@ -207,15 +208,18 @@ export default function addExamReduser(state = initialState, { type, payload }) case 'ADD_EXAM_DESCRIPTION': return { - ...state, - name: payload.name, - startDate: new Date(), - endDate: new Date(), - startTime: '19:0', - endTime: '', - description: payload.description, - type: payload.type - } + ...state, + name: payload.name, + startDate: new Date(), + endDate: new Date(), + startTime: "19:0", + endTime: "", + description: payload.description, + type: payload.type, + duration: payload.duration, + startDate:payload.startDate, + endDate:payload.endDate + }; case 'ADD_EXAM_QUESTIONAIRES': return { diff --git a/src/redux/reducers/exam2.js b/src/redux/reducers/exam2.js index 9512e53..43b2e59 100644 --- a/src/redux/reducers/exam2.js +++ b/src/redux/reducers/exam2.js @@ -12,6 +12,8 @@ export default function exam2(state = initialState, action) { switch (type) { case "exam/info": return { ...state, loading: false, info: data, error: null }; + case "exam/parentAdd": + return { ...state, loading: false, error: null }; default: return state; } diff --git a/src/view/addExam/views/AddDescription.js b/src/view/addExam/views/AddDescription.js index 0a5ae5b..f621e16 100644 --- a/src/view/addExam/views/AddDescription.js +++ b/src/view/addExam/views/AddDescription.js @@ -13,121 +13,165 @@ const AddExamDescription = ({ grades, addExamState, dispatch, stepClick, backSte const [name, setName] = useState(null); const [type, setType] = useState(null); const [description, setDescription] = useState(null); - - const payload = { name: name, description: description, type: type }; - const CostumeDatePickerInput = ({ openCalendar, value, handleValueChange, title }) => { - return( - { + return ( + changeHandler(e)} placeholder={title} - className="w-full h-14 rounded-lg p-3 border border-gray-200 text-blue3A outline-blue-300" + className="create-exame-date-input w-full h-14 rounded-lg p-3 border border-gray-200 text-blue3A outline-blue-300" /> - ) + ); } - return ( - <> -
-
-
- تنظیمات آزمون - -
-

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

-
- -
-
- setName(e.target.value)} - /> - ( - - )} - - render={} - plugins={[ - , - - ]} - /> - ( - - )} - - render={} - plugins={[ - , - - ]} - /> -
- - - - -
+ const dateChangeHandler=(index)=>{ + let inputs = document.querySelectorAll(".create-exame-date-input"); + console.log(inputs[index].value); + let dateList = inputs[index].value.split(" ")[0].split("/"); + let timeList = inputs[index].value.split(" ")[1].split(":"); + console.log(dateList); + console.log(timeList); + console.log(Number(dateList[0])); + } + return ( + <> +
+
+
+ تنظیمات آزمون
- -
-
-
- تنظیمات آزمون - -
-

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

-
- -
- -
setType('bank')}> - بانک سوالات - - -
-
setType('pdf')}> - دفترچه سوالات - - -
- -
+

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

+
+ +
+
+ setName(e.target.value)} + /> + dateChangeHandler(0)} + onChange={setStartDate} + renderButton={(direction, handleClick) => ( + + )} + render={ + + } + plugins={[]} + /> + ( + + )} + render={ + + } + plugins={[]} + />
-
- -
+
+ +
+
+
+ نوع آزمون
- - - ) +

+ لطفا یک مدل از آزمون را انتخاب کنید +

+
+ +
+
setType(1)} + > + بانک سوالات +
+
setType(2)} + > + دفترچه سوالات +
+
+
+
+ +
+ + ); } const mapStateToProps = (state) => ({ diff --git a/src/view/addExam/views/AddGradeGroup.js b/src/view/addExam/views/AddGradeGroup.js index 8289d80..e2be940 100644 --- a/src/view/addExam/views/AddGradeGroup.js +++ b/src/view/addExam/views/AddGradeGroup.js @@ -2,6 +2,7 @@ import React, { useState } from "react"; import { connect } from "react-redux"; import Button from "../../../components/Button"; +import { exam } from "../../../redux/actions"; const AddGradeGroup = ({grades, addExamState, dispatch, stepClick}) => { const [examGrade, setExamGrade] = useState(null); @@ -82,4 +83,6 @@ const mapStateToProps = (state) => ({ addExamState: state.addExamReduser }) + + export default connect(mapStateToProps)(AddGradeGroup); \ No newline at end of file diff --git a/src/view/addExam/views/OkExam.js b/src/view/addExam/views/OkExam.js index 3d82e9f..4fafd05 100644 --- a/src/view/addExam/views/OkExam.js +++ b/src/view/addExam/views/OkExam.js @@ -6,6 +6,8 @@ import AddQuestionnaireExam from "./addQuestionnaireExam"; import AddQuestionsFromBank from "./AddQuestionsFromBank"; const OkExam = ({ addExamState, stepClick, backStep }) => { + console.log("examInfo:----------------------------------------"); + console.log(addExamState); const grades = [ '', 'اول', @@ -63,4 +65,6 @@ const mapStateToProps = (state) => ({ addExamState: state.addExamReduser }) + + export default connect(mapStateToProps)(OkExam); \ No newline at end of file diff --git a/src/view/addExam/views/ViewExam.js b/src/view/addExam/views/ViewExam.js index 7f59f69..2be6268 100644 --- a/src/view/addExam/views/ViewExam.js +++ b/src/view/addExam/views/ViewExam.js @@ -9,146 +9,186 @@ import { Viewer } from '@react-pdf-viewer/core'; // Import the styles import '@react-pdf-viewer/core/lib/styles/index.css'; import Preview from "../../../components/AnswerSheet/preview"; - -const ViewExam = ({ addExamState, stepClick, backStep }) => { - useEffect(() => { - window.scrollTo(0, 0); - console.log(addExamState.type) - }, []) - const grades = [ - '', - 'اول', - 'دوم', - 'سوم', - 'چهارم', - 'پنجم', - 'ششم', - 'هفتم', - 'هشتم', - 'نهم', - 'دهم', - 'یازدهم', - 'دوازدهم', - ] - const optionNum = [ - '', - 'الف', - 'ب', - 'پ', - 'ت', - 'ث', - 'ج', - 'چ', - 'ح', - - ] - - const [selectedCourse, setSelectedCourse] = useState(addExamState?.questionnaires[0]); - - const [numPages, setNumPages] = useState(1); - - function onDocumentLoadSuccess({ numPages }) { - setNumPages(numPages); - } - - return ( - -
-
-

آزمون {addExamState.name}

-

پایه {grades[addExamState.grade]}

-
- {addExamState.type !== 'pdf' ?
- { - addExamState.courses.map((item, index) => ( -
-

سوالات {item.title}

-

ضریب {item.coefficient}

- { - item.selectedQuestions.map((question, idx) => ( -
- {console.log(item.selectedQuestions.length)} - {console.log(idx + 1)} -
-

{question.title}

-

{question.score} نمره

-
- { - question.options.map((option) => ( -
-
- {optionNum[option.id]} -
-
- {option.title} -
-
- )) - } -
- )) - } -
- )) - } -
: - addExamState.type === 'pdf' && -
-

دفترچه ها

-
- { - addExamState?.questionnaires?.map((item) => ( -
setSelectedCourse(item)} - > - - -

- {item.name} -

-
- )) - } -
- -
-
- - - -
-
-
- -
-
+import { exam } from "../../../redux/actions"; + +const ViewExam = ({ addExamState, stepClick, backStep, parentAdd }) => { + useEffect(() => { + window.scrollTo(0, 0); + console.log("oooooooooooooooooooooooooooooo"); + console.log(addExamState); + }, []); + const grades = [ + "", + "اول", + "دوم", + "سوم", + "چهارم", + "پنجم", + "ششم", + "هفتم", + "هشتم", + "نهم", + "دهم", + "یازدهم", + "دوازدهم", + ]; + const optionNum = ["", "الف", "ب", "پ", "ت", "ث", "ج", "چ", "ح"]; + + const [selectedCourse, setSelectedCourse] = useState( + addExamState?.questionnaires[0] + ); + + const [numPages, setNumPages] = useState(1); + + function onDocumentLoadSuccess({ numPages }) { + setNumPages(numPages); + } + + let questionCount = 0; + for(let i=0;i>>>>>>>>>>>>>>>>>>>>>>>>>>"); + console.log(addExamState.startDate); + const submitHandler=()=>{ + parentAdd({ + name: addExamState.name, + description: addExamState.description, + startDate: addExamState.startDate, + endDate: addExamState.endDate, + duration: addExamState?.duration || 60, + // duration:30, + type: addExamState.type, + //questionCount: addExamState.questions.length, + questionCount, + examGroupId: addExamState.groupId, + levelCriterion: null, + budgetFileId:null + }); + // stepClick(); + } + + return ( +
+
+

آزمون {addExamState.name}

+

پایه {grades[addExamState.grade]}

+
+ {addExamState.type !== "pdf" ? ( +
+ {addExamState.courses.map((item, index) => ( +
+

سوالات {item.title}

+

ضریب {item.coefficient}

+ {item.selectedQuestions.map((question, idx) => ( +
+ {console.log(item.selectedQuestions.length)} + {console.log(idx + 1)} +
+

{question.title}

+

{question.score} نمره

+
+ {question.options.map((option) => ( +
+
+ {optionNum[option.id]} +
+
+ {option.title} +
+ ))}
- - } -
- - - - + ))}
+ ))}
+ ) : ( + addExamState.type === "pdf" && ( +
+

+ دفترچه ها +

+
+ {addExamState?.questionnaires?.map((item) => ( +
setSelectedCourse(item)} + > +

{item.name}

+
+ ))} +
- - ) -} +
+
+ + + +
+
+
+ +
+
+
+
+ ) + )} +
+ + +
+
+ ); +}; const mapStateToProps = (state) => ({ grades: state.publicApi.grades, addExamState: state.addExamReduser }) -export default connect(mapStateToProps)(ViewExam); \ No newline at end of file +const mapDispatchToProps = { + parentAdd: exam.parentAdd, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(ViewExam); \ No newline at end of file diff --git a/src/view/services/service/index.js b/src/view/services/service/index.js index 2c73f24..48a688d 100644 --- a/src/view/services/service/index.js +++ b/src/view/services/service/index.js @@ -1,7 +1,9 @@ import moment from "jalali-moment"; import React from "react"; +import { connect } from "react-redux"; import Button from "../../../components/Button"; import Checkbox from "../../../components/Checkbox"; +import { userProduct } from "../../../redux/actions"; import separate from "../../../utils/separate"; const servicePopUp = ({ content, @@ -10,6 +12,8 @@ const servicePopUp = ({ sendPrice, setShowBudget, setBudgetFileId, + userInfo, + pushToCart }) => { console.log(")))))(((((((((("); console.log(content); @@ -18,6 +22,29 @@ const servicePopUp = ({ setBudgetFileId(fileId); setShowBudget(true); }; + + //addToCartHandler------ + let rulesAccepted = userInfo.rulesAccepted; + const addToCartHandler = () => { + let checkBoxes = document.querySelectorAll(".exam-child-checbox"); + let childList = []; + let parentLength = content?.product?.childs?.length; + console.log("buying....................."); + for (let i = 0; i < checkBoxes.length; i++) { + if (checkBoxes[i].checked) { + childList.push(content?.product?.childs[i].id); + } + } + console.log(childList); + console.log(parentLength); + if (parentLength === childList.length) { + pushToCart({ productId :content.product.id,count:1}); + } else { + for(let j=0;j )} {content.id === 2 && ( -
-

- {content.title} -

-
-
- نوع آزمون :{" "} - {content?.product?.exam?.productType === 2 - ? "حضوری" - : "مجازی"} -
-
- تاریخ شروع :{" "} - {moment(content?.product?.exam?.startDate, "YYYY/MM/DD") - .locale("fa") - .format("YYYY/MM/DD")} -
-
- تعداد آزمون : ۱۸ -
-
- budgetHandler(content?.product?.exam?.budgetFileId) - } - > - {" "} - بودجه بندی آزمون{" "} -
-
-
- توجه: - به صورت معمول تمامی آزمون ها برای شما خریداری خواهند شد مگر - اینکه شما به صورت دلخواه یک یا چند آزمون را انتخاب نمایید -
- {content?.product?.exam?.childs?.map((item, index) => ( +
+
+

+ {content.title} +

-
- - // e.target.checked - // ? sendPrice(item.price) - // : sendPrice(-item.price) - // } - /> -

{item?.name}

+
+ نوع آزمون :{" "} + {content?.product?.exam?.productType === 2 + ? "حضوری" + : "مجازی"}
-

- تاریخ :{" "} - {moment(item?.startDate, "YYYY/MM/DD") +

+ تاریخ شروع :{" "} + {moment(content?.product?.exam?.startDate, "YYYY/MM/DD") .locale("fa") .format("YYYY/MM/DD")} -

- {/*

ساعت : {item.time}

*/} -

+

+ تعداد آزمون : ۱۸ +
+
- budgetHandler(item?.budgetFileId) + budgetHandler(content?.product?.exam?.budgetFileId) } > - بودجه بندی ! -

-

تعداد سوالات: {item?.questionCount}

-

{separate(item?.price)} تومان

+ {" "} + بودجه بندی آزمون{" "} +
- ))} +
+ توجه: + به صورت معمول تمامی آزمون ها برای شما خریداری خواهند شد مگر + اینکه شما به صورت دلخواه یک یا چند آزمون را انتخاب نمایید +
+ {content?.product?.childs?.map((item, index) => ( +
+
+ {/* + // e.target.checked + // ? sendPrice(item.price) + // : sendPrice(-item.price) + // } + /> */} + +

{item?.name}

+
+

+ تاریخ :{" "} + {moment(item?.exam?.startDate, "YYYY/MM/DD") + .locale("fa") + .format("YYYY/MM/DD")} +

+ {/*

ساعت : {item.time}

*/} +

budgetHandler(item?.exam?.budgetFileId)} + > + بودجه بندی ! +

+

تعداد سوالات: {item?.exam?.questionCount}

+

{separate(item?.price)} تومان

+
+ ))} +
+ {rulesAccepted &&
+
+ افزودن به سبد خرید +
+
}
)} @@ -272,4 +313,12 @@ const servicePopUp = ({ ); }; -export default servicePopUp; +const mapStateToProps = (state) => ({ + userInfo: state.user.status, +}); + +const mapDispatchToProps = { + pushToCart: userProduct.add, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(servicePopUp);