diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-27 16:49:58 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-27 16:49:58 +0300 |
commit | e199f28a384dfd6fdf71e6ddaa21799096099cf9 (patch) | |
tree | 535b474b73f44a6091a22e5c07da7cfe4d75ab08 /src/components | |
parent | 562f675297e03f8abb16af0a5506c51ba91e166a (diff) | |
download | which-ui-e199f28a384dfd6fdf71e6ddaa21799096099cf9.tar.gz |
add dialog window for uploading avatar
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/UploadImage/UploadImage.tsx | 69 |
1 files changed, 69 insertions, 0 deletions
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<PropTypes> = ({displayD,setDisplayD,setUserInfo,setUser}) => { + const urlRef = useRef<HTMLInputElement>(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 ( + <div> + <Dialog open={displayD} onClose={handleClose} > + <DialogTitle id="form-dialog-title">Upload an Image</DialogTitle> + <DialogContent> + <DialogContentText> + Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image. + </DialogContentText> + <TextField + autoFocus + margin="dense" + id="name" + label="Image URL" + type="text" + fullWidth + autoComplete="off" + inputRef={urlRef} + /> + </DialogContent> + <DialogActions> + <Button onClick={handleClose} color="primary"> + Cancel + </Button> + <Button onClick={updateAvatar} color="primary"> + Submit + </Button> + </DialogActions> + </Dialog> + </div> + ); +}; + +export default UploadImage; |