aboutsummaryrefslogtreecommitdiff
path: root/src/components/UploadImage
diff options
context:
space:
mode:
authorilyayudovin <ilyayudovin123@gmail.com>2020-06-30 02:09:37 +0300
committerilyayudovin <ilyayudovin123@gmail.com>2020-06-30 02:09:37 +0300
commit952f8ae3183b062e3b46791c793891f64dc771d5 (patch)
tree8ccf1073a596869215cde6e20b7d9d6848b571e3 /src/components/UploadImage
parent720a32c4cb1697f3a8f90973f28c334551ab87ff (diff)
downloadwhich-ui-952f8ae3183b062e3b46791c793891f64dc771d5.tar.gz
fix eslint errors
Diffstat (limited to 'src/components/UploadImage')
-rw-r--r--src/components/UploadImage/UploadImage.tsx20
1 files changed, 18 insertions, 2 deletions
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>