|
@@ -3,23 +3,29 @@ import { connect } from 'react-redux';
|
|
|
import { NavLink, useHistory } from 'react-router-dom';
|
|
|
import { actionLogin } from '../../Actions/action_login';
|
|
|
import LoginError from '../../Components/LoginError/LoginError';
|
|
|
-// import history from "../../history";
|
|
|
import './Login.css';
|
|
|
|
|
|
-const Login = ({onLogin=null, checkLogin=false}) => { //деструктуризация объекта
|
|
|
+const Login = ({ onLogin = null, checkLogin = false, promiseLoginStatus, payloadLogin, loginNetworkError }) => { //деструктуризация объекта
|
|
|
|
|
|
let history = useHistory();
|
|
|
|
|
|
- if(localStorage.authToken) {
|
|
|
+ if (checkLogin) {
|
|
|
history.push('/profile')
|
|
|
}
|
|
|
|
|
|
- useEffect(()=>{
|
|
|
- if(checkLogin) {
|
|
|
- history.push('/profile')
|
|
|
- }
|
|
|
- }, [checkLogin])
|
|
|
-
|
|
|
+ if (localStorage.authToken) {
|
|
|
+ history.push('/profile')
|
|
|
+ }
|
|
|
+ if(loginNetworkError) {
|
|
|
+ history.push('/404')
|
|
|
+ }
|
|
|
+
|
|
|
+ // useEffect(()=>{
|
|
|
+ // if(checkLogin) {
|
|
|
+ // history.push('/profile')
|
|
|
+ // }
|
|
|
+ // }, [checkLogin])
|
|
|
+
|
|
|
const loginRef = useRef(null)
|
|
|
const pasRef = useRef(null)
|
|
|
|
|
@@ -28,7 +34,7 @@ const Login = ({onLogin=null, checkLogin=false}) => { //деструкту
|
|
|
|
|
|
return (
|
|
|
<div className='login-wrapper'>
|
|
|
- <input value={login} placeholder="Login" ref={loginRef} onChange={(e) => setLogin(e.target.value)}></input>
|
|
|
+ <input value={login} placeholder="Login" ref={loginRef} onChange={(e) => setLogin(e.target.value)}></input>
|
|
|
{/* зачем нужен value? */}
|
|
|
{/* <input placeholder="Login" ref={loginRef} onChange={(e) => setLogin(e.target.value)}></input> */}
|
|
|
<input value={password} placeholder="Password" ref={pasRef} onChange={(e) => setPassword(e.target.value)} type="password"></input>
|
|
@@ -39,11 +45,16 @@ const Login = ({onLogin=null, checkLogin=false}) => { //деструкту
|
|
|
<NavLink to="/registration" >Registration</NavLink>
|
|
|
</nav>
|
|
|
|
|
|
- <LoginError />
|
|
|
+ {promiseLoginStatus ==='RESOLVED' && payloadLogin === null && <LoginError />}
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-const CLogin = connect((state) => ({checkLogin: state.auth.isLogin}), {onLogin: actionLogin})(Login)
|
|
|
+const CLogin = connect((state) => ({
|
|
|
+ checkLogin: state.auth.isLogin,
|
|
|
+ promiseLoginStatus: state?.promise?.Login?.status,
|
|
|
+ payloadLogin: state?.promise?.Login?.payload?.data?.login,
|
|
|
+ loginNetworkError: state?.networkError?.loginNetworkError
|
|
|
+}), { onLogin: actionLogin })(Login)
|
|
|
|
|
|
export default CLogin;
|