aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/PollCard/PollCard.tsx4
-rw-r--r--src/pages/AuthPage/AuthPage.tsx46
-rw-r--r--src/pages/AuthPage/SignInForm.tsx40
-rw-r--r--src/pages/AuthPage/SignUpForm.tsx62
-rw-r--r--src/pages/ProfilePage/ProfileInfo.tsx7
-rw-r--r--src/types.d.ts1
6 files changed, 138 insertions, 22 deletions
diff --git a/src/components/PollCard/PollCard.tsx b/src/components/PollCard/PollCard.tsx
index 23dc342..baf896f 100644
--- a/src/components/PollCard/PollCard.tsx
+++ b/src/components/PollCard/PollCard.tsx
@@ -27,6 +27,9 @@ const useStyles = makeStyles(theme => ({
},
imagesBlock: {
display: 'flex'
+ },
+ avatar: {
+ cursor: 'pointer'
}
}));
@@ -51,6 +54,7 @@ const PollCard: React.FC<PropTypes> = ({ poll, navigate }) => {
src={author.avatarUrl}
alt={author.name[0].toUpperCase()}
onClick={handleNavigate}
+ className={classes.avatar}
/>
)}
title={author.name}
diff --git a/src/pages/AuthPage/AuthPage.tsx b/src/pages/AuthPage/AuthPage.tsx
index 72733f0..dc90c01 100644
--- a/src/pages/AuthPage/AuthPage.tsx
+++ b/src/pages/AuthPage/AuthPage.tsx
@@ -1,12 +1,54 @@
-import React from 'react';
+import React, { useState } from 'react';
+import { makeStyles } from '@material-ui/core/styles';
import SignInForm from './SignInForm';
+import SignUpForm from './SignUpForm';
+
interface PropTypes {
logIn: (name: string, password: string) => Promise<boolean>;
}
+const useStyles = makeStyles({
+ formTransfer: {
+ display: 'flex',
+ justifyContent: 'center'
+ },
+ transferButton: {
+ marginLeft: 10,
+ color: 'green',
+ cursor: 'pointer'
+ }
+});
+
const AuthPage: React.FC<PropTypes> = ({ logIn }) => {
- return <SignInForm logIn={logIn} />;
+ const [auth, setAuth] = useState<'signIn' | 'signUp'>('signIn');
+ const classes = useStyles();
+
+ const handleRedirect = () => {
+ setAuth(auth === 'signIn' ? 'signUp' : 'signIn');
+ };
+
+ const footerInfo = {
+ signIn: ['Don\'t have an account?', 'Sign in'],
+ signUp: ['Already have an account?', 'Sign up']
+ };
+
+ return (
+ <>
+ {auth === 'signIn' && <SignInForm logIn={logIn} />}
+ {auth === 'signUp' && <SignUpForm logIn={logIn} />}
+ <div className={classes.formTransfer}>
+ <div>{footerInfo[auth][0]}</div>
+ <span
+ onClick={handleRedirect}
+ className={classes.transferButton}
+ role="presentation"
+ >
+ {footerInfo[auth][1]}
+ </span>
+ </div>
+ </>
+ );
};
export default AuthPage;
diff --git a/src/pages/AuthPage/SignInForm.tsx b/src/pages/AuthPage/SignInForm.tsx
index 1d4ce0e..c521abf 100644
--- a/src/pages/AuthPage/SignInForm.tsx
+++ b/src/pages/AuthPage/SignInForm.tsx
@@ -11,12 +11,16 @@ const useStyles = makeStyles(theme => ({
root: {
'& > *': {
margin: theme.spacing(1),
- width: '25ch'
+ width: theme.spacing(35)
},
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center'
+ },
+ formHeader: {
+ textAlign: 'center',
+ fontSize: 25
}
}));
@@ -37,22 +41,24 @@ const SignInForm: React.FC<PropTypes> = ({ logIn }) => {
};
return (
- <form className={classes.root} noValidate autoComplete="off">
- <h1>Sign In</h1>
- <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>
+ </>
);
};
diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx
new file mode 100644
index 0000000..2769eb0
--- /dev/null
+++ b/src/pages/AuthPage/SignUpForm.tsx
@@ -0,0 +1,62 @@
+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 { post } from '../../requests';
+
+interface PropTypes {
+ logIn: (name: string, password: string) => Promise<boolean>;
+}
+
+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 SignUpForm: React.FC<PropTypes> = ({ logIn }) => {
+ const classes = useStyles();
+ const inputRef = useRef<HTMLInputElement>();
+ const inputRefPassword = useRef<HTMLInputElement>();
+
+ const onClick = () => {
+ const name = inputRef.current?.value;
+ const password = inputRefPassword.current?.value;
+ const newUser = { name, password };
+ if (name && password) {
+ post('/users', newUser).then(() => {
+ logIn(name, password);
+ });
+ }
+ };
+
+ return (
+ <>
+ <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}
+ id="standard-password-input"
+ label="Password"
+ type="password"
+ />
+ <Button variant="contained" onClick={onClick}>submit</Button>
+ </form>
+ </>
+ );
+};
+
+export default SignUpForm;
diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx
index c2f242a..bddecd8 100644
--- a/src/pages/ProfilePage/ProfileInfo.tsx
+++ b/src/pages/ProfilePage/ProfileInfo.tsx
@@ -37,7 +37,6 @@ const useStyles = makeStyles({
const ProfileInfo: React.FC<PropTypes> = ({ user, logOut }) => {
const classes = useStyles();
-
return (
<div>
<Avatar className={classes.avatar} src={user?.avatarUrl} />
@@ -55,7 +54,11 @@ const ProfileInfo: React.FC<PropTypes> = ({ user, logOut }) => {
Following
</div>
</div>
- <Button variant="contained" onClick={logOut}>Log Out</Button>
+ {
+ user?._id === localStorage.getItem('userId')
+ ? <Button variant="contained" onClick={logOut}>Log Out</Button>
+ : null
+ }
</div>
);
};
diff --git a/src/types.d.ts b/src/types.d.ts
index e84f96c..a62eec8 100644
--- a/src/types.d.ts
+++ b/src/types.d.ts
@@ -2,7 +2,6 @@ export interface Page {
prefix: string;
id: string;
}
-
export interface User {
name: string;
avatarUrl: string;