3 Commits a1765cd5e1 ... a9775a9cc4

Autor SHA1 Nachricht Datum
  sveta a9775a9cc4 get, delete users vor 5 Jahren
  Svetlana e260885cf2 merge Sveta vor 5 Jahren
  = 3d5c13feeb added cards page -> card preview proto vor 5 Jahren
37 geänderte Dateien mit 579 neuen und 158 gelöschten Zeilen
  1. 16 0
      src/actions/adminActions/deleteUser/index.js
  2. 5 5
      src/actions/adminActions/index.js
  3. 4 6
      src/actions/auth/users/users.js
  4. 1 2
      src/actions/auth/index.js
  5. 15 0
      src/actions/cards/index.js
  6. 30 18
      src/components/common/protectedRoute/config.js
  7. 4 4
      src/components/common/protectedRoute/index.js
  8. 6 0
      src/components/common/protectedRoute/validate/index.js
  9. 27 27
      src/components/public-components/auth/signInForm/index.js
  10. 10 10
      src/components/public-components/header/index.js
  11. 22 0
      src/components/user-components/CardsPage/cardPreview/index.js
  12. 52 0
      src/components/user-components/CardsPage/index.js
  13. 43 0
      src/components/user-components/admin-components/createDeleteUser/deleteUser/index.js
  14. 61 0
      src/components/user-components/admin-components/createDeleteUser/formGetUsers/index.js
  15. 36 12
      src/components/user-components/admin-components/createDeleteUser/index.js
  16. 2 5
      src/components/user-components/admin-components/createTestForm/validate/index.js
  17. 1 1
      src/components/user-components/profilePage/LoginFild/index.js
  18. 5 4
      src/components/user-components/profilePage/index.js
  19. 17 2
      src/constants/index.js
  20. 35 0
      src/reducers/cards/index.js
  21. 30 0
      src/reducers/getUser/index.js
  22. 7 3
      src/reducers/index.js
  23. 18 5
      src/reducers/initialState/index.js
  24. 30 0
      src/reducers/users/index.js
  25. 4 8
      src/router.js
  26. 1 2
      src/saga/auth/index.js
  27. 13 15
      src/saga/auth/signIn/index.js
  28. 0 19
      src/saga/auth/users/users.js
  29. 21 0
      src/saga/cards/getCards/index.js
  30. 8 0
      src/saga/cards/index.js
  31. 3 3
      src/saga/index.js
  32. 18 0
      src/saga/userFields/deleteUser/index.js
  33. 18 0
      src/saga/userFields/getUser/index.js
  34. 4 4
      src/saga/userFields/createDeleteUser/index.js
  35. 7 2
      src/saga/userFields/index.js
  36. 1 1
      src/state/index.js
  37. 4 0
      src/styles/components/_profilePage.scss

+ 16 - 0
src/actions/adminActions/deleteUser/index.js

@@ -0,0 +1,16 @@
+import * as types from '../../../constants';
+
+export const deleteUserRequest = payload => ({
+    type: types.DELETE_USER_REQUEST,
+    payload
+})
+
+export const deleteUserRequestSucces = payload => ({
+    type: types.DELETE_USER_REQUEST_SUCCESS,
+    payload
+})
+
+export const deleteUserRequestFailure = error => ({
+    type: types.DELETE_USER_REQUEST_FAILURE,
+    error
+})

+ 5 - 5
src/actions/adminActions/index.js

@@ -1,16 +1,16 @@
-import * as types from '../../constants';
+import * as types from '../../../constants';
 
 export const userGetRequest = payload => ({
-    type: types.USERS_GET_REQUEST,
+    type: types.USER_GET_REQUEST,
     payload
 })
 
 export const userGetRequestSucces = payload => ({
-    type: types.USERS_GET_REQUEST_SUCCESS,
+    type: types.USER_GET_REQUEST_SUCCESS,
     payload
 })
 
 export const userGetRequestFailure = error => ({
-    type: types.USERS_GET_REQUEST_FAILURE,
+    type: types.USER_GET_REQUEST_FAILURE,
     error
-})
+})

+ 4 - 6
src/actions/auth/users/users.js

@@ -1,10 +1,7 @@
 import * as types from '../../../constants';
 
-// all actions for signing up
-
-export const usersGetRequest= payload => ({
+export const usersGetRequest = () => ({
     type: types.USERS_GET_REQUEST,
-    payload
 })
 
 export const usersGetRequestSucces = payload => ({
@@ -13,6 +10,7 @@ export const usersGetRequestSucces = payload => ({
 })
 
 export const usersGetRequestFailure = error => ({
-    type: types.USERS_GET_REQUEST_SUCCESS_FAILURE ,
+    type: types.USERS_GET_REQUEST_FAILURE,
     error
-})
+})
+

+ 1 - 2
src/actions/auth/index.js

@@ -1,11 +1,10 @@
 import * as signInActions from './signIn';
 import * as signUpActions from './signUp';
 import * as signOutActions from './signOut';
-import * as usersGetActions from './signOut';
+
 
 export default {
     ...signInActions,
     ...signUpActions,
     ...signOutActions,
-    ...usersGetActions
 }

+ 15 - 0
src/actions/cards/index.js

@@ -0,0 +1,15 @@
+import * as actionTypes from './../../constants';
+
+export const getCards = () => ({
+    type: actionTypes.GET_CARDS
+})
+
+export const getCardsSuccess = (payload) => ({
+    type: actionTypes.GET_CARDS_SUCCESS,
+    payload
+})
+
+export const getCardsFailure = (error) => ({
+    type: actionTypes.GET_CARDS_FAILURE,
+    error
+})

+ 30 - 18
src/components/common/protectedRoute/config.js

@@ -1,49 +1,61 @@
+import React from 'react';
 import * as routes from './../../../constants/routes';
 import { lazy } from 'react';
 
-const landingPage = lazy(() => import('./../../public-components/landingPage'));
-const homePage = lazy(() => import('./../../user-components/homePage'));
-const signInPage = lazy(() => import('./../../../containers/auth/SignInPage'));
-const signUpPage = lazy(() => import('./../../../containers/auth/SignUpPage'));
-const createTestForm = lazy(() => import('./../../user-components/admin-components/createTestForm'));
-const profilePage = lazy(() => import('./../../user-components/profilePage'));
-const categoriesPage = lazy(() => import('./../../user-components/categoriesPage'));
-
+const DeleteUsers = lazy(()=>import('../../user-components/admin-components/createDeleteUser/index'))
+const LandingPage =    lazy(() => import('./../../public-components/landingPage'));
+const HomePage =       lazy(() => import('./../../user-components/homePage'));
+const SignInPage =     lazy(() => import('./../../../containers/auth/SignInPage'));
+const SignUpPage =     lazy(() => import('./../../../containers/auth/SignUpPage'));
+const CreateTestForm = lazy(() => import('./../../user-components/admin-components/createTestForm'));
+const ProfilePage =    lazy(() => import('./../../user-components/profilePage'));
+const CategoriesPage = lazy(() => import('./../../user-components/categoriesPage'));
+const CardsPage =      lazy(() => import('./../../user-components/CardsPage'));
+const NotFound =       lazy(() => import('./../../public-components/notFound'));
 
 export default [
     {
         path: routes.LANDING,
         access: 'public',
-        component: landingPage
+        component: LandingPage
     },
     {
         path: routes.SIGN_IN,
         access: 'public',
-        component: signInPage
+        component: SignInPage
     },
     {
         path: routes.SIGN_UP,
         access: 'public',
-        component: signUpPage
+        component: SignUpPage
     },
     {
         path: routes.HOME,
-        access: 'public',
-        component: homePage
+        access: 'user-only',
+        component: HomePage
     },
     {
         path: routes.CATEGORIES,
         access: 'user-only',
-        component: categoriesPage
+        component: CategoriesPage
     },
     {
         path: routes.PROFILE,
         access: 'user-only',
-        component: profilePage
+        component: ProfilePage
+    },
+    {
+        path: routes.TESTS,
+        access: 'user-only',
+        component: CardsPage
     },
     {
-        path: routes.CREATE_TEST,
+        path: routes.DELETE_USER ,
         access: 'admin-only',
-        component: createTestForm
-    }
+        component: DeleteUsers
+    },
+    {
+        access: 'public',
+        component: NotFound
+    },
 ]

+ 4 - 4
src/components/common/protectedRoute/index.js

@@ -4,7 +4,7 @@ import { Route, Redirect } from 'react-router-dom';
 import * as routes from './../../../constants/routes';
 import PermissionDenied from './../../public-components/permissionDenied';
 
-export default ({ component: Component, user, access, ...rest  }) => (
+export default ({ component: Component, user: {data}, access, ...rest  }) => (
     <Route
         {...rest}
         render={props => {
@@ -13,16 +13,16 @@ export default ({ component: Component, user, access, ...rest  }) => (
                 return <Component {...props} />
             }
             
-            if ( (access === 'user-only' || access === 'admin-only') && !user.data ) {
+            if ( (access === 'user-only' || access === 'admin-only') && !data ) {
                 return <Redirect to={routes.SIGN_IN}/>
             }
             
-            if (access === 'user-only' && user.data) {
+            if (access === 'user-only' && data) {
                 return <Component {...props} />
             }        
 
             if (access === 'admin-only') {
-                if (user.is_admin) {
+                if (data.is_admin) {
                     return <Component {...props} />
                 } 
 

+ 6 - 0
src/components/common/protectedRoute/validate/index.js

@@ -0,0 +1,6 @@
+export default function validate(values) {
+    const {} = values;
+    const errors = {}
+
+    return errors;
+}

+ 27 - 27
src/components/public-components/auth/signInForm/index.js

@@ -8,34 +8,34 @@ import { Link } from 'react-router-dom'
 import * as routes from './../../../../constants/routes'
 
 class Form extends React.Component {
-    sendRequest = values => {
-        const { actions: { signInRequest } } = this.props;
-        signInRequest(values);
-    }
-
-    render() {
-        const { invalid, handleSubmit, submitting, requestError } = this.props;
-
-        return (
-            <form className="sign-form" onSubmit={handleSubmit(this.sendRequest)}>
-                <h2 className="sign-form__header">Sign In</h2>
-                
-                {requestError && <p className="error-line error-line--warn error-line--no-margin">{requestError}</p>}
-
-                <Field className="sign-form__input sign-form__input--text" placeholder="Login" name="login" component={formInput} type="text" />
-                <Field className="sign-form__input sign-form__input--password" placeholder="Password" name="password" component={formInput} type="password" />
-                
-                <button className="link--btn link--btn60" disabled={invalid || submitting}>Sign In</button>
-                
-                <p className="sign-form__link--forgot-password"><Link className="link--inline" to={routes.PASSWORD_FORGET}>Forgot password ?</Link></p>
-                <hr className="sign-form__divider" />
-                <p className="sign-form__link--sign-up">Still ain't got an account? <Link className="link--inline" to={routes.SIGN_UP}>Sign up</Link> first!</p>
-            </form>
-        )
-    }
+  sendRequest = values => {
+    const { actions: { signInRequest } } = this.props;
+    signInRequest(values);
+  }
+
+  render() {
+    const { invalid, handleSubmit, submitting, requestError } = this.props;
+
+    return (
+      <form className="sign-form" onSubmit={handleSubmit(this.sendRequest)}>
+        <h2 className="sign-form__header">Sign In</h2>
+
+        {requestError && <p className="error-line error-line--warn error-line--no-margin">{requestError}</p>}
+
+        <Field className="sign-form__input sign-form__input--text" placeholder="Login" name="login" component={formInput} type="text" />
+        <Field className="sign-form__input sign-form__input--password" placeholder="Password" name="password" component={formInput} type="password" />
+
+        <button className="link--btn link--btn60" disabled={invalid || submitting}>Sign In</button>
+
+        <p className="sign-form__link--forgot-password"><Link className="link--inline" to={routes.PASSWORD_FORGET}>Forgot password ?</Link></p>
+        <hr className="sign-form__divider" />
+        <p className="sign-form__link--sign-up">Still ain't got an account? <Link className="link--inline" to={routes.SIGN_UP}>Sign up</Link> first!</p>
+      </form>
+    )
+  }
 }
 
 export default reduxForm({
-    form: "signIn",
-    validate
+  form: "signIn",
+  validate
 })(Form)

+ 10 - 10
src/components/public-components/header/index.js

@@ -23,8 +23,8 @@ export default class header extends Component {
 
     render() {
         const { togglerClosed } = this.state;
-        const { user:{data} } = this.props;
-        const toggleStatus = togglerClosed ? "toggle-status--closed" : "toggle-status--opened"
+        const { user: { data } } = this.props;
+        const toggleStatus = togglerClosed ? "toggle-status--closed" : "toggle-status--opened";
 
         return (
             <header className="header">
@@ -42,22 +42,22 @@ export default class header extends Component {
                             <li>
                                 <Link className="header__nav nav__list-item" to={routes.HOME}>
                                     Home
-                                </Link>
+                </Link>
                             </li>
                             <li>
                                 <Link className="header__nav nav__list-item" to={routes.PROFILE}>
                                     Profile
-                                </Link>
+                </Link>
                             </li>
                             <li>
                                 <Link className="header__nav nav__list-item" to={routes.TESTS}>
                                     Test
-                                </Link>
+                </Link>
                             </li>
                             <li>
                                 <Link className="header__nav nav__list-item" to={routes.CATEGORIES}>
                                     Categories
-                                </Link>
+                </Link>
                             </li>
                             {
                                 data && data.is_admin && (
@@ -65,17 +65,17 @@ export default class header extends Component {
                                         <li>
                                             <Link className="header__nav nav__list-item--admin-only" to={routes.CREATE_TEST}>
                                                 Create test
-                                            </Link>
+                            </Link>
                                         </li>
                                         <li>
                                             <Link className="header__nav nav__list-item--admin-only" to={routes.CREATE_CATEGORY}>
                                                 Create category
-                                            </Link>
+                            </Link>
                                         </li>
                                         <li>
                                             <Link className="header__nav nav__list-item--admin-only" to={routes.DELETE_USER}>
-                                                Delete user
-                                            </Link>
+                                                Delete data
+                            </Link>
                                         </li>
                                     </React.Fragment>
                                 )

+ 22 - 0
src/components/user-components/CardsPage/cardPreview/index.js

@@ -0,0 +1,22 @@
+import React from 'react';
+
+const styles = {
+    img: {
+        display: 'inline-block'
+    },
+    h3: {
+        marginTop: 0
+    },
+    p: {
+
+    }
+}
+
+const CardPreview = ({ description, title, cover }) => (
+    <div className=''>
+        <img src={cover} style={styles.img}/>
+        <h3 style={styles.h3}>{title}</h3>
+    </div>  
+)
+
+export default CardPreview;

+ 52 - 0
src/components/user-components/CardsPage/index.js

@@ -0,0 +1,52 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
+
+import { getCards } from './../../../actions/cards'
+
+import CardPreview from './cardPreview';
+import Spinner from './../../common/spinner';
+
+
+class CardsPage extends React.Component {
+    componentDidMount() {
+        const { getCards } = this.props;
+        getCards();
+    }
+
+    render() {
+        const { cards: { isFetching, data, error }, getCards } = this.props;
+        console.log('Pasha lox', isFetching, data, error);
+        console.log('PROPS', this.props);
+
+        return (
+            isFetching
+                ?
+                <Spinner />
+                : data
+                    ?
+                    <div className='page' >
+                        {data.map(card => (
+                            <CardPreview
+                                title={card.name}
+                                cover={card.image}
+                                action={null}
+                            />))}
+                    </div >
+                    : error
+                        ?
+                        <div className='page' >
+                            Error handler
+                        </div >
+                        :
+                        null
+        )
+    }
+}
+
+const mapStateToProps = state => ({
+    cards: state.cards
+});
+const mapDispatchToProps = dispatch => bindActionCreators({ getCards }, dispatch);
+
+export default connect(mapStateToProps, mapDispatchToProps)(CardsPage);

+ 43 - 0
src/components/user-components/admin-components/createDeleteUser/deleteUser/index.js

@@ -0,0 +1,43 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { Field, reduxForm } from 'redux-form';
+import { bindActionCreators } from 'redux'
+
+import formInput from '../../../../common/formInput/index';
+import {userGetRequest} from '../../../../../actions/adminActions/getUser';
+import {deleteUserRequest} from '../../../../../actions/adminActions/deleteUser'
+
+
+
+class DeleteUser extends React.Component {
+    onClick =() =>{
+        const { deleteUserRequest, data:{login}} = this.props;
+        console.log(login)
+        deleteUserRequest({
+            login
+        })
+    }
+
+    // handleClick = () => {
+    //     this.setState((prevState) => ({ clicked: !prevState.clicked }));
+    // }
+    render() {
+    const {data} =this.props
+    console.log(data)
+        return (<div>
+                    {data.login}
+                <button onClick ={this.onClick}>
+                    Delete
+                    </button>
+        </div>
+        )
+    }
+}
+
+
+
+
+const mapDispatchToProps = dispatch => bindActionCreators({ deleteUserRequest }, dispatch);
+
+
+export default connect( null,mapDispatchToProps)(DeleteUser)

+ 61 - 0
src/components/user-components/admin-components/createDeleteUser/formGetUsers/index.js

@@ -0,0 +1,61 @@
+import React from 'react';
+import { connect } from 'react-redux';
+import { Field, reduxForm } from 'redux-form';
+import { bindActionCreators } from 'redux'
+
+import formInput from '../../../../common/formInput/index';
+import {userGetRequest} from '../../../../../actions/adminActions/getUser'
+import DeleteUser from '../deleteUser/index'
+
+
+
+class FormGetUsers extends React.Component {
+    submit = ({ login}) => {
+        console.log('handleSubmit->submit', this.props)
+        const { userGetRequest }  = this.props;
+
+        console.log('hghjgjhg',login);
+
+        userGetRequest({
+            login
+        })
+    }
+
+    // handleClick = () => {
+    //     this.setState((prevState) => ({ clicked: !prevState.clicked }));
+    // }
+    render() {
+        const { handleSubmit, getUser:{data} } = this.props
+        const {submit} =this
+        console.log(data)
+        return (<div>
+            <form className="page" onSubmit = {handleSubmit(submit)}>
+                <Field name="login" type="email" placeholder="Enter new login" component={formInput} />
+                <button >Search</button>
+            </form >
+            {
+                data !== null?
+                       ( <div>
+                <DeleteUser data ={data}></DeleteUser>
+                        </div>
+                       ):
+                       <div>dddd</div>
+            }
+        </div>
+        )
+    }
+}
+
+const
+    mapStateToProps = state => ({
+        users: state.users,
+        getUser:state.getUser
+    });
+
+
+const mapDispatchToProps = dispatch => bindActionCreators({userGetRequest }, dispatch);
+
+
+export default connect(mapStateToProps, mapDispatchToProps)(reduxForm({
+    form: "FormGetUsers",
+})(FormGetUsers))

+ 36 - 12
src/components/user-components/admin-components/createDeleteUser/index.js

@@ -1,29 +1,53 @@
 import React from 'react';
 import { connect } from 'react-redux';
 import { Field, reduxForm } from 'redux-form';
+import { bindActionCreators } from 'redux'
 
 import formInput from '../../..//common/formInput';
- submit=()=>{
-     
- }
+import { usersGetRequest } from '../../../../actions/adminActions/getUsers/index'
+import FormGetUsers from './formGetUsers/index'
 
-class createDeleteUser extends React.Component {
 
+class createDeleteUser extends React.Component {
+    componentDidMount() {
+        const { usersGetRequest } = this.props;
+        usersGetRequest();
+    }
     render() {
-        const {  handleSubmit  } = this.props;
+        const { handleSubmit, users:{data} } = this.props;
+        console.log(data)
         return (
-            <form  className="page">
-                <Field name="login"  type="email" placeholder="Enter new login" component={formInput} />
-                <button >Search</button>
-            </form >
+            <div className="page page--bottom-only profile-page">
+                <section className="container section section--about">
+            <FormGetUsers></FormGetUsers>
+        </section>
+        <section className="container section section--about">
+            {data&&data.map(str=>
+            <div className="container section section--about">
+            <ul >
+                <h5>LOGIN</h5>
+                {str.login}
+                </ul>
+            <ul >
+                <h5>PASSWORD</h5>
+            {str.password}
+                </ul>
+                </div>)}
+            </section>
+        </div>
         )
     }
 }
 
+const
+    mapStateToProps = state => ({
+        users: state.users
+    });
+
 
-const mapDispatchToProps = dispatch => bindActionCreators({ userGetRequest }, dispatch);
+const mapDispatchToProps = dispatch => bindActionCreators({ usersGetRequest }, dispatch);
 
 
-export default connect(mapDispatchToProps)(reduxForm({
-    form: "createDeleteUser",   
+export default connect(mapStateToProps, mapDispatchToProps)(reduxForm({
+    form: "createDeleteUser",
 })(createDeleteUser))

+ 2 - 5
src/components/user-components/admin-components/createTestForm/validate/index.js

@@ -1,6 +1,3 @@
-export default function validate(values) {
-    const {} = values;
-    const errors = {}
-
-    return errors;
+export default () => {
+  
 }

+ 1 - 1
src/components/user-components/profilePage/LoginFild/index.js

@@ -37,7 +37,7 @@ export default class ChangeLogin extends React.Component {
                 ?
                 (
                     <React.Fragment>
-                        <div>{children}</div>
+                        <div >{children}</div>
                         <button className="link link--btn right"onClick={handleClick}>Change Email</button>
                     </React.Fragment>
                 )

+ 5 - 4
src/components/user-components/profilePage/index.js

@@ -49,9 +49,9 @@ class profilePage extends React.Component {
 
 
     render() {
-        const { user:{data}, userChangeRequest,passwordChangeRequest } = this.props;
+        const { user:{data},users, userChangeRequest,passwordChangeRequest } = this.props;
 
-        // console.log('User', user);
+        console.log('User', users);
         // console.log('Props', this.props);
         // console.log('State', this.state);
 
@@ -59,7 +59,7 @@ class profilePage extends React.Component {
             <div className="page page--bottom-only profile-page">
                 <section className="container section section--about">
                     {/* <h2 className="section__element section__element--header">{data.login}</h2> */}
-        
+
                     <div className="sedtion__element section__element--login">
                         <h3>Email</h3>
                         {/* <p>{user.login}<button className="link link--btn right" >Change login</button></p> */}
@@ -102,7 +102,8 @@ class profilePage extends React.Component {
 
 const
     mapStateToProps = state => ({
-        user: state.user
+        user: state.user,
+        users:state.users
     });
 
 const mapDispatchToProps = dispatch => bindActionCreators({ userChangeRequest, passwordChangeRequest }, dispatch);

+ 17 - 2
src/constants/index.js

@@ -15,7 +15,7 @@ export const SIGN_OUT = 'SIGN_OUT';
 
 export const USERS_GET_REQUEST = 'USERS_GET_REQUEST';
 export const USERS_GET_REQUEST_SUCCESS = 'USERS_GET_REQUEST_SUCCESS';
-export const USERS_GET_REQUEST_SUCCESS_FAILURE = 'USERS_GET_REQUEST_FAILURE';
+export const USERS_GET_REQUEST_FAILURE = 'USERS_GET_REQUEST_FAILURE';
 
 export const TOKEN_AUTH = 'TOKEN_AUTH';
 
@@ -26,4 +26,19 @@ export const USERS_CHANGE_REQUEST_FAILURE = 'USERS_CHANGE_REQUEST_FAILURE';
 
 export const PASSWORD_CHANGE_REQUEST = 'PASSWORD_CHANGE_REQUEST';
 export const PASSWORD_CHANGE_REQUEST_SUCCESS = 'PASSWORD_CHANGE_REQUEST_SUCCESS';
-export const PASSWORD_CHANGE_REQUEST_FAILURE = 'PASSWORD_CHANGE_REQUEST_FAILURE';
+export const PASSWORD_CHANGE_REQUEST_FAILURE = 'PASSWORD_CHANGE_REQUEST_FAILURE';
+
+export const GET_CARDS_URL = 'https://quiz.maxcrc.de/api/v1/quiz';
+
+export const GET_CARDS = 'GET_CARD';
+export const GET_CARDS_SUCCESS = 'GET_CARDS_SUCCESS';
+export const GET_CARDS_FAILURE = 'GET_CARDS_FAILURE';
+
+export const USER_GET ='http://quiz.maxcrc.de/api/v1/user?'
+export const USER_GET_REQUEST = 'USER_GET_REQUEST';
+export const USER_GET_REQUEST_SUCCESS = 'USER_GET_REQUEST_SUCCESS';
+export const USER_GET_REQUEST_FAILURE = 'USER_GET_REQUEST_FAILURE';
+
+export const DELETE_USER_REQUEST = 'DELETE_USER_REQUEST';
+export const DELETE_USER_REQUEST_SUCCESS = 'DELETE_USER_REQUEST_SUCCESS';
+export const DELETE_USER_REQUEST_FAILURE = 'DELETE_USER_REQUEST_FAILURE';

+ 35 - 0
src/reducers/cards/index.js

@@ -0,0 +1,35 @@
+import * as actionTypes from './../../constants';
+import initialState from './../initialState';
+
+export default function cards(state = initialState.cards, { type, payload: data, error }) {
+    switch (type) {
+        case actionTypes.GET_CARDS: {
+            return {
+                ...state,
+                isFetching: true,
+                data: null,
+                error: null
+            }
+        }
+        case actionTypes.GET_CARDS_SUCCESS: {
+            return {
+                ...state,
+                isFetching: false,
+                data,
+                error: null
+            }
+        }
+        case actionTypes.GET_CARDS_FAILURE: {
+            return {
+                ...state,
+                isFetching: false,
+                data: null,
+                error
+            }
+        }
+        default: {
+            return state
+        }
+    }
+
+}

+ 30 - 0
src/reducers/getUser/index.js

@@ -0,0 +1,30 @@
+import * as types from "../../constants/index";
+import initialState from '../initialState';
+
+export default function getUser(state = initialState.getUser, {type, payload: data, error }) {
+    switch (type) {
+        case types.USER_GET_REQUEST: {
+            return {
+                ...state,
+                isFetching: true
+            }
+        }
+        case types.USER_GET_REQUEST_SUCCESS: {
+            return {
+                ...state,
+                isFetching: false,
+                data
+            }
+        }
+        case types.USER_GET_REQUEST_FAILURE: {
+            return {
+                ...state,
+                isFetching: false,
+                error
+            }
+        }
+        default: {
+            return state
+        }
+    }
+}

+ 7 - 3
src/reducers/index.js

@@ -2,11 +2,12 @@
 // для создания store 
 import { combineReducers } from 'redux';
 
-
 import user from './user';
-
 import changeEmail from './userFields/changeEmail/index';
 import changePassword from './userFields/changePassword/index'
+import cards from './cards';
+import users from './users'
+import getUser from './getUser'
 
 import { reducer as form } from 'redux-form';
 
@@ -16,7 +17,10 @@ const combinedReducers = combineReducers({
     form,
     user,
     changeEmail,
-    changePassword
+    changePassword,
+    cards,
+    users,
+    getUser
 })
 
 export default combinedReducers;

+ 18 - 5
src/reducers/initialState/index.js

@@ -2,14 +2,27 @@ export default {
     user: {       
         data: null,
         error: null,
-        isFetching: null,
-
     },
     changeEmail: {
         login: null
-    },
-    
+    },  
     changePassword: {
-        password: null
+        password: null,
+        isFetching: null
+    },
+    cards: {
+        data: null,
+        error: null,
+        isFetching: null
+    },
+    users: {
+        data: null,
+        error: null,
+        isFetching: null
+    },
+    getUser:{
+        data:null,
+        error: null,
+        isFetching: null
     }
 }

+ 30 - 0
src/reducers/users/index.js

@@ -0,0 +1,30 @@
+import * as types from "../../constants/index";
+import initialState from '../initialState';
+
+export default function getUsers(state = initialState.users, {type, payload: data, error }) {
+    switch (type) {
+        case types.USERS_GET_REQUEST: {
+            return {
+                ...state,
+                isFetching: true
+            }
+        }
+        case types.USERS_GET_REQUEST_SUCCESS: {
+            return {
+                ...state,
+                isFetching: false,
+                data
+            }
+        }
+        case types.USERS_GET_REQUEST_FAILURE: {
+            return {
+                ...state,
+                isFetching: false,
+                error
+            }
+        }
+        default: {
+            return state
+        }
+    }
+}

+ 4 - 8
src/router.js

@@ -15,8 +15,6 @@ import config from './components/common/protectedRoute/config';
 import fakeToken from './utils/token'
 import { bindActionCreators } from "redux";
 
-const notFound = lazy(() => import('./components/public-components/notFound'));
-
 class Router extends React.Component {
 
     componentDidMount() {
@@ -29,10 +27,9 @@ class Router extends React.Component {
 
     render() {
         const { user } = this.props;
-
+        
         //map located here because of switch-bag
-
-        const protectedRoutes = config.map(route =>
+        const Router = config.map(route =>
             <ProtectedRoute
                 path={route.path}
                 component={route.component}
@@ -40,15 +37,14 @@ class Router extends React.Component {
                 user={user}
                 exact
             />
-        );
+        )
 
         return (
             <div className="app">
                 <Header />
                 <Suspense fallback={<Spinner />}>
                     <Switch>
-                        {protectedRoutes}
-                        <Route component={notFound} />
+                        {Router}
                     </Switch>
                 </Suspense>
                 <Footer />

+ 1 - 2
src/saga/auth/index.js

@@ -3,12 +3,11 @@ import * as types from "./../../constants"
 
 import signIn from './signIn';
 import signUp from './signUp';
-import getUsers from './users/users';
+
 
 export default function*() {
     yield takeEvery(types.SIGN_IN_REQUEST, signIn);
     yield takeEvery(types.SIGN_UP_REQUEST, signUp);
-    yield takeEvery(types.USERS_GET_REQUEST, getUsers);
 }
 
 

+ 13 - 15
src/saga/auth/signIn/index.js

@@ -7,20 +7,18 @@ import token from '../../../utils/token'
 // worker-saga for signing in
 
 export default function* ({ payload: { login, password } }) {
-    try {
-        const payload = yield call(() =>
-            axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`)
-                .then(({ data: [payload] }) => payload)
-        );
+  try {
+    const payload = yield call(() =>
+      axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`)
+        .then(({ data: [payload] }) => payload)
+    );
 
-        yield call(() => { if (!payload) throw (new Error("No such email or password")) })
-
-        yield put(actions.signInRequestSucces(payload));
-        yield call(() => localStorage.setItem(token, JSON.stringify(payload)));
-    }
-    catch ({ message }) {
-        yield put(actions.signInRequestFailure(message))
-        yield call(() => localStorage.removeItem(token));
-
-    }
+    yield call(() => { if (!payload) throw (new Error("No such email or password")) });
+    yield put(actions.signInRequestSucces(payload));
+    yield call(() => localStorage.setItem(token, JSON.stringify(payload)));
+  }
+  catch ({ message }) {
+    yield put(actions.signInRequestFailure(message));
+    yield call(() => localStorage.removeItem(token));
+  }
 }

+ 0 - 19
src/saga/auth/users/users.js

@@ -1,19 +0,0 @@
-import { put, call } from "redux-saga/effects";
-import * as actions from './../../../actions/auth/users/users'
-import axios from 'axios';
-
-
-
-export default function* ({ payload: requestBody }) {
-    try {
-        const payload = yield call(() =>
-            axios.get(`https://quiz.maxcrc.de/api/v1/user`)
-                .then(({ data }) => data)
-        );
-        
-        yield put(actions.usersGetRequestSucces(payload));
-    }
-    catch ({ message }) {
-        yield put(actions.usersGetRequestFailure(message))
-    }
-}

+ 21 - 0
src/saga/cards/getCards/index.js

@@ -0,0 +1,21 @@
+import { put, call } from "redux-saga/effects";
+import * as actions from '../../../actions/cards';
+import axios from 'axios';
+
+import { GET_CARDS_URL } from './../../../constants/index'
+
+// worker-saga for getting cards
+
+export default function* () {
+    try {
+        const payload = yield call(() =>
+            axios.get(GET_CARDS_URL)
+                .then(({ data }) => data)
+        );
+
+        yield put(actions.getCardsSuccess(payload));
+    }
+    catch ({ message }) {
+        yield put(actions.getCardsFailure(message))
+    }
+}

+ 8 - 0
src/saga/cards/index.js

@@ -0,0 +1,8 @@
+import { takeEvery } from "redux-saga/effects";
+
+import getCards from './getCards';
+import { GET_CARDS } from "./../../constants"
+
+export default function*() {
+    yield takeEvery(GET_CARDS, getCards);
+}

+ 3 - 3
src/saga/index.js

@@ -1,12 +1,12 @@
 import { fork } from "redux-saga/effects";
 import auth from './auth'
 import userFields from './userFields/index';
-
+import cards from './cards';
 
 export default function*() {
     yield [
         fork(auth),
         fork(userFields),
-        
-    ];
+        fork(cards)
+    ]
 }

+ 18 - 0
src/saga/userFields/deleteUser/index.js

@@ -0,0 +1,18 @@
+import { put, call } from "redux-saga/effects";
+import * as actions from './../../../actions/adminActions/deleteUser'
+import axios from 'axios';
+import { USER_GET } from '../../../constants/index'
+
+export default function* ({payload:{login}}) {
+    try {
+        console.log("payload inside the saga", login);
+        const payloads = yield call(() =>
+            axios.delete(`${USER_GET}login=${login}`)
+                .then((data) => data)
+        );
+        yield put(actions.deleteUserRequestSucces(payloads));
+    }
+    catch ({ message }) {
+        yield put(actions.deleteUserRequestFailure(message))
+    }
+}

+ 18 - 0
src/saga/userFields/getUser/index.js

@@ -0,0 +1,18 @@
+import { put, call } from "redux-saga/effects";
+import * as actions from '../../../actions/adminActions/getUser/index'
+import axios from 'axios';
+import { USER_GET } from '../../../constants/index'
+
+export default function* ({payload:{login}}) {
+    try {
+        console.log("payload inside the saga",login);
+        const payloads = yield call(() =>
+            axios.get(`${USER_GET}login=${login}`)
+                .then(({data: [payload]}) => payload)
+        );
+        yield put(actions.userGetRequestSucces(payloads));
+    }
+    catch ({ message }) {
+        yield put(actions.userGetRequestFailure(message))
+    }
+}

+ 4 - 4
src/saga/userFields/createDeleteUser/index.js

@@ -1,5 +1,5 @@
 import { put, call } from "redux-saga/effects";
-import * as actions from './../../../actions/adminActions/index'
+import * as actions from '../../../actions/adminActions/getUsers/index'
 import axios from 'axios';
 import { SIGN_UP_URL } from '../../../constants/index'
 
@@ -8,11 +8,11 @@ export default function* (payload) {
         console.log("payload inside the saga", payload);
         const payloads = yield call(() =>
             axios.get(SIGN_UP_URL)
-                .then(({ data }) => data)
+                .then(({data}) => data)
         );
-        yield put(actions.userGetRequestSucces(payloads));
+        yield put(actions.usersGetRequestSucces(payloads));
     }
     catch ({ message }) {
-        yield put(actions.userGetRequestFailure(message))
+        yield put(actions.usersGetRequestFailure(message))
     }
 }

+ 7 - 2
src/saga/userFields/index.js

@@ -3,9 +3,14 @@ import * as types from "./../../constants"
 
 import changeEmail from './changeEmail/index';
 import changePassword from "./changePassword";
-
+import getUsers from './getUsers'
+import getUser from './getUser'
+import deleteUser from './deleteUser'
 
 export default function*() {
     yield takeEvery(types.USERS_CHANGE_REQUEST, changeEmail);
-    yield takeEvery(types.PASSWORD_CHANGE_REQUEST, changePassword)
+    yield takeEvery(types.PASSWORD_CHANGE_REQUEST, changePassword);
+    yield takeEvery(types.USERS_GET_REQUEST, getUsers);
+    yield takeEvery(types.USER_GET_REQUEST, getUser);
+    yield takeEvery(types.DELETE_USER_REQUEST, deleteUser);
 }

+ 1 - 1
src/state/index.js

@@ -14,7 +14,7 @@ const logger = createLogger({
 const store = createStore(
     combinedReducers,
     initialState,
-    applyMiddleware(sagaMiddleware)
+    applyMiddleware(sagaMiddleware, logger)
 );
 export default store;
 

+ 4 - 0
src/styles/components/_profilePage.scss

@@ -8,6 +8,10 @@
         flex-basis: 400px;
         margin: 10px;
         padding: 10px;
+
+        h3{
+            margin: 25px 0
+        }
         &__element {
             &--image {
                 border: 3px solid $color-lightsteelblue;