Browse Source

athuorisation added back

Alex 5 years ago
parent
commit
a149e26a04

+ 5 - 0
package-lock.json

@@ -14733,6 +14733,11 @@
         }
         }
       }
       }
     },
     },
+    "redux-thunk": {
+      "version": "2.3.0",
+      "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz",
+      "integrity": "sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw=="
+    },
     "regenerate": {
     "regenerate": {
       "version": "1.4.0",
       "version": "1.4.0",
       "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz",
       "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz",

+ 2 - 1
package.json

@@ -11,7 +11,8 @@
     "react-router-dom": "^4.3.1",
     "react-router-dom": "^4.3.1",
     "react-scripts": "^2.1.3",
     "react-scripts": "^2.1.3",
     "redux": "^4.0.1",
     "redux": "^4.0.1",
-    "redux-form": "^8.1.0"
+    "redux-form": "^8.1.0",
+    "redux-thunk": "^2.3.0"
   },
   },
   "scripts": {
   "scripts": {
     "start": "react-scripts start",
     "start": "react-scripts start",

+ 0 - 5
src/actions/index.js

@@ -1,5 +0,0 @@
-import * as types from "../constants/actionTypes";
-
-export const getUsersData = (payload)=>({
-    type: types.GETDATA, payload
-});

+ 31 - 0
src/actions/usersAuthActions.js

@@ -0,0 +1,31 @@
+import * as types from "../constants/actionTypes";
+
+const axios= require("axios");
+
+const userAuthRequest = payload => ({
+    type: types.USER_AUTH_REQUEST,
+    payload
+})
+
+//const userAuthRequestSuccess = payload => ({
+//type: types.USER_AUTH_REQUEST_SUCCESS,
+//    payload
+//})
+
+const userAuthRequestFail = payload => ({
+    type: types.USER_AUTH_REQUEST_FAIL,
+    payload
+})
+
+export const getUsersData = (payload) => {
+    return dispatch => {
+        dispatch(userAuthRequest());
+        return axios.get(`http://127.0.0.1:2000/api/users`)
+            .then(res => {
+                 console.log(res);
+                })
+            .catch(err => {
+                dispatch(userAuthRequestFail(err));
+            })
+    }
+}

+ 32 - 0
src/actions/usersRegistrActions.js

@@ -0,0 +1,32 @@
+import * as types from "../constants/actionTypes";
+
+const axios= require("axios");
+
+const userRegRequest = payload => ({
+    type: types.USER_REG_REQUEST,
+    payload
+});
+
+const userRegRequestSuccess = payload => ({
+    type: types.USER_REG_REQUEST_SUCCESS,
+    payload
+});
+
+const userRegRequestFail = payload => ({
+    type: types.USER_REG_REQUEST_FAIL,
+    payload
+});
+
+export const postUsersData = (payload) =>{
+    return dispatch => {
+    dispatch(userRegRequest());
+    return axios.post(`http://127.0.0.1:2000/api/users`,payload)
+                    .then(res => {
+                            setTimeout(()=>{dispatch(userRegRequestSuccess(res))},2000);
+                        })
+                    .catch(err=>{
+                            dispatch(userRegRequestFail(err));
+                    })    
+      
+  };
+};

+ 15 - 0
src/components/Auth/authButtons.js

@@ -0,0 +1,15 @@
+import React, {Component} from "react"
+import {Link} from "react-router-dom"
+
+class Authbuttons extends Component {
+  render() {
+    return (
+        <div className="auth__button">
+          <Link to="/auth">Войти</Link>
+          <Link to="/registration">Зарегистрироваться</Link>
+        </div>
+    )
+  }
+}
+
+export default Authbuttons;

+ 12 - 8
src/components/Auth/authorisation.js

@@ -1,19 +1,23 @@
 import React from "react";
 import React from "react";
 import { reduxForm, Field } from "redux-form";
 import { reduxForm, Field } from "redux-form";
 import  authValidate  from "../../utils/validate";
 import  authValidate  from "../../utils/validate";
-import Auth from './index'
+import Authbuttons from './authButtons'
+
 const Form = props => {
 const Form = props => {
-  const { handleSubmit,submitting } = props
+  const { handleSubmit, getUsersData } = props
+  const submit = (values) => { 
+    getUsersData(values);
+  }
     return (
     return (
       <div>
       <div>
-        <Auth />
-        <form className="auth__form" onSubmit={handleSubmit}>
+        <Authbuttons />
+        <form className="auth__form" onSubmit={handleSubmit(submit)}>
           <div>
           <div>
             <Field
             <Field
               name="email"
               name="email"
               component="input"
               component="input"
-              type="email" 
-              placeholder="Email@example.com"
+              type="Емейл" 
+              placeholder="email@example.com"
 
 
             />
             />
           </div>
           </div>
@@ -22,10 +26,10 @@ const Form = props => {
               name="password"
               name="password"
               component="input" 
               component="input" 
               type="password" 
               type="password" 
-              placeholder ="Password"  
+              placeholder ="Пароль"  
             />
             />
           </div>
           </div>
-          <button className="auth__submit-button">Submit</button>
+          <button className="auth__submit-button">Отправить</button>
         </form>
         </form>
       </div>
       </div>
     );
     );

+ 0 - 15
src/components/Auth/index.js

@@ -1,15 +0,0 @@
-import React, {Component} from "react"
-import {Link} from "react-router-dom"
-
-class Auth extends Component {
-  render() {
-    return (
-        <div className="auth__button">
-          <Link to="/auth">Sign in</Link>
-          <Link to="/registration">Join</Link>
-        </div>
-    )
-  }
-}
-
-export default Auth;

+ 18 - 20
src/components/Auth/registration.js

@@ -1,20 +1,27 @@
 import React from 'react'
 import React from 'react'
 import { Field, reduxForm } from 'redux-form'
 import { Field, reduxForm } from 'redux-form'
-import Auth from './index'
+import Authbuttons from './authButtons'
 
 
 const RegistrForm = props => {
 const RegistrForm = props => {
-  const { handleSubmit, pristine, reset, submitting } = props
+  const { handleSubmit, pristine, reset, postUsersData } = props
+  const submit = (values) =>{
+    values.avatar = "https://site.com"
+    values.isAdmin = 1
+    values.description = "gfdfgdgdf"
+    postUsersData(values)
+  
+}
   return (
   return (
     <div>
     <div>
-      <Auth />
-      <form onSubmit={handleSubmit}>
+      <Authbuttons />
+      <form onSubmit={handleSubmit(submit)}>
         <div>
         <div>
           <div>
           <div>
             <Field
             <Field
               name="login"
               name="login"
               component="input"
               component="input"
               type="text"
               type="text"
-              placeholder="Login"
+              placeholder="Логин"
             />
             />
           </div>
           </div>
 
 
@@ -23,16 +30,7 @@ const RegistrForm = props => {
               name="password"
               name="password"
               component="input"
               component="input"
               type="password"
               type="password"
-              placeholder="Password"
-              />
-          </div>
-
-          <div>
-            <Field
-              name="confirmPassword"
-              component="input"
-              type="password"
-              placeholder="Confirm password"
+              placeholder="Пароль"
               />
               />
           </div>
           </div>
 
 
@@ -41,7 +39,7 @@ const RegistrForm = props => {
               name="name"
               name="name"
               component="input"
               component="input"
               type="text"
               type="text"
-              placeholder="Name"
+              placeholder="Имя"
             />
             />
           </div>
           </div>
           <div>
           <div>
@@ -62,11 +60,11 @@ const RegistrForm = props => {
           </div>
           </div>
         </div>
         </div>
         <div>
         <div>
-          <button type="submit" disabled={pristine || submitting}>
-            Submit
+          <button type="submit" disabled={pristine} >
+            Отправить
           </button>
           </button>
-          <button type="button" disabled={pristine || submitting} onClick={reset}>
-            Clear Values
+          <button type="button" disabled={pristine} onClick={reset}>
+            Очистить поля
           </button>
           </button>
         </div>
         </div>
         </form>
         </form>

+ 1 - 1
src/components/Header/searchLine.js

@@ -1,7 +1,7 @@
 import React, { Component } from 'react';
 import React, { Component } from 'react';
 import { Input } from 'antd';
 import { Input } from 'antd';
 const Search = Input.Search;
 const Search = Input.Search;
-const axios = require('axios');
+//const axios = require('axios');
 
 
 //Выводит всех пользователей
 //Выводит всех пользователей
 // axios.get('http://127.0.0.1:2000/api/users')
 // axios.get('http://127.0.0.1:2000/api/users')

+ 7 - 1
src/constants/actionTypes.js

@@ -1 +1,7 @@
-export const GET_DATA = "GET_DATA";
+export const USER_REG_REQUEST = "USER_REG_REQUEST";
+export const USER_REG_REQUEST_SUCCESS = "USER_REG_REQUEST_SUCCESS";
+export const USER_REG_REQUEST_FAIL = "USER_REG_REQUEST_FAIL";
+
+export const USER_AUTH_REQUEST = "USER_AUTH_REQUEST";
+export const USER_AUTH_REQUEST_SUCCESS = "USER_AUTH_REQUEST_SUCCESS";
+export const USER_AUTH_REQUEST_FAIL = "USER_AUTH_REQUEST_FAIL";

+ 27 - 0
src/container/renderAuthorisation.js

@@ -0,0 +1,27 @@
+import React, { Component } from "react";
+import { bindActionCreators } from "redux";
+import { connect} from 'react-redux';
+
+import Form from "../components/Auth/authorisation";
+import * as actions from "../actions/usersAuthActions";
+
+class RenderAuthorisation extends Component {      
+    render() {
+      return (
+        <div>
+          <Form {...this.props} />
+        </div>       
+      );
+    }
+}
+
+
+const mapStateToProps = state => ({
+});
+
+const mapDispatchToProps = dispatch => bindActionCreators({ ...actions }, dispatch);
+
+export default RenderAuthorisation = connect(
+  mapStateToProps,
+  mapDispatchToProps
+)(RenderAuthorisation);

+ 27 - 0
src/container/renderRegistration.js

@@ -0,0 +1,27 @@
+import React, { Component } from "react";
+import { bindActionCreators } from "redux";
+import { connect} from 'react-redux';
+
+import RegistrForm from "../components/Auth/registration";
+import * as actions from "../actions/usersRegistrActions";
+
+class RenderRegistration extends Component {      
+        render() {
+          return (
+            <div>
+              <RegistrForm {...this.props} />
+            </div>       
+          );
+        }
+  }
+  
+
+const mapStateToProps = state => ({
+  });
+  
+const mapDispatchToProps = dispatch => bindActionCreators({ ...actions }, dispatch);
+  
+export default RenderRegistration = connect(
+      mapStateToProps,
+      mapDispatchToProps
+  )(RenderRegistration);

+ 4 - 2
src/reducer/index.js

@@ -1,9 +1,11 @@
 import { combineReducers } from "redux";
 import { combineReducers } from "redux";
 import { reducer as formReducer } from 'redux-form';
 import { reducer as formReducer } from 'redux-form';
 
 
-import users from './users'
+import usersRegistration from './usersRegistration'
+import usersAuthorisation from './usersAuthorisation'
 
 
 export default  combineReducers({
 export default  combineReducers({
-    users: users,
+    usersRegistr: usersRegistration,
+    usersAuth: usersAuthorisation,
     form: formReducer,
     form: formReducer,
 })
 })

+ 0 - 21
src/reducer/users.js

@@ -1,21 +0,0 @@
-import * as types from "../constants/actionTypes";
-
-const initState = {
-    inputData: [],
-    isFetching: false,
-    error: null
-  };
-
-  export default (state = initState, { type, payload }) => {
-    
-      switch (type) {
-        case types.GET_DATA: {
-          return {
-          ...state,
-          inputData: payload
-          }
-        }
-        
-        default: return state;    
-    }
-  };

+ 35 - 0
src/reducer/usersAuthorisation.js

@@ -0,0 +1,35 @@
+import * as types from "../constants/actionTypes";
+
+const initState = {
+    inputData: [],
+    isFetching: false,
+    error: null
+  };
+
+export default (state = initState, {type, payload} ) => {
+    switch(type) {
+        case types.USER_AUTH_REQUEST: {
+            return {
+                ...state,
+                inputData: payload,
+                isFatching: true
+            }
+        }
+        case types.USER_AUTH_REQUEST_SUCCESS: {
+            return {
+                ...state,
+                inputData: payload.data,
+                isFatching: false
+            }
+        }
+        case types.USER_AUTH_REQUEST_FAIL: {
+            return {
+                ...state,
+                isFatching: false,
+                error: "ERROR"
+            }
+        }
+        default: return state;
+
+    }
+};

+ 37 - 0
src/reducer/usersRegistration.js

@@ -0,0 +1,37 @@
+import * as types from "../constants/actionTypes";
+
+const initState = {
+    inputData: [],
+    isFetching: false,
+    error: null
+  };
+
+  export default (state = initState, { type, payload }) => {
+      switch (type) {
+        case types.USER_REG_REQUEST: {
+          return {
+          ...state,
+          inputData: payload,
+          isFetching: true
+          }
+        }
+
+        case types.USER_REG_REQUEST_SUCCESS: {
+          return {
+            ...state,
+            isFetching: false,
+            inputDate: payload.data
+          }
+        }
+
+        case types.USER_REG_REQUEST_FAIL: {
+          return {
+            ...state,
+            isFetching: false,
+            error: "ERROR"
+          }
+        }
+        
+        default: return state;    
+    }
+  };

+ 6 - 7
src/router.js

@@ -1,11 +1,10 @@
-import React, {Fragment} from "react";
+import React from "react";
 import { Switch, Route } from "react-router-dom";
 import { Switch, Route } from "react-router-dom";
 
 
 import App from "./container/App";
 import App from "./container/App";
 import Header from "./components/Header"
 import Header from "./components/Header"
-import Auth from "./components/Auth/index"
-import Form from './components/Auth/authorisation'
-import RegistrForm from "./components/Auth/registration"
+import RenderRegistration from "./container/renderRegistration"
+import RenderAuthorisation from "./container/renderAuthorisation"
 
 
 
 
 export default () => (
 export default () => (
@@ -13,9 +12,9 @@ export default () => (
         <Header/>
         <Header/>
 	        <Switch>
 	        <Switch>
                 <Route path="/" exact component={App} />
                 <Route path="/" exact component={App} />
-                <Route path="/authorisation" exact component={Form} />
-                <Route path="/auth" exact component= {Form}/>
-                <Route path="/registration" exact component={RegistrForm} />
+                <Route path="/authorisation" exact component={RenderAuthorisation} />
+                <Route path="/auth" exact component= {RenderAuthorisation}/>
+                <Route path="/registration" exact component={RenderRegistration} />
 
 
 	        </Switch>
 	        </Switch>
     </div>
     </div>

+ 4 - 4
src/state/state.js

@@ -1,8 +1,8 @@
-import { createStore} from "redux";
-
-//import thunk from "redux-thunk";
+import { createStore, applyMiddleware} from "redux";
+import thunk from "redux-thunk";
 import reducers from "../reducer/";
 import reducers from "../reducer/";
 
 
 export default createStore(
 export default createStore(
-	reducers
+	reducers,
+	applyMiddleware(thunk)
 );
 );

+ 1 - 1
src/utils/validate.js

@@ -1,7 +1,7 @@
 export default values => {
 export default values => {
     const { email, password } = values;
     const { email, password } = values;
     const error = {};
     const error = {};
-    console.log(values)
+
 
 
     if(!email) {
     if(!email) {
         error.email = "Required"
         error.email = "Required"