feat: new barcodes system
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import {ContextModalProps, modals} from "@mantine/modals";
|
||||
import {Button, Divider, Flex, NumberInput, rem, Select} from "@mantine/core";
|
||||
import {useEffect, useRef, useState} from "react";
|
||||
import {useReactToPrint} from "react-to-print";
|
||||
import {BarcodeSchema, ProductService} from "../../client";
|
||||
import {useGetProductById} from "../../api/product/useGetProductById.tsx";
|
||||
import {notifications} from "../../shared/lib/notifications.ts";
|
||||
import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx";
|
||||
import {base64ToBlob} from "../../shared/lib/utils.ts";
|
||||
|
||||
type Props = {
|
||||
productId: number;
|
||||
@@ -22,9 +22,9 @@ const PrintBarcodeModal = ({
|
||||
const {product, refetch} = useGetProductById(productId);
|
||||
|
||||
const barcodeRef = useRef(null);
|
||||
const handlePrint = useReactToPrint({
|
||||
content: () => barcodeRef.current
|
||||
});
|
||||
// const handlePrint = useReactToPrint({
|
||||
// content: () => barcodeRef.current
|
||||
// });
|
||||
|
||||
const onAdd = (newBarcode: string) => {
|
||||
ProductService.addProductBarcode({requestBody: {productId, barcode: newBarcode}})
|
||||
@@ -117,7 +117,26 @@ const PrintBarcodeModal = ({
|
||||
<Button
|
||||
size={"lg"}
|
||||
disabled={!barcode}
|
||||
onClick={() => handlePrint()}
|
||||
onClick={async () => {
|
||||
if (!barcode) return;
|
||||
const response = await ProductService.getProductBarcodePdf({
|
||||
requestBody: {
|
||||
productId,
|
||||
barcode,
|
||||
quantity
|
||||
}
|
||||
});
|
||||
const pdfBlob = base64ToBlob(response.base64String, response.mimeType);
|
||||
const pdfUrl = URL.createObjectURL(pdfBlob);
|
||||
const pdfWindow = window.open(pdfUrl);
|
||||
if (!pdfWindow) {
|
||||
notifications.error({message: "Ошибка"});
|
||||
return
|
||||
}
|
||||
pdfWindow.onload = () => {
|
||||
pdfWindow.print();
|
||||
}
|
||||
}}
|
||||
>Печать</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
Reference in New Issue
Block a user