aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-16 20:08:01 +0300
committereug-vs <eug-vs@keemail.me>2020-06-16 20:08:01 +0300
commite68d60d60880f4b1e847f7b092210fadfe5d6ab5 (patch)
tree4fd41991c1e9fbc513a140aae0d2dbeb0a6f5ee9 /src
parent171af45318b3c27c232fc7d1aee99976dfb3046e (diff)
downloadwhich-ui-e68d60d60880f4b1e847f7b092210fadfe5d6ab5.tar.gz
refactor: restructure components
Diffstat (limited to 'src')
-rw-r--r--src/pages/AuthPage/AuthPage.tsx39
-rw-r--r--src/pages/AuthPage/SignInForm.tsx21
-rw-r--r--src/pages/AuthPage/SignUpForm.tsx24
3 files changed, 41 insertions, 43 deletions
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<boolean>;
}
+const useStyles = makeStyles({
+ formTransfer: {
+ display: 'flex',
+ justifyContent: 'center'
+ },
+ transferButton: {
+ marginLeft: 10,
+ color: 'green',
+ cursor: 'pointer'
+ }
+});
+
const AuthPage: React.FC<PropTypes> = ({ logIn }) => {
- const [auth, setAuth] = useState<String>('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' && <SignInForm logIn={logIn} setAuth={setAuth} />}
- {auth === 'signUp' && <SignUpForm logIn={logIn} setAuth={setAuth} />}
+ {auth === 'signIn' && <SignInForm logIn={logIn} />}
+ {auth === 'signUp' && <SignUpForm logIn={logIn} />}
+ <div className={classes.formTransfer}>
+ <div>{footerInfo[auth][0]}</div>
+ <span
+ onClick={handleRedirect}
+ className={classes.transferButton}
+ role="presentation"
+ >
+ {footerInfo[auth][1]}
+ </span>
+ </div>
</>
);
};
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<boolean>;
- 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<PropTypes> = ({ logIn, setAuth }) => {
+const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
const [error, setError] = useState<boolean>(false);
const classes = useStyles();
const nameRef = useRef<HTMLInputElement>();
@@ -49,10 +40,6 @@ const SignInForm: React.FC<PropTypes> = ({ logIn, setAuth }) => {
}
};
- const handleSignUp = () => {
- setAuth('signUp');
- };
-
return (
<>
<div className={classes.formHeader}>Sign In</div>
@@ -71,10 +58,6 @@ const SignInForm: React.FC<PropTypes> = ({ logIn, setAuth }) => {
/>
<Button variant="contained" onClick={onClick}>submit</Button>
</form>
- <div className={classes.formTransfer}>
- <div>Don`t have an account?</div>
- <div onClick={handleSignUp} className={classes.transferButton}>Sign Up</div>
- </div>
</>
);
};
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<boolean>;
- 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<PropTypes> = ({ logIn, setAuth }) => {
+const SignUpForm: React.FC<PropTypes> = ({ logIn }) => {
const classes = useStyles();
const inputRef = useRef<HTMLInputElement>();
const inputRefPassword = useRef<HTMLInputElement>();
-
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<PropTypes> = ({ logIn, setAuth }) => {
}
};
- const handleSignIn = () => {
- setAuth( 'signIn');
- };
-
return (
<>
<div className={classes.formHeader}>Sign Up</div>
@@ -69,10 +55,6 @@ const SignUpForm: React.FC<PropTypes> = ({ logIn, setAuth }) => {
/>
<Button variant="contained" onClick={onClick}>submit</Button>
</form>
- <div className={classes.formTransfer}>
- <div>Already have an account?</div>
- <div className={classes.transferButton} onClick={handleSignIn}>Sign In</div>
- </div>
</>
);
};