From 181d40fab14c9170a7bbd9fe1782db727f5b19d6 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Tue, 16 Jun 2020 15:14:40 +0300 Subject: add form transfer to signIn and signUp --- src/pages/AuthPage/AuthPage.tsx | 27 +++--------- src/pages/AuthPage/Registration.tsx | 60 -------------------------- src/pages/AuthPage/SignInForm.tsx | 60 ++++++++++++++++++-------- src/pages/AuthPage/SignUpForm.tsx | 84 +++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 99 deletions(-) delete mode 100644 src/pages/AuthPage/Registration.tsx create mode 100644 src/pages/AuthPage/SignUpForm.tsx 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; @@ -19,28 +19,13 @@ const useStyles = makeStyles(theme => ({ const AuthPage: React.FC = ({logIn}) => { const classes = useStyles(); - const[authorization,setAuthorization] = useState({authorize: 'signUp'}); - - const handleSignUp = () => { - setAuthorization({authorize: 'signUp'}); - console.log(authorization.authorize); - }; - - const handleRegistration = () => { - setAuthorization({authorize: 'registration'}); - console.log(authorization.authorize); - }; + const [authorization, setAuthorization] = useState({authorize: 'signIn'}); return ( <> -
-
SignUp
-
or
-
Registrate
-
- { authorization.authorize === 'signUp' && } - { authorization.authorize === 'registration' && } - + {authorization.authorize === 'signIn' && } + {authorization.authorize === 'signUp' && } + ); }; diff --git a/src/pages/AuthPage/Registration.tsx b/src/pages/AuthPage/Registration.tsx deleted file mode 100644 index 1884a8a..0000000 --- a/src/pages/AuthPage/Registration.tsx +++ /dev/null @@ -1,60 +0,0 @@ -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 {get, post} from '../../requests'; - -interface PropTypes { - logIn: (name: string, password: string) => Promise; -} - -const useStyles = makeStyles(theme => ({ - root: { - '& > *': { - margin: theme.spacing(1), - width: '25ch' - }, - display: 'flex', - flexDirection: 'column', - alignItems: 'center', - textAlign: 'center' - } -})); - -const Registration: 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: '', - }; - if (name && password) { - post(`/users`,newUser).then(response => { - logIn(name, password); - }); - } - }; - - return ( -
- - - - - - ); -}; - -export default Registration; 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; + 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 = ({ logIn }) => { +const SignInForm: React.FC = ({logIn, setAuthorization}) => { const [error, setError] = useState(false); const classes = useStyles(); const nameRef = useRef(); @@ -36,22 +49,33 @@ const SignInForm: React.FC = ({ logIn }) => { } }; + const handleSignUp = () => { + setAuthorization({authorize: 'signUp'}); + }; + return ( -
- - - - + <> +
Sign In
+
+ + + + +
+
Don't have an account?
+
Sign Up
+
+ ); }; diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx new file mode 100644 index 0000000..29f17b1 --- /dev/null +++ b/src/pages/AuthPage/SignUpForm.tsx @@ -0,0 +1,84 @@ +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 {Authorization} from '../../types'; +import {get, post} from '../../requests'; + +interface PropTypes { + logIn: (name: string, password: string) => Promise; + setAuthorization: (authorization: { authorize: string }) => void ; +} + +const useStyles = makeStyles(theme => ({ + root: { + '& > *': { + margin: theme.spacing(1), + width: '25ch' + }, + 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,setAuthorization}) => { + 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: '', + }; + if (name && password) { + post(`/users`,newUser).then(response => { + logIn(name, password); + }); + } + }; + + const handleSignIn = () => { + setAuthorization({authorize: 'signIn'}); + }; + + return ( + <> +
Sign Up
+
+ + + + + +
+
Already have an account?
+
Sign In
+
+ + ); +}; + +export default SignUpForm; -- cgit v1.2.3