|
@@ -1,4 +1,5 @@
|
|
|
import './style.css';
|
|
|
+import { userConstants } from '../../constants/users';
|
|
|
import React from 'react';
|
|
|
import {connect} from 'react-redux';
|
|
|
import {authApi, usersApi} from '../../api';
|
|
@@ -8,14 +9,15 @@ import withAuthWrapper from '../../components/withAuthWrapper';
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
return {
|
|
|
- loginDispatch: token => dispatch({type: 'LOGIN', payload: token}),
|
|
|
- initDispatch: currentUser => dispatch({type: 'INIT', payload: currentUser}),
|
|
|
+ loginDispatch: token => dispatch({type: userConstants.LOGIN_REQUEST, payload: token}),
|
|
|
+ initDispatch: currentUser => dispatch({type: userConstants.INIT, payload: currentUser}),
|
|
|
+
|
|
|
startLoader: () => dispatch({type: 'LOADER_START'}),
|
|
|
stopLoader: () => dispatch({type: 'LOADER_STOP'}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const Login = ({loginDispatch, initDispatch, startLoader, stopLoader, history}) => {
|
|
|
+const Login = ({loginDispatch, initDispatch, startLoader, failLogin, stopLoader, history}) => {
|
|
|
const handleSubmit = async (e) => {
|
|
|
startLoader()
|
|
|
e.preventDefault();
|
|
@@ -32,12 +34,9 @@ const Login = ({loginDispatch, initDispatch, startLoader, stopLoader, history})
|
|
|
initDispatch(currentUser)
|
|
|
|
|
|
} catch(err) {
|
|
|
-
|
|
|
- console.log(err)
|
|
|
- return (
|
|
|
|
|
|
- <div> You are {err}. Go to <Link to='auth/registration'>Sign Up</Link></div>
|
|
|
- )
|
|
|
+ alert(`Oops, something went wrong!!! ${err.response.data} . `)
|
|
|
+ console.log(err.response.data)
|
|
|
|
|
|
} finally {
|
|
|
stopLoader()
|