From e68d60d60880f4b1e847f7b092210fadfe5d6ab5 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 16 Jun 2020 20:08:01 +0300 Subject: refactor: restructure components --- src/pages/AuthPage/AuthPage.tsx | 39 ++++++++++++++++++++++++++++++++++++--- src/pages/AuthPage/SignInForm.tsx | 21 ++------------------- src/pages/AuthPage/SignUpForm.tsx | 24 +++--------------------- 3 files changed, 41 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/pages/AuthPage/AuthPage.tsx b/src/pages/AuthPage/AuthPage.tsx index 0072686..dc90c01 100644 --- a/src/pages/AuthPage/AuthPage.tsx +++ b/src/pages/AuthPage/AuthPage.tsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { makeStyles } from '@material-ui/core/styles'; import SignInForm from './SignInForm'; import SignUpForm from './SignUpForm'; @@ -7,13 +8,45 @@ interface PropTypes { logIn: (name: string, password: string) => Promise; } +const useStyles = makeStyles({ + formTransfer: { + display: 'flex', + justifyContent: 'center' + }, + transferButton: { + marginLeft: 10, + color: 'green', + cursor: 'pointer' + } +}); + const AuthPage: React.FC = ({ logIn }) => { - const [auth, setAuth] = useState('signIn'); + const [auth, setAuth] = useState<'signIn' | 'signUp'>('signIn'); + const classes = useStyles(); + + const handleRedirect = () => { + setAuth(auth === 'signIn' ? 'signUp' : 'signIn'); + }; + + const footerInfo = { + signIn: ['Don\'t have an account?', 'Sign in'], + signUp: ['Already have an account?', 'Sign up'] + }; return ( <> - {auth === 'signIn' && } - {auth === 'signUp' && } + {auth === 'signIn' && } + {auth === 'signUp' && } +
+
{footerInfo[auth][0]}
+ + {footerInfo[auth][1]} + +
); }; diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx index ae75541..c521abf 100644 --- a/src/pages/AuthPage/SignInForm.tsx +++ b/src/pages/AuthPage/SignInForm.tsx @@ -5,35 +5,26 @@ import Button from '@material-ui/core/Button'; interface PropTypes { logIn: (name: string, password: string) => Promise; - setAuth: (auth: string) => void; } const useStyles = makeStyles(theme => ({ root: { '& > *': { margin: theme.spacing(1), - width: '25ch' + width: theme.spacing(35) }, display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' }, - formTransfer: { - display: 'flex', - justifyContent: 'center' - }, - transferButton: { - marginLeft: 10, - color: 'green' - }, formHeader: { textAlign: 'center', fontSize: 25 } })); -const SignInForm: React.FC = ({ logIn, setAuth }) => { +const SignInForm: React.FC = ({ logIn }) => { const [error, setError] = useState(false); const classes = useStyles(); const nameRef = useRef(); @@ -49,10 +40,6 @@ const SignInForm: React.FC = ({ logIn, setAuth }) => { } }; - const handleSignUp = () => { - setAuth('signUp'); - }; - return ( <>
Sign In
@@ -71,10 +58,6 @@ const SignInForm: React.FC = ({ logIn, setAuth }) => { /> -
-
Don`t have an account?
-
Sign Up
-
); }; diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx index 0013372..2769eb0 100644 --- a/src/pages/AuthPage/SignUpForm.tsx +++ b/src/pages/AuthPage/SignUpForm.tsx @@ -6,44 +6,34 @@ import { post } from '../../requests'; interface PropTypes { logIn: (name: string, password: string) => Promise; - setAuth: (auth: string) => void ; } const useStyles = makeStyles(theme => ({ root: { '& > *': { margin: theme.spacing(1), - width: '25ch' + width: theme.spacing(35) }, display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center' }, - formTransfer: { - display: 'flex', - justifyContent: 'center' - }, - transferButton: { - marginLeft: 10, - color: 'green' - }, formHeader: { textAlign: 'center', fontSize: 25 } })); -const SignUpForm: React.FC = ({ logIn, setAuth }) => { +const SignUpForm: React.FC = ({ logIn }) => { const classes = useStyles(); const inputRef = useRef(); const inputRefPassword = useRef(); - const onClick = () => { const name = inputRef.current?.value; const password = inputRefPassword.current?.value; - const newUser = { name: name, password: password, avatarUrl: '' }; + const newUser = { name, password }; if (name && password) { post('/users', newUser).then(() => { logIn(name, password); @@ -51,10 +41,6 @@ const SignUpForm: React.FC = ({ logIn, setAuth }) => { } }; - const handleSignIn = () => { - setAuth( 'signIn'); - }; - return ( <>
Sign Up
@@ -69,10 +55,6 @@ const SignUpForm: React.FC = ({ logIn, setAuth }) => { /> -
-
Already have an account?
-
Sign In
-
); }; -- cgit v1.2.3