|
@@ -1,7 +1,6 @@
|
|
|
import React, { Component } from "react";
|
|
|
import { Modal } from "react-bootstrap";
|
|
|
-import { Header } from "react-bootstrap/ModalHeader";
|
|
|
-import { Button } from "react-bootstrap"
|
|
|
+
|
|
|
import { Field, reduxForm } from 'redux-form';
|
|
|
import formInput from '../../common/formInput'
|
|
|
|
|
@@ -13,28 +12,29 @@ class EditModal extends React.Component {
|
|
|
clicks: false,
|
|
|
questionId: null
|
|
|
}
|
|
|
+
|
|
|
submit = (payload) => {
|
|
|
const { name, categoryId, description, question, simple, topicId } = payload
|
|
|
const { answers, questionId } = this.state
|
|
|
- console.log(name, categoryId, description, question, simple, topicId, answers)
|
|
|
const { actions: { changeTestRequest } } = this.props;
|
|
|
changeTestRequest({ questionId, name, categoryId, description, question, simple, topicId, answers })
|
|
|
|
|
|
- // console.log(payload)
|
|
|
}
|
|
|
+
|
|
|
changeQuestion = (event) => {
|
|
|
const { value } = event.target
|
|
|
const { actions: { getAnswersRequest } } = this.props;
|
|
|
- console.log(event.target.valus, value)
|
|
|
getAnswersRequest({ value })
|
|
|
this.setState((prevState) => ({ clicked: !prevState.clicked, }))
|
|
|
this.setState({ questionId: value })
|
|
|
|
|
|
}
|
|
|
+
|
|
|
answersChange = (event) => {
|
|
|
const { value } = event.target
|
|
|
this.setState({ clicks: true, answers_id: value })
|
|
|
}
|
|
|
+
|
|
|
changeAnswers = (payload) => {
|
|
|
const { answers_id } = this.state
|
|
|
const { answer, price, correct } = payload
|
|
@@ -48,28 +48,31 @@ class EditModal extends React.Component {
|
|
|
this.setState({ clicks: false })
|
|
|
|
|
|
}
|
|
|
+
|
|
|
deleteAnswer = () => {
|
|
|
const { answers_id } = this.state
|
|
|
const { actions: { deleteAnswerRequest } } = this.props;
|
|
|
deleteAnswerRequest({ answers_id })
|
|
|
|
|
|
}
|
|
|
+
|
|
|
deleteQuestions = () => {
|
|
|
- const{questionId} =this.state
|
|
|
+ const { questionId } = this.state
|
|
|
const { actions: { deleteQuestionRequest } } = this.props;
|
|
|
- deleteQuestionRequest({questionId})
|
|
|
+ deleteQuestionRequest({ questionId })
|
|
|
}
|
|
|
- deleteTopic=(payload)=>{
|
|
|
- const{topicId}=payload
|
|
|
- const{actions:{deleteTopicRequest}} =this.props;
|
|
|
- deleteTopicRequest({topicId})
|
|
|
+
|
|
|
+ deleteTopic = (payload) => {
|
|
|
+ const { topicId } = payload
|
|
|
+ const { actions: { deleteTopicRequest } } = this.props;
|
|
|
+ deleteTopicRequest({ topicId })
|
|
|
|
|
|
}
|
|
|
+
|
|
|
render() {
|
|
|
const { visible, handleClose: { closeModal }, inputData, editLoads, initialValues, arrayQuestions: { questions, _id }, answers, handlers: { handelClick }, click, handleSubmit } = this.props;
|
|
|
const { submit, answersChange, changeAnswers, deleteAnswer, deleteQuestions, deleteTopic } = this
|
|
|
const { clicked, clicks } = this.state
|
|
|
- console.log(this.state)
|
|
|
return (
|
|
|
<Modal show={visible} onHide={closeModal} aria-labelledby="contained-modal-title-vcenter" >
|
|
|
< Modal.Header closeButton >
|
|
@@ -102,7 +105,7 @@ class EditModal extends React.Component {
|
|
|
<h4 class="text-center text-white font-ci font-ci-bold">Questions and Simple</h4>
|
|
|
<Field name="question" type="question" component={formInput} />
|
|
|
<Field name="simple" type="checkbox" component={formInput} />
|
|
|
- <button className="btn btn-outline-light bg-stone m-3" onClick={handleSubmit(deleteQuestions)} >Change Question</button >
|
|
|
+ <button className="btn btn-outline-light bg-stone m-3" onClick={handleSubmit(deleteQuestions)} >Delete Question</button >
|
|
|
</React.Fragment>
|
|
|
: null
|
|
|
}
|
|
@@ -138,40 +141,14 @@ class EditModal extends React.Component {
|
|
|
</React.Fragment>
|
|
|
: null
|
|
|
}
|
|
|
- {/* {
|
|
|
- answers !== null
|
|
|
- ?
|
|
|
- answers.map(el =>
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- <React.Fragment>
|
|
|
- <li class="list-group-item" key={el._id} id={el._id}>{el.answer}</li>
|
|
|
- <button type="button" onClick={handelClick.bind(null, { el })}>Change</button>
|
|
|
- <button type="button">Delete</button>
|
|
|
- </React.Fragment>
|
|
|
- :
|
|
|
- <React.Fragment>
|
|
|
- <Field name="answer" type="answer" component={formInput} className="form-control mb-3" />
|
|
|
- <Field name="corrent" type="checkbox" component={formInput} />
|
|
|
- <Field name="price" type="price" component={formInput} />
|
|
|
- <button onClick={handelClick.bind(null, { el })}>Change</button>
|
|
|
- <button>Delete</button>
|
|
|
- </React.Fragment>
|
|
|
- )
|
|
|
- :
|
|
|
- null
|
|
|
- } */}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
</ul>
|
|
|
</form>
|
|
|
</ Modal.Body >
|
|
|
< Modal.Footer>
|
|
|
- <React.Fragment>
|
|
|
- <button className="btn btn-outline-light bg-stone m-3" onClick={handleSubmit(deleteTopic)}>Delete Answer</button>
|
|
|
- <button type="submit" >Change</button>
|
|
|
+ <React.Fragment>
|
|
|
+ <button className="btn btn-outline-light bg-stone m-3" onClick={handleSubmit(deleteTopic)}>Delete Answer</button>
|
|
|
+ <button type="submit" className="btn btn-outline-light bg-stone m-3" onClick={handleSubmit(submit)} >Change</button>
|
|
|
</React.Fragment>
|
|
|
</ Modal.Footer >
|
|
|
</Modal>
|