aboutsummaryrefslogtreecommitdiff
path: root/src/Form
diff options
context:
space:
mode:
authorilyayudovin <ilyayudovin123@gmail.com>2020-06-14 01:31:05 +0300
committerilyayudovin <ilyayudovin123@gmail.com>2020-06-14 01:31:05 +0300
commit3969face39ecc933b1cb9c7625be921d148552cb (patch)
tree6c1ebc773767bf0637ae6b568997033479d0e597 /src/Form
parent57a2ff3cfa7eae111bb8f46447198586c47425fb (diff)
downloadwhich-ui-3969face39ecc933b1cb9c7625be921d148552cb.tar.gz
feat: add sing in form
Diffstat (limited to 'src/Form')
-rw-r--r--src/Form/SignInForm.tsx59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Form/SignInForm.tsx b/src/Form/SignInForm.tsx
new file mode 100644
index 0000000..07e8f02
--- /dev/null
+++ b/src/Form/SignInForm.tsx
@@ -0,0 +1,59 @@
+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 } from '../requests';
+
+interface PropTypes {
+ setUser: (newUser: User) => void;
+}
+
+const useStyles = makeStyles(theme => ({
+ root: {
+ '& > *': {
+ margin: theme.spacing(1),
+ width: '25ch'
+ },
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ textAlign: 'center'
+ }
+}));
+
+const SignInForm: React.FC<PropTypes> = ({ setUser }) => {
+ const classes = useStyles();
+ const inputRef = useRef<any>();
+
+ const getUserProfile = name => {
+ get(`/users?name=${name}`).then(response => {
+ setUser(response.data[0]);
+ });
+ };
+
+ const onClick = () => {
+ const value = inputRef.current.value;
+ localStorage.setItem('user', value);
+ getUserProfile(value);
+ };
+
+ if (localStorage.getItem('user') !== null) {
+ getUserProfile(localStorage.getItem('user'));
+ }
+
+ return (
+ <form className={classes.root} noValidate autoComplete="off">
+ <h1>Sign In</h1>
+ <TextField inputRef={inputRef} id="standard-basic" label="Login" />
+ <TextField
+ id="standard-password-input"
+ label="Password"
+ type="password"
+ />
+ <Button variant="contained" onClick={onClick}>submit</Button>
+ </form>
+ );
+};
+
+export default SignInForm;