|
@@ -0,0 +1,145 @@
|
|
|
+import React from 'react';
|
|
|
+import { Field, reduxForm } from 'redux-form';
|
|
|
+import formInput from '../../common/formInput';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class CreateTopic extends React.Component {
|
|
|
+
|
|
|
+ state ={
|
|
|
+ click:false,
|
|
|
+ klick:["1"],
|
|
|
+ array:[],
|
|
|
+ simple:false
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ submit=({name, description })=>{
|
|
|
+ const {actions:{createTopicsRequest}, token, categoryId} = this.props;
|
|
|
+ createTopicsRequest({
|
|
|
+ name,
|
|
|
+ description,
|
|
|
+ categoryId,
|
|
|
+ token
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ qestionAnswerSubmit = ({questions, correct }) =>{
|
|
|
+ const {simple, array} = this.state
|
|
|
+console.log(this.state)
|
|
|
+ const {topic:{data:{topic:{_id}}}, actions:{createTestRequest}, token} =this.props;
|
|
|
+ console.log("topicId",_id,questions, correct)
|
|
|
+ createTestRequest({
|
|
|
+ questions,
|
|
|
+ simple,
|
|
|
+ _id,
|
|
|
+ array,
|
|
|
+ token
|
|
|
+
|
|
|
+ })
|
|
|
+ this.setState({array: []})
|
|
|
+ const {ansversInput} =this.refs
|
|
|
+ // ansversInput.value = " "
|
|
|
+
|
|
|
+ console.log(this.state, ansversInput.value)
|
|
|
+
|
|
|
+ }
|
|
|
+ handelClick =()=>{
|
|
|
+ this.setState((prevState) => ({klick:prevState.klick.push("1")}))
|
|
|
+ }
|
|
|
+ handelChange=(event)=>{
|
|
|
+ const target = event.target;
|
|
|
+ const value = target.type === 'checkbox' ? target.checked : target.value;
|
|
|
+ const name = target.name;
|
|
|
+
|
|
|
+ this.setState({
|
|
|
+ [name]: value
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ onClick =() =>{
|
|
|
+ this.setState((prevState) => ({ click: !prevState.click }));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ formSubmitinput =({answer, price,correct})=>{
|
|
|
+ console.log(answer, correct, price);
|
|
|
+ const values ={
|
|
|
+ answer:answer,
|
|
|
+ price:+price,
|
|
|
+ correct:correct
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setState((prevState) =>({array:prevState.array.push(values), klick:prevState.klick.push("1")},console.log(prevState.array) ))
|
|
|
+ console.log(this.state)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { handleSubmit} =this.props;
|
|
|
+ const {simple, price, correct, click, array, klick} =this.state;
|
|
|
+ const {handelChange, submit, onClick, handelClick, formSubmitinput,qestionAnswerSubmit} = this;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <form>
|
|
|
+ <h4 className ="text-white font-ci"> Enter topic </h4>
|
|
|
+ <Field className ="bg-mist bg-mist-op text-white mt-3 mb-3 border rounded w-100 " name="name" type="name" placeholder="Create Name Topic" component={formInput} />
|
|
|
+ <h4 className ="text-white font-ci"> Enter description </h4>
|
|
|
+ <Field className ="bg-mist bg-mist-op text-white mt-3 mb-3 border rounded w-100 " name ="description" type = "textarea" placeholder = "Create Descriptions" component = {formInput} />
|
|
|
+ {
|
|
|
+ !click
|
|
|
+ ?
|
|
|
+ <button onClick = {()=>{
|
|
|
+ onClick()
|
|
|
+ handleSubmit(submit)()
|
|
|
+ }}> Create questions</button>
|
|
|
+ :
|
|
|
+ <div>
|
|
|
+ <h4 className ="text-white font-ci"> Enter question and set the difficulty level</h4>
|
|
|
+ <div className ="d-flex w-100 ">
|
|
|
+ <Field className="bg-mist bg-mist-op text-white mt-3 mb-3 border rounded w-100 " name ="questions" type = "questions" placeholder = "Create Qestions" component = {formInput} />
|
|
|
+ <Field className="bg-mist bg-mist-op text-white mt-4 pb-1 border rounded w-25 flex-row align-items-end check" name ="simple" type = "checkbox" checked ={simple} onChange ={handelChange} component = {formInput} />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <Field className = "bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="answer" type = "name" placeholder ="Add anwer" ref ='ansversInput' component = {formInput} />
|
|
|
+ <Field className = "bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="price" type = "number" value ={price} component = {formInput} />
|
|
|
+ <Field className ="bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="correct" type = "checkbox" checked ={correct} component = {formInput} />
|
|
|
+ </div>)
|
|
|
+ {
|
|
|
+ array.map(el=>
|
|
|
+ <div>
|
|
|
+ <Field className = "bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="answer" type = "name" placeholder ="Add anwer" ref ='ansversInput' component = {formInput} />
|
|
|
+ <Field className = "bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="price" type = "number" value ={price} component = {formInput} />
|
|
|
+ <Field className ="bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="correct" type = "checkbox" checked ={correct} component = {formInput} />
|
|
|
+ </div>)
|
|
|
+ }
|
|
|
+
|
|
|
+ <button onClick={
|
|
|
+ handleSubmit(formSubmitinput)}></button>
|
|
|
+ <button className="form__submit-button form__submit-button--reset" onClick = {()=>
|
|
|
+ {
|
|
|
+ handleSubmit(qestionAnswerSubmit)()}}></button>
|
|
|
+
|
|
|
+
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+export default reduxForm({
|
|
|
+ form: "createTopicForm"
|
|
|
+})(CreateTopic);
|