From 952f8ae3183b062e3b46791c793891f64dc771d5 Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Tue, 30 Jun 2020 02:09:37 +0300
Subject: fix eslint errors

---
 src/components/UploadImage/UploadImage.tsx | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

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

diff --git a/src/components/UploadImage/UploadImage.tsx b/src/components/UploadImage/UploadImage.tsx
index e6f6d05..d005830 100644
--- a/src/components/UploadImage/UploadImage.tsx
+++ b/src/components/UploadImage/UploadImage.tsx
@@ -6,6 +6,7 @@ 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 '../../../node_modules/axios';
 
 interface PropTypes {
   isOpen: boolean;
@@ -15,14 +16,27 @@ interface PropTypes {
 
 const UploadImage: React.FC<PropTypes> = ({ setIsOpen, isOpen, callback }) => {
   const [url, setUrl] = useState('');
+  const [isError, setIsError] = useState(false);
+
 
   const handleClose = () => {
     setIsOpen(false);
   };
 
   const handleSubmit = () => {
-    callback(url || '');
-    setIsOpen(false);
+    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);
+    });
   };
 
   const handleChange = (event:React.ChangeEvent<HTMLInputElement>) => {
@@ -46,6 +60,8 @@ 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

