fix: uploading barcode pdf files instead of images
This commit is contained in:
@@ -39,12 +39,6 @@ const BarcodeImageDropzone: FC<Props> = (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: 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: 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: 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: Props) => {
|
||||
<Dropzone
|
||||
{...restProps}
|
||||
accept={[
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/webp",
|
||||
"application/pdf",
|
||||
]}
|
||||
multiple={false}
|
||||
onDrop={onDrop}>
|
||||
|
||||
Reference in New Issue
Block a user