From d68052300c2f52dfd0396a64f16645d639b8a52b Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Fri, 3 Jul 2020 17:44:02 +0300
Subject: feat!: remove url validation

---
 src/components/UploadImage/UploadImage.tsx | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

(limited to 'src/components/UploadImage/UploadImage.tsx')

diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx
index f5e680d..8ad65d5 100644
--- a/src/components/UploadImage/UploadImage.tsx
+++ b/src/components/UploadImage/UploadImage.tsx
@@ -6,7 +6,6 @@ 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 get from 'axios';
 
 interface PropTypes {
   isOpen: boolean;
@@ -15,8 +14,7 @@ interface PropTypes {
 }
 
 const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
-  const [url, setUrl] = useState('');
-  const [isError, setIsError] = useState(false);
+  const [url, setUrl] = useState<string>('');
 
 
   const handleClose = () => {
@@ -24,19 +22,8 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
   };
 
   const handleSubmit = () => {
-    get(url).then(res => {
-      if (res.headers['content-type'] === 'image/jpeg') {
-        callback(url || '');
-        setIsOpen(false);
-        setIsError(false);
-      } else {
-        // console.warn(res); TODO: handle error if response status is ok but not an image
-        setIsError(true);
-      }
-    }).catch(() => {
-      // console.warn(err); TODO: handle error if resposne status is not ok
-      setIsError(true);
-    });
+    handleClose();
+    callback(url || '');
   };
 
   const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
@@ -49,7 +36,7 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
         <DialogTitle>Upload an Image</DialogTitle>
         <DialogContent>
           <DialogContentText>
-            Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image.
+            Unfortunetly we do not support uploading images yet. Please provide a valid URL to your image:
           </DialogContentText>
           <TextField
             autoFocus
@@ -60,8 +47,6 @@ const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
             fullWidth
             autoComplete="off"
             onChange={handleChange}
-            error={isError}
-            helperText={isError === true ? 'invalid Url!' : ''}
           />
         </DialogContent>
         <DialogActions>
-- 
cgit v1.2.3

