From 7ad127942bb12ee9de691e10dc9386849459ea46 Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Sun, 28 Jun 2020 19:09:20 +0300
Subject: feat: add poll submission component

---
 src/pages/ProfilePage/ProfileInfo.tsx | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

(limited to 'src/pages/ProfilePage/ProfileInfo.tsx')

diff --git a/src/pages/ProfilePage/ProfileInfo.tsx b/src/pages/ProfilePage/ProfileInfo.tsx
index 2b9227e..fada65f 100644
--- a/src/pages/ProfilePage/ProfileInfo.tsx
+++ b/src/pages/ProfilePage/ProfileInfo.tsx
@@ -7,6 +7,7 @@ import VerifiedIcon from '@material-ui/icons/CheckCircleOutline';
 import MoreMenu from './MoreMenu';
 import Highlight from './Highlight';
 import UploadImage from '../../components/UploadImage/UploadImage';
+import { patch } from '../../requests';
 
 
 interface PropTypes {
@@ -82,12 +83,21 @@ const ProfileInfo: React.FC<PropTypes> = ({
   const classes = useStyles();
   const [input, setInput] = useState(false);
 
+
   const dateSince = new Date(user?.createdAt || '').toLocaleDateString();
 
   const handleClick = () => {
     setInput(!input);
   };
 
+  const patchAvatar = (url: string) => {
+    const id = localStorage.getItem('userId');
+    patch(`/users/${id}`, { avatarUrl: url }).then(res => {
+      setUserInfo(res.data);
+      setUser(res.data);
+    });
+  };
+
   return (
     <div className={classes.root}>
       {
@@ -112,7 +122,7 @@ const ProfileInfo: React.FC<PropTypes> = ({
                   <Avatar className={classes.avatar} src={user?.avatarUrl} />
                 </Badge>
               </div>
-              <UploadImage displayD={input} setDisplayD={setInput} setUserInfo={setUserInfo} setUser={setUser} />
+              <UploadImage displayD={input} setDisplayD={setInput} callback={patchAvatar} />
             </div>
 )
           : <Avatar className={classes.avatar} src={user?.avatarUrl} />
-- 
cgit v1.2.3

