aboutsummaryrefslogtreecommitdiff
path: root/src/pages/AuthPage
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-25 21:46:06 +0300
committereug-vs <eug-vs@keemail.me>2020-06-25 21:47:12 +0300
commitcc91abb0ca403b7d7180b0e24fe126bd35ce20ab (patch)
tree662a158be971e0771de2c44db46e1dfe3b2c1e4c /src/pages/AuthPage
parentf24ea161fd2aef6ba75418c965d444ccbfd53fac (diff)
downloadwhich-ui-cc91abb0ca403b7d7180b0e24fe126bd35ce20ab.tar.gz
feat: add rememberMe switch
Diffstat (limited to 'src/pages/AuthPage')
-rw-r--r--src/pages/AuthPage/AuthPage.tsx2
-rw-r--r--src/pages/AuthPage/SignInForm.tsx25
2 files changed, 20 insertions, 7 deletions
diff --git a/src/pages/AuthPage/AuthPage.tsx b/src/pages/AuthPage/AuthPage.tsx
index 0938bce..d2c2eec 100644
--- a/src/pages/AuthPage/AuthPage.tsx
+++ b/src/pages/AuthPage/AuthPage.tsx
@@ -5,7 +5,7 @@ import SignUpForm from './SignUpForm';
interface PropTypes {
- logIn: (name: string, password: string) => Promise<boolean>;
+ logIn: (name: string, password: string, remember?: boolean) => Promise<boolean>;
}
const useStyles = makeStyles({
diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx
index c521abf..1dad153 100644
--- a/src/pages/AuthPage/SignInForm.tsx
+++ b/src/pages/AuthPage/SignInForm.tsx
@@ -1,10 +1,14 @@
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';
+import {
+ TextField,
+ Button,
+ FormControlLabel,
+ Switch
+} from '@material-ui/core';
interface PropTypes {
- logIn: (name: string, password: string) => Promise<boolean>;
+ logIn: (name: string, password: string, remember?: boolean) => Promise<boolean>;
}
const useStyles = makeStyles(theme => ({
@@ -26,15 +30,20 @@ const useStyles = makeStyles(theme => ({
const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
const [error, setError] = useState<boolean>(false);
+ const [remember, setRemember] = useState<boolean>(true);
const classes = useStyles();
const nameRef = useRef<HTMLInputElement>();
const passwordRef = useRef<HTMLInputElement>();
- const onClick = async () => {
+ const handleCheck = () => {
+ setRemember(!remember);
+ };
+
+ const handleSubmit = async () => {
const name = nameRef.current?.value;
const password = passwordRef.current?.value;
if (name && password) {
- logIn(name, password).then(success => {
+ logIn(name, password, remember).then(success => {
if (!success) setError(true);
});
}
@@ -56,7 +65,11 @@ const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
label="Password"
type="password"
/>
- <Button variant="contained" onClick={onClick}>submit</Button>
+ <FormControlLabel
+ control={<Switch color="primary" onClick={handleCheck} checked={remember} size="small" />}
+ label="Remember me"
+ />
+ <Button variant="contained" onClick={handleSubmit}>submit</Button>
</form>
</>
);