From 08599cd0954fbbb90d4932cf3de1c7511eb81b52 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Fri, 26 Jun 2020 18:59:29 +0300 Subject: add request to set avatarUrl --- src/pages/ProfilePage/ProfileInfo.tsx | 43 ++++++++++++++++++++++++++++++++--- src/requests.ts | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'src') 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 = ({user, logOut}) => { const classes = useStyles(); + const [input,setInput] = useState('hide'); + const urlRef = useRef(); + + 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 (
{ @@ -78,16 +95,36 @@ const ProfileInfo: React.FC = ({user, logOut}) => {
} + badgeContent= + { +
+ +
+ } >
+ { + input === 'show' + ?
+ + + + : null + }
: } diff --git a/src/requests.ts b/src/requests.ts index 4cfd37b..42b5b95 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -10,6 +10,6 @@ requests.interceptors.request.use(config => { return _.set(config, 'headers.Authorization', token); }); -export const { get, post, put } = requests; +export const { get, post, put, patch } = requests; export default requests; -- cgit v1.2.3