aboutsummaryrefslogtreecommitdiff
path: root/src/pages/AuthPage/SignUpForm.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-29 23:59:15 +0300
committereug-vs <eug-vs@keemail.me>2020-06-29 23:59:15 +0300
commit1f646377c35b65b97d6eeebb1e88f6d8307e1ef0 (patch)
tree56fbda6b594350656891644734d0bf740bfcbb0d /src/pages/AuthPage/SignUpForm.tsx
parentb301bf24c5037403a1e5fc32fc8c10794941b528 (diff)
downloadwhich-ui-1f646377c35b65b97d6eeebb1e88f6d8307e1ef0.tar.gz
feat!: create useAuth hook
Diffstat (limited to 'src/pages/AuthPage/SignUpForm.tsx')
-rw-r--r--src/pages/AuthPage/SignUpForm.tsx9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx
index 25b79ff..af7a0f8 100644
--- a/src/pages/AuthPage/SignUpForm.tsx
+++ b/src/pages/AuthPage/SignUpForm.tsx
@@ -3,10 +3,8 @@ import { makeStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import { post } from '../../requests';
+import { useAuth } from '../../hooks/useAuth';
-interface PropTypes {
- logIn: (name: string, password: string) => Promise<boolean>;
-}
const useStyles = makeStyles(theme => ({
root: {
@@ -25,12 +23,13 @@ const useStyles = makeStyles(theme => ({
}
}));
-const SignUpForm: React.FC<PropTypes> = ({ logIn }) => {
+const SignUpForm: React.FC = () => {
const [error, setError] = useState<boolean>(false);
const classes = useStyles();
const usernameRef = useRef<HTMLInputElement>();
const emailRef = useRef<HTMLInputElement>();
const passwordRef = useRef<HTMLInputElement>();
+ const { login } = useAuth();
const onClick = () => {
const username = usernameRef.current?.value;
@@ -38,7 +37,7 @@ const SignUpForm: React.FC<PropTypes> = ({ logIn }) => {
const email = emailRef.current?.value;
if (username && password) {
post('/users', { username, password, email }).then(() => {
- logIn(username, password);
+ login(username, password);
});
} else setError(true);
};