diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-26 18:59:29 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-26 18:59:29 +0300 |
commit | 08599cd0954fbbb90d4932cf3de1c7511eb81b52 (patch) | |
tree | 9c16cf0cc091ddbd0503c6fde4f4be55456ec2b1 /src/pages/ProfilePage | |
parent | 9e9c18cd1d02a0185d0387770a7bafc18020d6c0 (diff) | |
download | which-ui-08599cd0954fbbb90d4932cf3de1c7511eb81b52.tar.gz |
add request to set avatarUrl
Diffstat (limited to 'src/pages/ProfilePage')
-rw-r--r-- | src/pages/ProfilePage/ProfileInfo.tsx | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx index 7489bc5..07a6df0 100644 --- a/src/pages/ProfilePage/ProfileInfo.tsx +++ b/src/pages/ProfilePage/ProfileInfo.tsx @@ -1,9 +1,11 @@ -import React from 'react'; -import {Avatar, Badge, withStyles} from '@material-ui/core/'; +import React, {useRef, useState} from 'react'; +import {Avatar, Badge, TextField, withStyles} from '@material-ui/core/'; import {makeStyles} from '@material-ui/core/styles'; import {User} from 'which-types'; import CameraAltIcon from '@material-ui/icons/CameraAlt'; import MoreMenu from "./MoreMenu"; +import {patch} from '../../requests'; + interface PropTypes { user: User | undefined; @@ -69,6 +71,21 @@ const StyledBadge = withStyles((theme) => ({ const ProfileInfo: React.FC<PropTypes> = ({user, logOut}) => { const classes = useStyles(); + const [input,setInput] = useState('hide'); + const urlRef = useRef<HTMLInputElement>(); + + const handleClick = () => { + input === 'hide' ? setInput('show') : setInput('hide'); + }; + + 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}> { @@ -78,16 +95,36 @@ const ProfileInfo: React.FC<PropTypes> = ({user, logOut}) => { <MoreMenu logOut={logOut}/> <div className={classes.avatarContainer}> <StyledBadge + onClick={handleClick} overlap="circle" anchorOrigin={{ vertical: 'bottom', horizontal: 'right', }} - badgeContent={<CameraAltIcon/>} + badgeContent= + { + <div> + <CameraAltIcon/> + </div> + } > <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 + } </div> : <Avatar className={classes.avatar} src={user?.avatarUrl}/> } |