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) => {
|
const uploadImage = (productId: number, file: File) => {
|
||||||
ProductService.uploadProductBarcodeImage({
|
ProductService.uploadProductBarcodeImage({
|
||||||
productId: productId,
|
productId: productId,
|
||||||
@@ -54,7 +48,6 @@ const BarcodeImageDropzone: FC<Props> = (props: Props) => {
|
|||||||
})
|
})
|
||||||
.then(({ ok, message, barcodeImageUrl }) => {
|
.then(({ ok, message, barcodeImageUrl }) => {
|
||||||
notifications.guess(ok, { message });
|
notifications.guess(ok, { message });
|
||||||
setIsLoading(false);
|
|
||||||
|
|
||||||
if (ok && barcodeImageUrl) {
|
if (ok && barcodeImageUrl) {
|
||||||
setBarcodeImageUrl(barcodeImageUrl);
|
setBarcodeImageUrl(barcodeImageUrl);
|
||||||
@@ -62,26 +55,10 @@ const BarcodeImageDropzone: FC<Props> = (props: Props) => {
|
|||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
notifications.error({ message: error.toString() });
|
notifications.error({ message: error.toString() });
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
setIsLoading(false);
|
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[]) => {
|
const onDrop = (files: FileWithPath[]) => {
|
||||||
@@ -92,7 +69,7 @@ const BarcodeImageDropzone: FC<Props> = (props: Props) => {
|
|||||||
}
|
}
|
||||||
const file = files[0];
|
const file = files[0];
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
uploadImageWrapper(props.productId, file);
|
uploadImage(props.productId, file);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteImage = () => {
|
const deleteImage = () => {
|
||||||
@@ -119,9 +96,7 @@ const BarcodeImageDropzone: FC<Props> = (props: Props) => {
|
|||||||
<Dropzone
|
<Dropzone
|
||||||
{...restProps}
|
{...restProps}
|
||||||
accept={[
|
accept={[
|
||||||
"image/png",
|
"application/pdf",
|
||||||
"image/jpeg",
|
|
||||||
"image/webp",
|
|
||||||
]}
|
]}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
onDrop={onDrop}>
|
onDrop={onDrop}>
|
||||||
|
|||||||
Reference in New Issue
Block a user