diff options
-rw-r--r-- | src/pages/AuthPage/AuthPage.tsx | 27 | ||||
-rw-r--r-- | src/pages/AuthPage/SignInForm.tsx | 60 | ||||
-rw-r--r-- | src/pages/AuthPage/SignUpForm.tsx (renamed from src/pages/AuthPage/Registration.tsx) | 32 |
3 files changed, 76 insertions, 43 deletions
diff --git a/src/pages/AuthPage/AuthPage.tsx b/src/pages/AuthPage/AuthPage.tsx index 9b8040c..c490078 100644 --- a/src/pages/AuthPage/AuthPage.tsx +++ b/src/pages/AuthPage/AuthPage.tsx @@ -1,8 +1,8 @@ import React, {useState} from 'react'; -import { Authorization} from '../../types'; +import {Authorization} from '../../types'; import SignInForm from './SignInForm'; import {makeStyles} from "@material-ui/core"; -import Registration from "./Registration"; +import SignUpForm from "./SignUpForm"; interface PropTypes { logIn: (name: string, password: string) => Promise<boolean>; @@ -19,28 +19,13 @@ const useStyles = makeStyles(theme => ({ const AuthPage: React.FC<PropTypes> = ({logIn}) => { const classes = useStyles(); - const[authorization,setAuthorization] = useState<Authorization>({authorize: 'signUp'}); - - const handleSignUp = () => { - setAuthorization({authorize: 'signUp'}); - console.log(authorization.authorize); - }; - - const handleRegistration = () => { - setAuthorization({authorize: 'registration'}); - console.log(authorization.authorize); - }; + const [authorization, setAuthorization] = useState<Authorization>({authorize: 'signIn'}); return ( <> - <div className={classes.authorize}> - <div onClick={handleSignUp}>SignUp</div> - <div>or</div> - <div onClick={handleRegistration}>Registrate</div> - </div> - { authorization.authorize === 'signUp' && <SignInForm logIn={logIn} /> } - { authorization.authorize === 'registration' && <Registration logIn={logIn} /> } - </> + {authorization.authorize === 'signIn' && <SignInForm logIn={logIn} setAuthorization={setAuthorization}/>} + {authorization.authorize === 'signUp' && <SignUpForm logIn={logIn} setAuthorization={setAuthorization} />} + </> ); }; diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx index e2ae8b7..f4f763c 100644 --- a/src/pages/AuthPage/SignInForm.tsx +++ b/src/pages/AuthPage/SignInForm.tsx @@ -1,10 +1,11 @@ -import React, { useState, useRef } from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +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'; interface PropTypes { logIn: (name: string, password: string) => Promise<boolean>; + setAuthorization: (authorization: { authorize: string }) => void ; } const useStyles = makeStyles(theme => ({ @@ -17,10 +18,22 @@ const useStyles = makeStyles(theme => ({ 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 }) => { +const SignInForm: React.FC<PropTypes> = ({logIn, setAuthorization}) => { const [error, setError] = useState<boolean>(false); const classes = useStyles(); const nameRef = useRef<HTMLInputElement>(); @@ -36,22 +49,33 @@ const SignInForm: React.FC<PropTypes> = ({ logIn }) => { } }; + const handleSignUp = () => { + setAuthorization({authorize: 'signUp'}); + }; + return ( - <form className={classes.root} noValidate autoComplete="off"> - <TextField - inputRef={nameRef} - error={error} - label="Login" - /> - <TextField - inputRef={passwordRef} - error={error} - helperText={error && 'Invalid credentials'} - label="Password" - type="password" - /> - <Button variant="contained" onClick={onClick}>submit</Button> - </form> + <> + <div className={classes.formHeader}>Sign In</div> + <form className={classes.root} noValidate autoComplete="off"> + <TextField + inputRef={nameRef} + error={error} + label="Login" + /> + <TextField + inputRef={passwordRef} + error={error} + helperText={error && 'Invalid credentials'} + label="Password" + type="password" + /> + <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/Registration.tsx b/src/pages/AuthPage/SignUpForm.tsx index 1884a8a..29f17b1 100644 --- a/src/pages/AuthPage/Registration.tsx +++ b/src/pages/AuthPage/SignUpForm.tsx @@ -2,11 +2,12 @@ import React, {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 {User} from '../../types'; +import {Authorization} from '../../types'; import {get, post} from '../../requests'; interface PropTypes { logIn: (name: string, password: string) => Promise<boolean>; + setAuthorization: (authorization: { authorize: string }) => void ; } const useStyles = makeStyles(theme => ({ @@ -19,10 +20,22 @@ const useStyles = makeStyles(theme => ({ flexDirection: 'column', alignItems: 'center', textAlign: 'center' + }, + formTransfer: { + display: 'flex', + justifyContent: 'center' + }, + transferButton: { + marginLeft: 10, + color: 'green' + }, + formHeader: { + textAlign: 'center', + fontSize: 25 } })); -const Registration: React.FC<PropTypes> = ({logIn}) => { +const SignUpForm: React.FC<PropTypes> = ({logIn,setAuthorization}) => { const classes = useStyles(); const inputRef = useRef<HTMLInputElement>(); const inputRefPassword = useRef<HTMLInputElement>(); @@ -43,8 +56,14 @@ const Registration: React.FC<PropTypes> = ({logIn}) => { } }; + const handleSignIn = () => { + setAuthorization({authorize: 'signIn'}); + }; + return ( - <form className={classes.root} noValidate autoComplete="off"> + <> + <div className={classes.formHeader}>Sign Up</div> + <form className={classes.root} noValidate autoComplete="off"> <TextField inputRef={inputRef} id="standard-basic" label="Name"/> <TextField id="standard-basic" label="Email"/> <TextField inputRef={inputRefPassword} @@ -54,7 +73,12 @@ const Registration: React.FC<PropTypes> = ({logIn}) => { /> <Button variant="contained" onClick={onClick}>submit</Button> </form> + <div className={classes.formTransfer}> + <div>Already have an account?</div> + <div onClick={handleSignIn} className={classes.transferButton}>Sign In</div> + </div> + </> ); }; -export default Registration; +export default SignUpForm; |