diff options
author | ilyayudovin <46264063+ilyayudovin@users.noreply.github.com> | 2020-06-27 19:18:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-27 19:18:33 +0300 |
commit | 5057fe763d423be607336d6b839909843c5a2567 (patch) | |
tree | 83356dd3ee0871e5226aa9ed67d9905f35e323f2 /src/components/UploadImage | |
parent | 9c4d6400ae83a32853d4437236f42796f08dbde7 (diff) | |
parent | 5b08023e0aa0e626264673ebb86dc82299a3b54b (diff) | |
download | which-ui-5057fe763d423be607336d6b839909843c5a2567.tar.gz |
Merge pull request #46 from which-ecosystem/profile
profile
Diffstat (limited to 'src/components/UploadImage')
-rw-r--r-- | src/components/UploadImage/UploadImage.tsx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx new file mode 100644 index 0000000..42ee989 --- /dev/null +++ b/src/components/UploadImage/UploadImage.tsx @@ -0,0 +1,70 @@ +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 { User } from 'which-types'; +import { patch } from '../../requests'; + +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 = () => { + const id = localStorage.getItem('userId'); + const newAvatar = urlRef.current?.value; + 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; |