aboutsummaryrefslogtreecommitdiff
path: root/src/pages/ProfilePage/ProfileInfo.tsx
diff options
context:
space:
mode:
authorilyayudovin <ilyayudovin123@gmail.com>2020-06-27 16:49:58 +0300
committerilyayudovin <ilyayudovin123@gmail.com>2020-06-27 16:49:58 +0300
commite199f28a384dfd6fdf71e6ddaa21799096099cf9 (patch)
tree535b474b73f44a6091a22e5c07da7cfe4d75ab08 /src/pages/ProfilePage/ProfileInfo.tsx
parent562f675297e03f8abb16af0a5506c51ba91e166a (diff)
downloadwhich-ui-e199f28a384dfd6fdf71e6ddaa21799096099cf9.tar.gz
add dialog window for uploading avatar
Diffstat (limited to 'src/pages/ProfilePage/ProfileInfo.tsx')
-rw-r--r--src/pages/ProfilePage/ProfileInfo.tsx32
1 files changed, 7 insertions, 25 deletions
diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx
index b68075f..6578764 100644
--- a/src/pages/ProfilePage/ProfileInfo.tsx
+++ b/src/pages/ProfilePage/ProfileInfo.tsx
@@ -6,6 +6,7 @@ import CameraAltIcon from '@material-ui/icons/CameraAlt';
import MoreMenu from "./MoreMenu";
import {patch} from '../../requests';
import Highlight from "../../components/Highlight/Highlight";
+import UploadImage from "../../components/UploadImage/UploadImage";
interface PropTypes {
@@ -13,6 +14,8 @@ interface PropTypes {
logOut: () => void;
savedPolls: number;
totalVotes: number;
+ setUserInfo: (a: User) => void;
+ setUser: (a:User) => void;
}
const useStyles = makeStyles({
@@ -67,22 +70,14 @@ const StyledBadge = withStyles((theme) => ({
},
}))(Badge);
-const ProfileInfo: React.FC<PropTypes> = ({user, logOut,savedPolls, totalVotes}) => {
+const ProfileInfo: React.FC<PropTypes> = ({user, logOut,savedPolls, totalVotes, setUserInfo,setUser}) => {
const classes = useStyles();
- const [input,setInput] = useState('hide');
- const urlRef = useRef<HTMLInputElement>();
+ const [input,setInput] = useState(false);
const handleClick = () => {
- input === 'hide' ? setInput('show') : setInput('hide');
+ input === false ? setInput(true) : setInput(false);
};
- const updateAvatar = (event: any) => {
- const id = localStorage.getItem('userId');
- const newAvatar = urlRef.current?.value;
- patch(`/users/${id}`, {avatarUrl: newAvatar}).then(res => {
- console.log(res);
- })
- };
return (
<div className={classes.root}>
@@ -109,20 +104,7 @@ const ProfileInfo: React.FC<PropTypes> = ({user, logOut,savedPolls, totalVotes})
<Avatar className={classes.avatar} src={user?.avatarUrl}/>
</StyledBadge>
</div>
- {
- input === 'show'
- ?<form>
- <TextField
- inputRef={urlRef}
- id="url"
- label="url:"
- variant="outlined"
- color="secondary"
- />
- <button type='submit' onClick={updateAvatar}>upload</button>
- </form>
- : null
- }
+ <UploadImage displayD={input} setDisplayD={setInput} setUserInfo={setUserInfo} setUser={setUser}/>
</div>
: <Avatar className={classes.avatar} src={user?.avatarUrl}/>
}