feat: barcode image output in PrintBarcodeModal
This commit is contained in:
@@ -121,12 +121,7 @@ const BarcodeImageDropzone: FC<Props> = (props: Props) => {
|
|||||||
accept={[
|
accept={[
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"image/bmp",
|
|
||||||
"image/tiff",
|
|
||||||
"image/x-icon",
|
|
||||||
"image/webp",
|
"image/webp",
|
||||||
"image/svg+xml",
|
|
||||||
"image/heic",
|
|
||||||
]}
|
]}
|
||||||
multiple={false}
|
multiple={false}
|
||||||
onDrop={onDrop}>
|
onDrop={onDrop}>
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import { notifications } from "../../shared/lib/notifications.ts";
|
|||||||
import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx";
|
import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx";
|
||||||
import { base64ToBlob } from "../../shared/lib/utils.ts";
|
import { base64ToBlob } from "../../shared/lib/utils.ts";
|
||||||
|
|
||||||
|
// Barcode image aspects ratio should be equal 58/40
|
||||||
|
const BARCODE_IMAGE_RATIO = 1.45;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
productId: number;
|
productId: number;
|
||||||
defaultQuantity?: number;
|
defaultQuantity?: number;
|
||||||
@@ -16,6 +19,7 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps<Props>) => {
|
|||||||
const [quantity, setQuantity] = useState(defaultQuantity);
|
const [quantity, setQuantity] = useState(defaultQuantity);
|
||||||
const [barcode, setBarcode] = useState<string | undefined>();
|
const [barcode, setBarcode] = useState<string | undefined>();
|
||||||
const [barcodeData, setBarcodeData] = useState<BarcodeSchema | undefined>();
|
const [barcodeData, setBarcodeData] = useState<BarcodeSchema | undefined>();
|
||||||
|
const [barcodeImageUrl, setBarcodeImageUrl] = useState<string | undefined>();
|
||||||
|
|
||||||
const { product, refetch } = useGetProductById(productId);
|
const { product, refetch } = useGetProductById(productId);
|
||||||
|
|
||||||
@@ -63,9 +67,18 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps<Props>) => {
|
|||||||
setBarcodeData(barcode);
|
setBarcodeData(barcode);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const fetchBarcodeImage = () => {
|
||||||
|
if (!product) return;
|
||||||
|
ProductService.getProductBarcodeImage({
|
||||||
|
productId: product.id,
|
||||||
|
}).then(res => {
|
||||||
|
if (res.barcodeImageUrl) setBarcodeImageUrl(res.barcodeImageUrl);
|
||||||
|
});
|
||||||
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!product) return;
|
if (!product) return;
|
||||||
if (product.barcodes.length === 1) setBarcode(product.barcodes[0]);
|
if (product.barcodes.length === 1) setBarcode(product.barcodes[0]);
|
||||||
|
fetchBarcodeImage();
|
||||||
}, [product]);
|
}, [product]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -78,13 +91,23 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps<Props>) => {
|
|||||||
<Flex
|
<Flex
|
||||||
gap={rem(10)}
|
gap={rem(10)}
|
||||||
direction={"column"}>
|
direction={"column"}>
|
||||||
<Select
|
{
|
||||||
value={barcode}
|
barcodeImageUrl ? (
|
||||||
onChange={value => setBarcode(value || undefined)}
|
<object style={{
|
||||||
data={product?.barcodes}
|
alignSelf: "center",
|
||||||
label={"Штрихкод"}
|
aspectRatio: BARCODE_IMAGE_RATIO,
|
||||||
placeholder={"Выберите штрихкод"}
|
width: "240px",
|
||||||
/>
|
}} data={barcodeImageUrl} />
|
||||||
|
) : (
|
||||||
|
<Select
|
||||||
|
value={barcode}
|
||||||
|
onChange={value => setBarcode(value || undefined)}
|
||||||
|
data={product?.barcodes}
|
||||||
|
label={"Штрихкод"}
|
||||||
|
placeholder={"Выберите штрихкод"}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
<NumberInput
|
<NumberInput
|
||||||
label={"Количество копий"}
|
label={"Количество копий"}
|
||||||
placeholder={"Введите количество копий"}
|
placeholder={"Введите количество копий"}
|
||||||
@@ -99,20 +122,24 @@ const PrintBarcodeModal = ({ innerProps }: ContextModalProps<Props>) => {
|
|||||||
<Flex
|
<Flex
|
||||||
direction={"column"}
|
direction={"column"}
|
||||||
gap={rem(10)}>
|
gap={rem(10)}>
|
||||||
<Flex gap={rem(10)}>
|
{
|
||||||
<Button
|
!barcodeImageUrl && (
|
||||||
onClick={() => onAddClick()}
|
<Flex gap={rem(10)}>
|
||||||
variant={"default"}
|
<Button
|
||||||
fullWidth>
|
onClick={() => onAddClick()}
|
||||||
Добавить вручную
|
variant={"default"}
|
||||||
</Button>
|
fullWidth>
|
||||||
<Button
|
Добавить вручную
|
||||||
onClick={() => onGenerateClick()}
|
</Button>
|
||||||
variant={"default"}
|
<Button
|
||||||
fullWidth>
|
onClick={() => onGenerateClick()}
|
||||||
Сгенерировать
|
variant={"default"}
|
||||||
</Button>
|
fullWidth>
|
||||||
</Flex>
|
Сгенерировать
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
size={"lg"}
|
size={"lg"}
|
||||||
disabled={!barcode}
|
disabled={!barcode}
|
||||||
|
|||||||
Reference in New Issue
Block a user