diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-06-30 01:47:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 01:47:27 +0300 |
commit | 720a32c4cb1697f3a8f90973f28c334551ab87ff (patch) | |
tree | c9028ea3ff850774d33cbc510eb19dd0e9f7aade /src/pages/AuthPage/SignUpForm.tsx | |
parent | b301bf24c5037403a1e5fc32fc8c10794941b528 (diff) | |
parent | e170d04d5d2c8c86d2683f3accb4feb2d94c881a (diff) | |
download | which-ui-720a32c4cb1697f3a8f90973f28c334551ab87ff.tar.gz |
Merge pull request #54 from which-ecosystem/hooks
Use hooks logic
Diffstat (limited to 'src/pages/AuthPage/SignUpForm.tsx')
-rw-r--r-- | src/pages/AuthPage/SignUpForm.tsx | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx index 25b79ff..1dacd45 100644 --- a/src/pages/AuthPage/SignUpForm.tsx +++ b/src/pages/AuthPage/SignUpForm.tsx @@ -3,10 +3,9 @@ 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'; +import { useNavigate } from '../../hooks/useNavigate'; -interface PropTypes { - logIn: (name: string, password: string) => Promise<boolean>; -} const useStyles = makeStyles(theme => ({ root: { @@ -25,21 +24,23 @@ 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 { navigate } = useNavigate(); const onClick = () => { const username = usernameRef.current?.value; const password = passwordRef.current?.value; const email = emailRef.current?.value; if (username && password) { - post('/users', { username, password, email }).then(() => { - logIn(username, password); - }); + post('/users', { username, password, email }) + .then(() => login(username, password)) + .then(() => navigate('profile')); } else setError(true); }; |