From e199f28a384dfd6fdf71e6ddaa21799096099cf9 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Sat, 27 Jun 2020 16:49:58 +0300 Subject: add dialog window for uploading avatar --- src/components/UploadImage/UploadImage.tsx | 69 ++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/components/UploadImage/UploadImage.tsx (limited to 'src/components/UploadImage/UploadImage.tsx') diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx new file mode 100644 index 0000000..929151f --- /dev/null +++ b/src/components/UploadImage/UploadImage.tsx @@ -0,0 +1,69 @@ +import React, {useRef} from 'react'; +import Button from '@material-ui/core/Button'; +import TextField from '@material-ui/core/TextField'; +import Dialog from '@material-ui/core/Dialog'; +import DialogActions from '@material-ui/core/DialogActions'; +import DialogContent from '@material-ui/core/DialogContent'; +import DialogContentText from '@material-ui/core/DialogContentText'; +import DialogTitle from '@material-ui/core/DialogTitle'; +import {patch} from "../../requests"; +import {User} from 'which-types'; + +interface PropTypes { + displayD: boolean; + setDisplayD: (d: boolean) => void; + setUserInfo: (a: User) => void; + setUser: (a: User) => void +} + +const UploadImage: React.FC = ({displayD,setDisplayD,setUserInfo,setUser}) => { + const urlRef = useRef(null); + + const handleClose = () => { + setDisplayD(false); + }; + + const updateAvatar = (event: any) => { + const id = localStorage.getItem('userId'); + const newAvatar = urlRef.current?.value; + console.log(newAvatar); + patch(`/users/${id}`, {avatarUrl: newAvatar}).then(res => { + setUserInfo(res.data); + setUser(res.data); + }); + setDisplayD(false); + }; + + return ( +
+ + Upload an Image + + + Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image. + + + + + + + + +
+ ); +}; + +export default UploadImage; -- cgit v1.2.3