|
@@ -1,5 +1,7 @@
|
|
|
+import { useEffect } from 'react';
|
|
|
import hookForm from 'hook-easy-form';
|
|
|
-import { useDispatch } from 'react-redux';
|
|
|
+import { useHistory } from 'react-router-dom';
|
|
|
+import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
|
|
import { runAuth } from 'store/auth/actions';
|
|
|
import Input from 'components/inputs/text-input/text-input';
|
|
@@ -32,26 +34,33 @@ const form = [
|
|
|
|
|
|
const Auth = () => {
|
|
|
const dispatch = useDispatch();
|
|
|
+ const history = useHistory();
|
|
|
+
|
|
|
+ const user = useSelector((s) => s.auth.user)
|
|
|
+ console.log('user', user);
|
|
|
+ useEffect(() => {
|
|
|
+ if (user) history.push('/');
|
|
|
+ }, [user, history]);
|
|
|
|
|
|
- // const [values, setValues] = useState({ email: '', password: '' })
|
|
|
const { formArray, updateEvent, valid, disabled, submitEvent } = hookForm({ initialForm: form })
|
|
|
|
|
|
const submit = submitEvent((v) => dispatch(runAuth(v)));
|
|
|
|
|
|
- // console.log('s', formArray);
|
|
|
return (
|
|
|
- <form onSubmit={submit} className={classes.container}>
|
|
|
- {formArray.map(el => (
|
|
|
- <div className={classes.form} key={el.name}>
|
|
|
- <Input
|
|
|
- name={el.name}
|
|
|
- label={el.options.label}
|
|
|
- type={el.options.type}
|
|
|
- onChange={updateEvent} />
|
|
|
- </div>
|
|
|
- ))}
|
|
|
- <button type="submit" disabled={disabled || !valid}>Submit</button>
|
|
|
- </form>
|
|
|
+ <div className={classes.container}>
|
|
|
+ <form onSubmit={submit} className={classes.form}>
|
|
|
+ {formArray.map(el => (
|
|
|
+ <div className={classes.form} key={el.name}>
|
|
|
+ <Input
|
|
|
+ name={el.name}
|
|
|
+ label={el.options.label}
|
|
|
+ type={el.options.type}
|
|
|
+ onChange={updateEvent} />
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+ <button type="submit" disabled={disabled || !valid}>Submit</button>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
)
|
|
|
}
|
|
|
|