From e9009017650fb349ca29b6cf74113a2257e45a20 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Sat, 2 Nov 2024 00:55:12 +0400 Subject: [PATCH] feat: barcode image output in PrintBarcodeModal --- .../BarcodeImageDropzone.tsx | 5 -- .../PrintBarcodeModal/PrintBarcodeModal.tsx | 69 +++++++++++++------ 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx b/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx index 51f59ca..77804a0 100644 --- a/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx +++ b/src/components/BarcodeImageDropzone/BarcodeImageDropzone.tsx @@ -121,12 +121,7 @@ const BarcodeImageDropzone: FC = (props: Props) => { accept={[ "image/png", "image/jpeg", - "image/bmp", - "image/tiff", - "image/x-icon", "image/webp", - "image/svg+xml", - "image/heic", ]} multiple={false} onDrop={onDrop}> diff --git a/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx b/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx index 6abaf8a..3a90ec8 100644 --- a/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx +++ b/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx @@ -7,6 +7,9 @@ import { notifications } from "../../shared/lib/notifications.ts"; import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx"; import { base64ToBlob } from "../../shared/lib/utils.ts"; +// Barcode image aspects ratio should be equal 58/40 +const BARCODE_IMAGE_RATIO = 1.45; + type Props = { productId: number; defaultQuantity?: number; @@ -16,6 +19,7 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps) => { const [quantity, setQuantity] = useState(defaultQuantity); const [barcode, setBarcode] = useState(); const [barcodeData, setBarcodeData] = useState(); + const [barcodeImageUrl, setBarcodeImageUrl] = useState(); const { product, refetch } = useGetProductById(productId); @@ -63,9 +67,18 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps) => { setBarcodeData(barcode); }); }; + const fetchBarcodeImage = () => { + if (!product) return; + ProductService.getProductBarcodeImage({ + productId: product.id, + }).then(res => { + if (res.barcodeImageUrl) setBarcodeImageUrl(res.barcodeImageUrl); + }); + } useEffect(() => { if (!product) return; if (product.barcodes.length === 1) setBarcode(product.barcodes[0]); + fetchBarcodeImage(); }, [product]); useEffect(() => { @@ -78,13 +91,23 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps) => { - setBarcode(value || undefined)} + data={product?.barcodes} + label={"Штрихкод"} + placeholder={"Выберите штрихкод"} + /> + ) + } ) => { - - - - + { + !barcodeImageUrl && ( + + + + + ) + }