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/LoginPage/LoginPage.tsx | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/pages/LoginPage/LoginPage.tsx (limited to 'src/pages/LoginPage') diff --git a/src/pages/LoginPage/LoginPage.tsx b/src/pages/LoginPage/LoginPage.tsx new file mode 100644 index 0000000..ef31491 --- /dev/null +++ b/src/pages/LoginPage/LoginPage.tsx @@ -0,0 +1,82 @@ +import React, { useState, useRef } from 'react'; +import { makeStyles } from '@material-ui/core/styles'; +import { + TextField, + Button, + FormControlLabel, + Switch +} from '@material-ui/core'; +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 LoginPage: React.FC = () => { + const [error, setError] = useState(false); + const [remember, setRemember] = useState(true); + const classes = useStyles(); + const nameRef = useRef(); + const passwordRef = useRef(); + const { login } = useAuth(); + const { navigate } = useNavigate(); + + const handleCheck = () => { + setRemember(!remember); + }; + + const handleSubmit = async () => { + const name = nameRef.current?.value; + const password = passwordRef.current?.value; + if (name && password) { + login(name, password, remember).then(success => { + if (success) navigate('profile'); + else setError(true); + }); + } + }; + + // TODO: Add registration redirect + + return ( + <> +
Sign In
+
+ + + } + label="Remember me" + /> + + + + ); +}; + +export default LoginPage; + -- cgit v1.2.3 From 6a0b6ec911c39989a1af4322e2a32d75fddbb274 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 8 Aug 2020 09:42:16 +0300 Subject: feat: complete router navigation --- src/pages/LoginPage/LoginPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pages/LoginPage') diff --git a/src/pages/LoginPage/LoginPage.tsx b/src/pages/LoginPage/LoginPage.tsx index ef31491..367ed6b 100644 --- a/src/pages/LoginPage/LoginPage.tsx +++ b/src/pages/LoginPage/LoginPage.tsx @@ -1,4 +1,5 @@ import React, { useState, useRef } from 'react'; +import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { TextField, @@ -7,7 +8,6 @@ import { Switch } from '@material-ui/core'; import { useAuth } from '../../hooks/useAuth'; -import { useNavigate } from '../../hooks/useNavigate'; const useStyles = makeStyles(theme => ({ root: { @@ -33,7 +33,7 @@ const LoginPage: React.FC = () => { const nameRef = useRef(); const passwordRef = useRef(); const { login } = useAuth(); - const { navigate } = useNavigate(); + const history = useHistory(); const handleCheck = () => { setRemember(!remember); @@ -44,7 +44,7 @@ const LoginPage: React.FC = () => { const password = passwordRef.current?.value; if (name && password) { login(name, password, remember).then(success => { - if (success) navigate('profile'); + if (success) history.push(`/profile/${login}`); else setError(true); }); } -- cgit v1.2.3 From f55374d5328f672dbce47e8d452ce17d02ced9f8 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 8 Aug 2020 11:13:00 +0300 Subject: feat: add redirect tips to auth pages --- src/pages/LoginPage/LoginPage.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/pages/LoginPage') diff --git a/src/pages/LoginPage/LoginPage.tsx b/src/pages/LoginPage/LoginPage.tsx index 367ed6b..2bc7e5a 100644 --- a/src/pages/LoginPage/LoginPage.tsx +++ b/src/pages/LoginPage/LoginPage.tsx @@ -23,6 +23,15 @@ const useStyles = makeStyles(theme => ({ formHeader: { textAlign: 'center', fontSize: 25 + }, + formTransfer: { + display: 'flex', + justifyContent: 'center' + }, + transferButton: { + marginLeft: 10, + color: 'green', + cursor: 'pointer' } })); @@ -50,7 +59,9 @@ const LoginPage: React.FC = () => { } }; - // TODO: Add registration redirect + const handleRegistration = () => { + history.push('/registration'); + }; return ( <> @@ -74,6 +85,16 @@ const LoginPage: React.FC = () => { /> +
+
{'Don\'t have an account?'}
+ + Sign up + +
); }; -- cgit v1.2.3 From f0a53feb38c5bbec8a94bbf4440a1ce184876013 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 8 Aug 2020 11:23:13 +0300 Subject: feat: lowercase all username inputs --- src/pages/LoginPage/LoginPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pages/LoginPage') diff --git a/src/pages/LoginPage/LoginPage.tsx b/src/pages/LoginPage/LoginPage.tsx index 2bc7e5a..335cbb1 100644 --- a/src/pages/LoginPage/LoginPage.tsx +++ b/src/pages/LoginPage/LoginPage.tsx @@ -49,11 +49,11 @@ const LoginPage: React.FC = () => { }; const handleSubmit = async () => { - const name = nameRef.current?.value; + const name = nameRef.current?.value?.toLowerCase(); const password = passwordRef.current?.value; if (name && password) { login(name, password, remember).then(success => { - if (success) history.push(`/profile/${login}`); + if (success) history.push(`/profile/${name}`); else setError(true); }); } -- cgit v1.2.3