diff --git a/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx b/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx index 77804a0..ff7631d 100644 --- a/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx +++ b/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx @@ -39,12 +39,6 @@ const BarcodeImageDropzone: FC = (props: Props) => { }); }; - const showIncorrectImageSizeError = () => { - notifications.error({ - message: "Изображение должно быть размером 58 х 40.", - }); - }; - const uploadImage = (productId: number, file: File) => { ProductService.uploadProductBarcodeImage({ productId: productId, @@ -54,7 +48,6 @@ const BarcodeImageDropzone: FC = (props: Props) => { }) .then(({ ok, message, barcodeImageUrl }) => { notifications.guess(ok, { message }); - setIsLoading(false); if (ok && barcodeImageUrl) { setBarcodeImageUrl(barcodeImageUrl); @@ -62,26 +55,10 @@ const BarcodeImageDropzone: FC = (props: Props) => { }) .catch(error => { notifications.error({ message: error.toString() }); + }) + .finally(() => { setIsLoading(false); - }); - }; - - const uploadImageWrapper = (productId: number, file: File) => { - const reader = new FileReader(); - reader.onloadend = () => { - const img = new Image(); - img.src = reader.result as string; - img.onload = () => { - const ratio = img.width / img.height; - if (Math.abs(ratio - BARCODE_IMAGE_RATIO) > 0.01) { - showIncorrectImageSizeError(); - setIsLoading(false); - return; - } - uploadImage(productId, file); - }; - }; - reader.readAsDataURL(file); + }) }; const onDrop = (files: FileWithPath[]) => { @@ -92,7 +69,7 @@ const BarcodeImageDropzone: FC = (props: Props) => { } const file = files[0]; setIsLoading(true); - uploadImageWrapper(props.productId, file); + uploadImage(props.productId, file); }; const deleteImage = () => { @@ -119,9 +96,7 @@ const BarcodeImageDropzone: FC = (props: Props) => {