From 5ba6455b2aa6c75c336628bda59e70b46e3b1d6b Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 7 Aug 2020 22:42:50 +0300 Subject: refactor: separate Auth pages --- src/pages/RegistrationPage/RegistrationPage.tsx | 75 +++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/pages/RegistrationPage/RegistrationPage.tsx (limited to 'src/pages/RegistrationPage/RegistrationPage.tsx') diff --git a/src/pages/RegistrationPage/RegistrationPage.tsx b/src/pages/RegistrationPage/RegistrationPage.tsx new file mode 100644 index 0000000..e283a0e --- /dev/null +++ b/src/pages/RegistrationPage/RegistrationPage.tsx @@ -0,0 +1,75 @@ +import React, { useState, useRef } from 'react'; +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'; + + +const useStyles = makeStyles(theme => ({ + root: { + '& > *': { + margin: theme.spacing(1), + width: theme.spacing(35) + }, + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + textAlign: 'center' + }, + formHeader: { + textAlign: 'center', + fontSize: 25 + } +})); + +const RegistrationPage: React.FC = () => { + const [error, setError] = useState(false); + const classes = useStyles(); + const usernameRef = useRef(); + const emailRef = useRef(); + const passwordRef = useRef(); + 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)) + .then(() => navigate('profile')); + } else setError(true); + }; + + // TODO: add login redirect + + return ( + <> +
Sign Up
+
+ + + + + + + ); +}; + +export default RegistrationPage; -- cgit v1.2.3