|
@@ -36,31 +36,28 @@ const Auth = () => {
|
|
|
const dispatch = useDispatch();
|
|
|
const history = useHistory();
|
|
|
|
|
|
- const [auth, setAuth] = useState(true);
|
|
|
const { formArray, updateEvent, valid, disabled, submitEvent, setValueManually } = hookForm({ initialForm: form })
|
|
|
- console.log('formArray', formArray);
|
|
|
+
|
|
|
const user = useSelector((s) => s.auth.user);
|
|
|
- const emailFromRegister = useSelector((s) => s.auth.emailFromRegister);
|
|
|
+ const registeredUser = useSelector((s) => s.auth.registeredUser);
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (user) history.push('/');
|
|
|
}, [user, history]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (emailFromRegister) {
|
|
|
- setValueManually('password', '');
|
|
|
- setAuth(true);
|
|
|
+ if (registeredUser) {
|
|
|
+ setValueManually('email', registeredUser.email)
|
|
|
}
|
|
|
- }, [emailFromRegister, setValueManually])
|
|
|
+ }, [registeredUser, setValueManually]);
|
|
|
|
|
|
const submit = submitEvent((v) => {
|
|
|
- if (auth) dispatch(runAuth(v))
|
|
|
- else dispatch(runRegister(v))
|
|
|
+ dispatch(runAuth(v))
|
|
|
});
|
|
|
|
|
|
return (
|
|
|
<div className={classes.container}>
|
|
|
- <form onSubmit={submit} className={classes.form}>
|
|
|
+ <form action="/adfsgfb" className={classes.form}>
|
|
|
{formArray.map(el => (
|
|
|
<div className={classes.form} key={el.name}>
|
|
|
<Input
|
|
@@ -73,8 +70,6 @@ const Auth = () => {
|
|
|
))}
|
|
|
<button type="submit" disabled={disabled || !valid}>Submit</button>
|
|
|
</form>
|
|
|
-
|
|
|
- <p className={classes.text} onClick={() => setAuth(p => !p)}>{auth ? 'Do you have a account ?' : 'Log In'}</p>
|
|
|
</div>
|
|
|
)
|
|
|
}
|