aboutsummaryrefslogtreecommitdiff
path: root/src/pages/AuthPage/SignInForm.tsx
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-06-30 01:47:27 +0300
committerGitHub <noreply@github.com>2020-06-30 01:47:27 +0300
commit720a32c4cb1697f3a8f90973f28c334551ab87ff (patch)
treec9028ea3ff850774d33cbc510eb19dd0e9f7aade /src/pages/AuthPage/SignInForm.tsx
parentb301bf24c5037403a1e5fc32fc8c10794941b528 (diff)
parente170d04d5d2c8c86d2683f3accb4feb2d94c881a (diff)
downloadwhich-ui-720a32c4cb1697f3a8f90973f28c334551ab87ff.tar.gz
Merge pull request #54 from which-ecosystem/hooks
Use hooks logic
Diffstat (limited to 'src/pages/AuthPage/SignInForm.tsx')
-rw-r--r--src/pages/AuthPage/SignInForm.tsx15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx
index 1dad153..e68483b 100644
--- a/src/pages/AuthPage/SignInForm.tsx
+++ b/src/pages/AuthPage/SignInForm.tsx
@@ -6,10 +6,8 @@ import {
FormControlLabel,
Switch
} from '@material-ui/core';
-
-interface PropTypes {
- logIn: (name: string, password: string, remember?: boolean) => Promise<boolean>;
-}
+import { useAuth } from '../../hooks/useAuth';
+import { useNavigate } from '../../hooks/useNavigate';
const useStyles = makeStyles(theme => ({
root: {
@@ -28,12 +26,14 @@ const useStyles = makeStyles(theme => ({
}
}));
-const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
+const SignInForm: React.FC = () => {
const [error, setError] = useState<boolean>(false);
const [remember, setRemember] = useState<boolean>(true);
const classes = useStyles();
const nameRef = useRef<HTMLInputElement>();
const passwordRef = useRef<HTMLInputElement>();
+ const { login } = useAuth();
+ const { navigate } = useNavigate();
const handleCheck = () => {
setRemember(!remember);
@@ -43,8 +43,9 @@ const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
const name = nameRef.current?.value;
const password = passwordRef.current?.value;
if (name && password) {
- logIn(name, password, remember).then(success => {
- if (!success) setError(true);
+ login(name, password, remember).then(success => {
+ if (success) navigate('profile');
+ else setError(true);
});
}
};