Browse Source

create test

sveta 5 years ago
parent
commit
37604e9378

+ 9 - 9
package-lock.json

@@ -2836,7 +2836,7 @@
     },
     "camelcase-keys": {
       "version": "2.1.0",
-      "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
+      "resolved": "http://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz",
       "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=",
       "requires": {
         "camelcase": "^2.0.0",
@@ -6397,7 +6397,7 @@
         },
         "string-width": {
           "version": "1.0.2",
-          "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
+          "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
           "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
           "requires": {
             "code-point-at": "^1.0.0",
@@ -9030,7 +9030,7 @@
     },
     "meow": {
       "version": "3.7.0",
-      "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
+      "resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz",
       "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=",
       "requires": {
         "camelcase-keys": "^2.0.0",
@@ -9375,7 +9375,7 @@
       "dependencies": {
         "semver": {
           "version": "5.3.0",
-          "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
+          "resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
           "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8="
         }
       }
@@ -9479,7 +9479,7 @@
         },
         "chalk": {
           "version": "1.1.3",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "requires": {
             "ansi-styles": "^2.2.1",
@@ -15251,7 +15251,7 @@
         },
         "os-locale": {
           "version": "1.4.0",
-          "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
+          "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
           "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
           "requires": {
             "lcid": "^1.0.0"
@@ -15259,7 +15259,7 @@
         },
         "string-width": {
           "version": "1.0.2",
-          "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
+          "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
           "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
           "requires": {
             "code-point-at": "^1.0.0",
@@ -15414,7 +15414,7 @@
       "dependencies": {
         "source-map": {
           "version": "0.4.4",
-          "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
+          "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
           "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=",
           "requires": {
             "amdefine": ">=0.0.4"
@@ -16279,7 +16279,7 @@
     },
     "tar": {
       "version": "2.2.1",
-      "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
+      "resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
       "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=",
       "requires": {
         "block-stream": "*",

+ 1 - 1
src/actions/admin/changeCategory.js

@@ -1,4 +1,4 @@
-import * as actionTypes from './../../constants/admin';
+import * as actionTypes from '../../../constants/admin';
 
 export const changeCategoryRequest = payload => ({
     type: actionTypes.CHANGE_CATEGORY_REQUEST,

+ 1 - 1
src/actions/admin/createCategory.js

@@ -1,4 +1,4 @@
-import * as actionTypes from './../../constants/admin';
+import * as actionTypes from '../../../constants/admin';
 
 export const createCategoryRequest = payload => ({
     type: actionTypes.CREATE_CATEGORY_REQUEST,

+ 1 - 1
src/actions/admin/deleteCategory.js

@@ -1,4 +1,4 @@
-import * as actionTypes from './../../constants/admin';
+import * as actionTypes from '../../../constants/admin';
 
 export const deleteCategoryRequest = payload => ({
     type: actionTypes.DELETE_CATEGORY_REQUEST,

+ 1 - 1
src/actions/admin/getCategory.js

@@ -1,4 +1,4 @@
-import * as actionTypes from './../../constants/admin';
+import * as actionTypes from '../../../constants/admin';
 
 export const getCategoryRequest = payload => ({
     type: actionTypes.GET_CATEGORY_REQUEST,

+ 21 - 0
src/actions/admin/test/createTest.js

@@ -0,0 +1,21 @@
+import * as actionTypes from '../../../constants/admin';
+
+export const createTestRequest = payload => {
+    console.log(payload)
+    return{
+    type: actionTypes.CREATE_TEST_REQUEST,
+    payload
+};
+}
+export const createQuestionSuccess = payload => ({
+    type: actionTypes.CREATE_QUESTIONS_REQUEST_SUCCESS,
+    payload
+});
+export const createAnswersSuccess = payload => ({
+    type: actionTypes.CREATE_ANSVERS_REQUEST_SUCCESS,
+    payload
+});
+export const createTestFailure = error => ({
+    type: actionTypes.CREATE_TEST_REQUEST_FAILURE,
+    error
+});

+ 25 - 0
src/actions/admin/test/createTopics.js

@@ -0,0 +1,25 @@
+import * as actionTypes from '../../../constants/admin';
+
+export const createTopicsRequest = payload => {
+    console.log(payload)
+    return{
+    type: actionTypes.CREATE_TOPICS_REQUEST,
+    payload
+};
+}
+export const createTopicsSuccess = payload => ({
+    type: actionTypes.CREATE_TOPICS_REQUEST_SUCCESS,
+    payload
+});
+export const createQuestionSuccess = payload => ({
+    type: actionTypes.CREATE_QUESTIONS_REQUEST_SUCCESS,
+    payload
+});
+export const createAnswersSuccess = payload => ({
+    type: actionTypes.CREATE_ANSVERS_REQUEST_SUCCESS,
+    payload
+});
+export const createTopicsFailure = error => ({
+    type: actionTypes.CREATE_TOPICS_REQUEST_FAILURE,
+    error
+});

+ 105 - 0
src/components/admin/CreateTest/CreateQestions.js

@@ -0,0 +1,105 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
+import { Field, reduxForm } from 'redux-form';
+import formInput from '../../common/formInput';
+
+
+
+class CreateQuestions extends React.Component {
+
+    state ={
+        click:false,
+        klick:true,
+        array:[],
+        simple:false,
+        
+    }
+
+    submit=({name, description, questions })=>{
+        const {simple, array} = this.state;
+        console.log(this.state)
+        const {actions:{createTopicsRequest}, token, categoryId} = this.props;
+        console.log("name", name, "description", description, "question", questions, "categoryId", categoryId   )
+        console.log(this.props)
+        createTopicsRequest({
+            name,
+            description, 
+            questions,
+            array,
+            simple,
+            categoryId,
+            token
+
+        })
+    }
+    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})=>{    
+
+        const {ansversInput:{value},correctAnsversInput,checkAnsversInput} =this.refs
+        console.log(value,checkAnsversInput.value,correctAnsversInput.value);
+        const values ={
+            answer:answer,
+                       price:+correctAnsversInput.value,
+                       correct:checkAnsversInput.value
+        }
+        
+        this.setState((prevState) =>({array:prevState.array.push(values)},console.log(prevState.array) ))
+        console.log(this.state, answer.target)
+        
+    }
+    answersClick =()=>{
+        this.setState((prevState) => ({ click: !prevState.click }));
+    }
+    
+    
+
+    render() {
+        const {  handleSubmit} =this.props;
+        const {simple, price, correct, click,arrey} =this.state;
+        const {handelChange, submit, onClick, handelClick, formSubmitinput, answersClick} = this;
+
+
+       
+        return (
+            <div>
+            <form onSubmit = {handleSubmit(submit)}>
+                <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 ="correct" type = "checkbox" checked ={correct} 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} ref ='correctAnsversInput'  component = {formInput} />
+                <Field className ="bg-mist bg-mist-op text-white mt-3 mb-3 border rounded" name ="simple" type = "checkbox" checked ={simple}  ref ='checkAnsversInput'  component = {formInput} />
+                </div>
+    
+            </form >
+            </div>
+            
+            
+        )
+    }
+
+}
+
+
+
+export default reduxForm({
+    form: "createQuestionsForm",
+})(CreateQuestions);

+ 145 - 0
src/components/admin/CreateTest/CreateTopic.js

@@ -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);

+ 73 - 0
src/components/admin/CreateTest/index.js

@@ -0,0 +1,73 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
+import {getCategoryRequest} from '../../../actions/admin/category/getCategory';
+import CreateTopic from './CreateTopic';
+import {createTopicsRequest} from '../../../actions/admin/test/createTopics';
+import {createTestRequest} from '../../../actions/admin/test/createTest';
+
+
+
+
+class CreateTest extends React.Component {
+    state = {
+        categoryId:null
+    }
+
+    componentDidMount() {
+        const {getCategoryRequest, signIn:{token}} = this.props;
+        console.log("token", token)
+        getCategoryRequest(
+            token
+            )
+            
+        }
+
+        onClick =(event)=>{
+            this.setState({ categoryId: event.target.value })
+        }
+
+
+    
+
+    render() {
+        const {category:{data}, signIn:{token}, createTopicsRequest,createTestRequest, topicId:{topic}} = this.props;
+        const {categoryId} = this.state
+        const {onClick} = this;
+       
+
+        console.log(this.state)
+       
+        return (
+            <div className=" profile-page p-4 d-flex flex-row font-ci">
+                <div className ='w-50 p-3 bg-gradient border rounded'  > 
+                    <h3 className ="text-white font-ci">Нou are taking category for creating tests</h3>
+            <select class="custom-select bg-mist bg-mist-op text-white mt-3 mb-3" onChange ={onClick} value ={categoryId}>
+                    <option selected>Open this Category menu</option>
+                    {
+                        data&&data.map(mass => <option key = {mass._id} value ={mass._id}>{mass.name}</option>)
+                        
+                    }
+                </select>
+                <CreateTopic categoryId ={categoryId} topic ={topic} actions ={{createTopicsRequest,createTestRequest}} token ={token}></CreateTopic>
+            </div>
+            <div>
+                ffff
+            </div>
+            </div>
+            
+        )
+    }
+
+}
+
+const
+    mapStateToProps = state => ({
+        signIn: state.signIn,
+        category:state.category,
+        topicId:state.topicId
+        });
+
+const mapDispatchToProps = dispatch => bindActionCreators({getCategoryRequest, createTopicsRequest, createTestRequest}, dispatch);
+
+export default connect(mapStateToProps, mapDispatchToProps)(CreateTest);

+ 0 - 1
src/components/admin/addDeleteCategory/ChangeCategory.js

@@ -3,7 +3,6 @@ import { connect } from 'react-redux';
 import { bindActionCreators } from 'redux';
 import { Field, reduxForm } from 'redux-form';
 import formInput from '../../common/formInput'
-import {changeCategoryRequest} from '../../../actions/admin/changeCategory'
 
 
 

+ 1 - 1
src/components/admin/addDeleteCategory/DeleteCategory.js

@@ -1,7 +1,7 @@
 import React from 'react';
 import { connect } from 'react-redux';
 import { bindActionCreators } from 'redux'
-import {deleteCategoryRequest} from  '../../../actions/admin/deleteCategory';
+import {deleteCategoryRequest} from  '../../../actions/admin/category/deleteCategory';
 
 
 

+ 3 - 3
src/components/admin/addDeleteCategory/index.js

@@ -1,9 +1,9 @@
 import React from 'react';
 import { connect } from 'react-redux';
 import { bindActionCreators } from 'redux'
-import {createCategoryRequest} from  '../../../actions/admin/createCategory';
-import {changeCategoryRequest} from  '../../../actions/admin/changeCategory';
-import {getCategoryRequest} from '../../../actions/admin/getCategory';
+import {createCategoryRequest} from  '../../../actions/admin/category/createCategory';
+import {changeCategoryRequest} from  '../../../actions/admin/category/changeCategory';
+import {getCategoryRequest} from '../../../actions/admin/category/getCategory';
 import GetCategory from './GetCategory'
 
 

+ 4 - 2
src/components/public/Header.js

@@ -31,8 +31,10 @@ export default class Header extends React.Component {
                                 Menu Admina
                                     </a>
                             <div class="dropdown-menu" aria-labelledby="navbarDropdown">
-                                <Link onClick={this.handleClick} class="nav-link font-ci font-ci-bold " to={routes.DELETE_USER}>Delete</Link>
-                                <Link onClick={this.handleClick} class="nav-link font-ci font-ci-bold " to={routes.CREATE_CATEGORY}><a class="dropdown-item">fffffff</a></Link>
+                                <Link onClick={this.handleClick} class="nav-link font-ci font-ci-bold " to={routes.DELETE_USER}>Delete User</Link>
+                                <Link onClick={this.handleClick} class="nav-link font-ci font-ci-bold " to={routes.CREATE_CATEGORY}><a class="dropdown-item">Create Category</a></Link>
+                                <Link onClick={this.handleClick} class="nav-link font-ci font-ci-bold " to={routes.CREATE_TEST}><a class="dropdown-item">Create Test</a></Link>
+
                                 <a class="dropdown-item" href="#">Action</a>
                                 <a class="dropdown-item" href="#">Another action</a>
                                 <div class="dropdown-divider"></div>

+ 9 - 2
src/configs/routerConfig.js

@@ -3,7 +3,9 @@ import * as routes from './../constants/routes';
 
 const ProfilePage = lazy(() => import('../components/user/ProfilePage'));
 const DeleteUser = lazy(()=>import('../components/admin/deleteUser/index'));
-const AddDeleteCategory = lazy(()=> import('../components/admin/addDeleteCategory'))
+const AddDeleteCategory = lazy(()=> import('../components/admin/addDeleteCategory'));
+const CreateTest = lazy(()=> import('../components/admin/CreateTest'));
+
 // import SignIn from '../components/public/SignIn';
 const SignIn = lazy(() => import('./../components/public/SignIn'));
 const SignUp = lazy(() => import('./../components/public/SignUp'));
@@ -51,9 +53,14 @@ export default [
     },
     {
         path: routes.CREATE_CATEGORY,
-        access: 'public',
+        access: 'admin-only',
         component: AddDeleteCategory
     },
+    {
+        path: routes.CREATE_TEST,
+        access: 'admin-only',
+        component: CreateTest
+    },
     {
         access: 'public',
         component: () => <div>404</div>

+ 15 - 0
src/constants/admin.js

@@ -15,3 +15,18 @@ export const CHANGE_CATEGORY_REQUEST_FAILURE = 'CHANGE_CATEGORY_REQUEST_FAILURE'
 export const DELETE_CATEGORY_REQUEST = 'DELETE_CATEGORY_REQUEST';
 export const DELETE_CATEGORY_REQUEST_SUCCESS = 'DELETE_CATEGORY_REQUEST_SUCCESS';
 export const DELETE_CATEGORY_REQUEST_FAILURE = 'DELETE_CATEGORY_REQUEST_FAILURE';
+
+export const CREATE_TOPICS = "https://test-app-a-level.herokuapp.com/topics";
+export const CREATE_TOPICS_REQUEST = 'CREATE_TOPICS_REQUEST';
+export const CREATE_TOPICS_REQUEST_SUCCESS = 'CREATE_TOPICS_REQUEST_SUCCESS';
+export const CREATE_TOPICS_REQUEST_FAILURE = 'CREATE_TOPICS_REQUEST_FAILURE';
+
+export const CREATE_QUESTIONS = "https://test-app-a-level.herokuapp.com/questions"; 
+export const CREATE_ANSVERS = "https://test-app-a-level.herokuapp.com/answers";
+export const CREATE_TEST_REQUEST = 'CREATE_TEST_REQUEST';
+export const CREATE_QUESTIONS_REQUEST_SUCCESS = 'CREATE_QUESTIONS_REQUEST_SUCCESS';
+export const CREATE_ANSVERS_REQUEST_SUCCESS = 'CREATE_ANSVERS_REQUEST_SUCCESS';
+export const CREATE_TEST_REQUEST_FAILURE = 'CREATE_TEST_REQUEST_FAILURE';
+
+
+

+ 35 - 0
src/reducers/admin/test/createTopics.js

@@ -0,0 +1,35 @@
+import * as actionTypes from '../../../constants/admin';
+import initialState from '../../initialState';
+
+export default function topic(state = initialState.topicId, {payload, type, error}) {
+
+    switch (type) { // payload.type -> type
+        case actionTypes.CREATE_TOPICS_REQUEST: {
+            return {
+                ...state,
+                isFetching: true,
+                payload
+            }
+        }
+        case actionTypes.CREATE_TOPICS_REQUEST_SUCCESS: {
+            const { data } = payload;
+
+            return {
+                ...state,
+                isFetching: false,
+                topic:payload
+            }
+        }
+        case actionTypes.DELETE_CATEGORY_REQUEST_FAILURE: {
+
+            return {
+                ...state,
+                isFetching: false,
+                error
+            }
+        }
+        default: {
+            return state;
+        }
+    }
+}

+ 3 - 1
src/reducers/index.js

@@ -6,6 +6,7 @@ import signUp from './auth/signUp';
 
 import category from './admin/getCategory';
 import newCategory from './admin/changeCategory';
+import topicId from './admin/test/createTopics';
 
 import chageLoginReducer from './user/chageLogin';
 import changeEmailReducer from './user/changeEmail';
@@ -18,5 +19,6 @@ export default combineReducers({
     changeEmailReducer,
     form,
     category,
-    newCategory
+    newCategory,
+    topicId
 })

+ 6 - 1
src/reducers/initialState.js

@@ -29,6 +29,11 @@ newCategory:{
     name:null,
     isFetching:false,
     error:null
-}
+},
+ topicId:{
+    topicId:null,
+    isFetching:false,
+    error:null
+ }
 
 }

+ 4 - 5
src/sagas/admin/changeCategory.js

@@ -1,8 +1,8 @@
 import { put, call } from 'redux-saga/effects';
 import axios from 'axios';
 
-import { CREATE_CATEGORY } from './../../constants/admin';
-import { changeCategorySuccess, changeCategoryFailure } from './../../actions/admin/changeCategory'
+import { CREATE_CATEGORY } from '../../../constants/admin';
+import { changeCategorySuccess, changeCategoryFailure } from '../../../actions/admin/category/changeCategory'
 
 export default function* ({payload:{id,name ,token}}) {
     console.log('User inside the worker-saga', name, "token", token, 'id', id );
@@ -14,14 +14,13 @@ export default function* ({payload:{id,name ,token}}) {
             }
         }
 
-        const user = yield call(() =>
+        const category = yield call(() =>
             axios.put(`${CREATE_CATEGORY}${'/'}${id}`,{
                 id,
                 name}, config)
-                .then(({ data }) => data)
         )
 
-        yield put(changeCategorySuccess(user));
+        yield put(changeCategorySuccess(category));
     }
     catch ({ message }) {
         yield put(changeCategoryFailure(message));

+ 4 - 5
src/sagas/admin/createCategory.js

@@ -1,8 +1,8 @@
 import { put, call } from 'redux-saga/effects';
 import axios from 'axios';
 
-import { CREATE_CATEGORY } from './../../constants/admin';
-import { createCategorySuccess, createCategoryFailure } from './../../actions/admin/createCategory'
+import { CREATE_CATEGORY } from '../../../constants/admin';
+import { createCategorySuccess, createCategoryFailure } from '../../../actions/admin/category/createCategory'
 
 export default function* ({payload:{name,token}}) {
     console.log('User inside the worker-saga', name, token);
@@ -14,13 +14,12 @@ export default function* ({payload:{name,token}}) {
             }
         }
 
-        const user = yield call(() =>
+        const category = yield call(() =>
             axios.post(CREATE_CATEGORY,{
                 name}, config)
-                .then(({ data }) => data)
         )
 
-        yield put(createCategorySuccess(user));
+        yield put(createCategorySuccess(category));
     }
     catch ({ message }) {
         yield put(createCategoryFailure(message));

+ 5 - 5
src/sagas/admin/deleteCategory.js

@@ -1,8 +1,8 @@
 import { put, call } from 'redux-saga/effects';
 import axios from 'axios';
 
-import { CREATE_CATEGORY } from './../../constants/admin';
-import { deleteCategorySuccess, deleteCategoryFailure } from './../../actions/admin/deleteCategory';
+import { CREATE_CATEGORY } from '../../../constants/admin';
+import { deleteCategorySuccess, deleteCategoryFailure } from '../../../actions/admin/category/deleteCategory';
 
 export default function* ({payload:{id,token}}) {
     console.log('User inside the worker-saga', "token", token, 'id', id );
@@ -13,12 +13,12 @@ export default function* ({payload:{id,token}}) {
             }
         }
 
-        const user = yield call(() =>
+        const category = yield call(() =>
             axios.delete(`${CREATE_CATEGORY}${'/'}${id}`, config)
-                .then(({ data }) => data)
+                
         )
 
-        yield put(deleteCategorySuccess(user));
+        yield put(deleteCategorySuccess(category));
     }
     catch ({ message }) {
         yield put(deleteCategoryFailure(message));

+ 5 - 5
src/sagas/admin/getCategory.js

@@ -1,8 +1,8 @@
 import { put, call } from 'redux-saga/effects';
 import axios from 'axios';
 
-import { CREATE_CATEGORY } from './../../constants/admin';
-import { getCategorySuccess, getCategoryFailure } from './../../actions/admin/getCategory'
+import { CREATE_CATEGORY } from '../../../constants/admin';
+import { getCategorySuccess, getCategoryFailure } from '../../../actions/admin/category/getCategory'
 
 export default function* ({payload}) {
     console.log('User inside the worker-saga', payload);
@@ -14,12 +14,12 @@ export default function* ({payload}) {
             }
         }
 
-        const user = yield call(() =>
+        const category = yield call(() =>
             axios.get(CREATE_CATEGORY, config)
-                .then(({ data }) => data)
+            .then(({ data }) => data)
         )
 
-        yield put(getCategorySuccess(user));
+        yield put(getCategorySuccess(category));
     }
     catch ({ message }) {
         yield put(getCategoryFailure(message));

+ 1 - 1
src/sagas/admin/index.js

@@ -1,6 +1,6 @@
 import createCategory from './createCategory';
 import getCategory from './getCategory';
-import * as actionTypes from './../../constants/admin';
+import * as actionTypes from '../../../constants/admin';
 
 import { takeEvery } from 'redux-saga/effects';
 import changeCategory from './changeCategory';

+ 59 - 0
src/sagas/admin/test/createTest.js

@@ -0,0 +1,59 @@
+import { put, call, all } from 'redux-saga/effects';
+import axios from 'axios';
+
+import { CREATE_QUESTIONS, CREATE_ANSVERS } from '../../../constants/admin';
+import {  createQuestionSuccess, createAnswersSuccess, createTestFailure } from '../../../actions/admin/test/createTest'
+
+export default function* ({ payload: {  questions, array, simple,_id,  token } }) {
+    console.log('User inside the worker-saga', "name", _id, "discription", simple, "question", questions, array);
+    console.log(token)
+    try {
+         
+        const   headers = {
+                "Content-Type": "application/json",
+                "Authorization": `Bearer ${token}`
+            }
+        
+
+
+        const questionses = yield call(
+            axios, {
+                url:`https://test-app-a-level.herokuapp.com/questions`,
+                method:'POST',
+                headers,
+                data:{
+                topicId:_id,
+                question:questions,
+                simple:simple
+                }
+                
+            }
+        )
+
+        
+        const { data: { question } } = questionses;
+        console.log(question._id)
+
+        const responses = yield all(array.map(el =>{ return call(axios,{
+                    url:`https://test-app-a-level.herokuapp.com/answers`,
+                    method:'POST',
+                    headers,
+                    data:{
+                    answer: el.answer,
+                    price: el.price,
+                    correct: el.correct,
+                    questionId:question._id
+                    }
+                  
+        
+                })}))
+
+    // yield put(createTopicsSuccess(topic));
+    yield put(createAnswersSuccess(responses));
+    yield put(createQuestionSuccess(questionses));
+
+}
+    catch ({ message }) {
+    yield put(createTestFailure(message));
+}
+}

+ 35 - 0
src/sagas/admin/test/createTopic.js

@@ -0,0 +1,35 @@
+import { put, call, all } from 'redux-saga/effects';
+import axios from 'axios';
+
+import { CREATE_TOPICS } from '../../../constants/admin';
+import { createTopicsSuccess, createTopicsFailure} from '../../../actions/admin/test/createTopics'
+
+export default function* ({ payload: { name, description, categoryId, token } }) {
+    try {
+         
+        const   headers = {
+                "Content-Type": "application/json",
+                "Authorization": `Bearer ${token}`
+            }
+        
+        const topic = yield call(
+            axios, {
+                url:CREATE_TOPICS,
+                method:'POST',
+                headers,
+                data:{
+                name:name,
+                categoryId:categoryId,
+                description:description
+                }
+                
+            }
+        )
+
+    yield put(createTopicsSuccess(topic));
+
+}
+    catch ({ message }) {
+    yield put(createTopicsFailure(message));
+}
+}

+ 17 - 0
src/sagas/admin/test/index.js

@@ -0,0 +1,17 @@
+
+import * as actionTypes from '../../../constants/admin';
+
+import { takeEvery } from 'redux-saga/effects';
+import createTest from './createTest'
+import createTopic from './createTopic';
+
+export default function* () {
+    yield takeEvery(actionTypes.CREATE_TOPICS_REQUEST, createTopic);
+    yield takeEvery(actionTypes.CREATE_TEST_REQUEST, createTest);
+
+    
+
+
+
+
+}

+ 2 - 1
src/sagas/auth/signIn.js

@@ -15,7 +15,8 @@ export default function* ({ payload }) {
 
         const user = yield call(() =>
             axios.post(SIGN_IN_URL, payload, config)
-                .then(({ data }) => data)
+            .then(({ data }) => data)
+            
         )
 
         // TODO: TOKEN

+ 0 - 1
src/sagas/auth/signUp.js

@@ -14,7 +14,6 @@ export default function* ({payload}) {
 
         const report = yield call(() =>
             axios.post(SIGN_UP_URL, payload, config)
-                .then(({ data }) => data)
         )
 
         yield put(signUpSuccess(report));

+ 4 - 1
src/sagas/index.js

@@ -1,10 +1,13 @@
 import { fork } from "redux-saga/effects";
 import auth from './auth'
 import user from './user/index'
-import admin from './admin/index'
+import admin from './admin/category/index';
+import adminTest from './admin/test/index'
 
 export default function*() {
     yield fork(user);
     yield fork(auth);
     yield fork(admin);
+    yield fork(adminTest);
+
 }

+ 1 - 0
src/styles/_index.scss

@@ -1,6 +1,7 @@
 @import 'abstracts/variables';
 @import 'abstracts/theme';
 @import 'extended/vh';
+@import './components/page';
 @import './style/styles';
 
 @import 'base/typography';

+ 12 - 0
src/styles/abstracts/_theme.scss

@@ -13,9 +13,21 @@
             border:solid;
             border-color: $color-mist
         }
+        &-op{
+            opacity:0.8 ; 
+        }
     }
     &-af {
         background: $color-autumn-foliage !important;
+        &-border{
+            border:solid;
+            border-color: $color-autumn-foliage
+            
+        }
+        
+    }
+    &-gradient{
+        background:linear-gradient(to top, $color-shadow, $color-stone );
     }
 
 

+ 36 - 0
src/styles/components/_page.scss

@@ -0,0 +1,36 @@
+
+
+.profile-page {
+
+    font-size: 20px;
+    .section {
+        flex-grow: 1;
+        flex-basis: 400px;
+        margin: 10px;
+        padding: 10px;
+
+        h3{
+            margin: 25px 0
+        }
+        &__element {
+            &--image {
+                border: 3px solid $color-shadow;
+                margin-bottom: 20px;
+            }
+            p {
+                margin-top: 5px;
+            }
+            .comments-block {
+                height: 250px;
+                overflow: auto;
+            }
+            
+        }
+    }
+    .right {
+        float: right;
+    }
+}
+.check{
+    height: 25px
+}