aboutsummaryrefslogtreecommitdiff
path: root/src/components/UploadImage/UploadImage.tsx
diff options
context:
space:
mode:
authorilyayudovin <46264063+ilyayudovin@users.noreply.github.com>2020-06-27 19:18:33 +0300
committerGitHub <noreply@github.com>2020-06-27 19:18:33 +0300
commit5057fe763d423be607336d6b839909843c5a2567 (patch)
tree83356dd3ee0871e5226aa9ed67d9905f35e323f2 /src/components/UploadImage/UploadImage.tsx
parent9c4d6400ae83a32853d4437236f42796f08dbde7 (diff)
parent5b08023e0aa0e626264673ebb86dc82299a3b54b (diff)
downloadwhich-ui-5057fe763d423be607336d6b839909843c5a2567.tar.gz
Merge pull request #46 from which-ecosystem/profile
profile
Diffstat (limited to 'src/components/UploadImage/UploadImage.tsx')
-rw-r--r--src/components/UploadImage/UploadImage.tsx70
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;