feat: new barcodes system
This commit is contained in:
		@@ -82,6 +82,8 @@ export type { GetAllBarcodeTemplateSizesResponse } from './models/GetAllBarcodeT
 | 
				
			|||||||
export type { GetAllBarcodeTemplatesResponse } from './models/GetAllBarcodeTemplatesResponse';
 | 
					export type { GetAllBarcodeTemplatesResponse } from './models/GetAllBarcodeTemplatesResponse';
 | 
				
			||||||
export type { GetBarcodeTemplateByIdRequest } from './models/GetBarcodeTemplateByIdRequest';
 | 
					export type { GetBarcodeTemplateByIdRequest } from './models/GetBarcodeTemplateByIdRequest';
 | 
				
			||||||
export type { GetBarcodeTemplateByIdResponse } from './models/GetBarcodeTemplateByIdResponse';
 | 
					export type { GetBarcodeTemplateByIdResponse } from './models/GetBarcodeTemplateByIdResponse';
 | 
				
			||||||
 | 
					export type { GetProductBarcodePdfRequest } from './models/GetProductBarcodePdfRequest';
 | 
				
			||||||
 | 
					export type { GetProductBarcodePdfResponse } from './models/GetProductBarcodePdfResponse';
 | 
				
			||||||
export type { GetProductBarcodeRequest } from './models/GetProductBarcodeRequest';
 | 
					export type { GetProductBarcodeRequest } from './models/GetProductBarcodeRequest';
 | 
				
			||||||
export type { GetProductBarcodeResponse } from './models/GetProductBarcodeResponse';
 | 
					export type { GetProductBarcodeResponse } from './models/GetProductBarcodeResponse';
 | 
				
			||||||
export type { HTTPValidationError } from './models/HTTPValidationError';
 | 
					export type { HTTPValidationError } from './models/HTTPValidationError';
 | 
				
			||||||
@@ -96,6 +98,7 @@ export type { ProductExistsBarcodeResponse } from './models/ProductExistsBarcode
 | 
				
			|||||||
export type { ProductGenerateBarcodeRequest } from './models/ProductGenerateBarcodeRequest';
 | 
					export type { ProductGenerateBarcodeRequest } from './models/ProductGenerateBarcodeRequest';
 | 
				
			||||||
export type { ProductGenerateBarcodeResponse } from './models/ProductGenerateBarcodeResponse';
 | 
					export type { ProductGenerateBarcodeResponse } from './models/ProductGenerateBarcodeResponse';
 | 
				
			||||||
export type { ProductGetResponse } from './models/ProductGetResponse';
 | 
					export type { ProductGetResponse } from './models/ProductGetResponse';
 | 
				
			||||||
 | 
					export type { ProductImageSchema } from './models/ProductImageSchema';
 | 
				
			||||||
export type { ProductSchema } from './models/ProductSchema';
 | 
					export type { ProductSchema } from './models/ProductSchema';
 | 
				
			||||||
export type { ProductUpdateRequest } from './models/ProductUpdateRequest';
 | 
					export type { ProductUpdateRequest } from './models/ProductUpdateRequest';
 | 
				
			||||||
export type { ProductUpdateResponse } from './models/ProductUpdateResponse';
 | 
					export type { ProductUpdateResponse } from './models/ProductUpdateResponse';
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								src/client/models/GetProductBarcodePdfRequest.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/client/models/GetProductBarcodePdfRequest.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					/* generated using openapi-typescript-codegen -- do no edit */
 | 
				
			||||||
 | 
					/* istanbul ignore file */
 | 
				
			||||||
 | 
					/* tslint:disable */
 | 
				
			||||||
 | 
					/* eslint-disable */
 | 
				
			||||||
 | 
					export type GetProductBarcodePdfRequest = {
 | 
				
			||||||
 | 
					    productId: number;
 | 
				
			||||||
 | 
					    barcode: string;
 | 
				
			||||||
 | 
					    barcodeTemplateId?: (number | null);
 | 
				
			||||||
 | 
					    quantity: number;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/client/models/GetProductBarcodePdfResponse.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/client/models/GetProductBarcodePdfResponse.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					/* generated using openapi-typescript-codegen -- do no edit */
 | 
				
			||||||
 | 
					/* istanbul ignore file */
 | 
				
			||||||
 | 
					/* tslint:disable */
 | 
				
			||||||
 | 
					/* eslint-disable */
 | 
				
			||||||
 | 
					export type GetProductBarcodePdfResponse = {
 | 
				
			||||||
 | 
					    base64String: string;
 | 
				
			||||||
 | 
					    filename: string;
 | 
				
			||||||
 | 
					    mimeType: string;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
/* tslint:disable */
 | 
					/* tslint:disable */
 | 
				
			||||||
/* eslint-disable */
 | 
					/* eslint-disable */
 | 
				
			||||||
import type { BarcodeTemplateSchema } from './BarcodeTemplateSchema';
 | 
					import type { BarcodeTemplateSchema } from './BarcodeTemplateSchema';
 | 
				
			||||||
 | 
					import type { ProductImageSchema } from './ProductImageSchema';
 | 
				
			||||||
export type ProductCreateRequest = {
 | 
					export type ProductCreateRequest = {
 | 
				
			||||||
    name: string;
 | 
					    name: string;
 | 
				
			||||||
    article?: (string | null);
 | 
					    article?: (string | null);
 | 
				
			||||||
@@ -15,5 +16,6 @@ export type ProductCreateRequest = {
 | 
				
			|||||||
    size?: (string | null);
 | 
					    size?: (string | null);
 | 
				
			||||||
    additionalInfo?: (string | null);
 | 
					    additionalInfo?: (string | null);
 | 
				
			||||||
    imageUrl?: (string | null);
 | 
					    imageUrl?: (string | null);
 | 
				
			||||||
 | 
					    images?: (Array<ProductImageSchema> | null);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								src/client/models/ProductImageSchema.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/client/models/ProductImageSchema.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					/* generated using openapi-typescript-codegen -- do no edit */
 | 
				
			||||||
 | 
					/* istanbul ignore file */
 | 
				
			||||||
 | 
					/* tslint:disable */
 | 
				
			||||||
 | 
					/* eslint-disable */
 | 
				
			||||||
 | 
					export type ProductImageSchema = {
 | 
				
			||||||
 | 
					    id: number;
 | 
				
			||||||
 | 
					    productId: number;
 | 
				
			||||||
 | 
					    imageUrl: string;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
/* tslint:disable */
 | 
					/* tslint:disable */
 | 
				
			||||||
/* eslint-disable */
 | 
					/* eslint-disable */
 | 
				
			||||||
import type { BarcodeTemplateSchema } from './BarcodeTemplateSchema';
 | 
					import type { BarcodeTemplateSchema } from './BarcodeTemplateSchema';
 | 
				
			||||||
 | 
					import type { ProductImageSchema } from './ProductImageSchema';
 | 
				
			||||||
export type ProductSchema = {
 | 
					export type ProductSchema = {
 | 
				
			||||||
    name: string;
 | 
					    name: string;
 | 
				
			||||||
    article?: (string | null);
 | 
					    article?: (string | null);
 | 
				
			||||||
@@ -15,6 +16,7 @@ export type ProductSchema = {
 | 
				
			|||||||
    size?: (string | null);
 | 
					    size?: (string | null);
 | 
				
			||||||
    additionalInfo?: (string | null);
 | 
					    additionalInfo?: (string | null);
 | 
				
			||||||
    imageUrl?: (string | null);
 | 
					    imageUrl?: (string | null);
 | 
				
			||||||
 | 
					    images?: (Array<ProductImageSchema> | null);
 | 
				
			||||||
    id: number;
 | 
					    id: number;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,8 @@
 | 
				
			|||||||
/* tslint:disable */
 | 
					/* tslint:disable */
 | 
				
			||||||
/* eslint-disable */
 | 
					/* eslint-disable */
 | 
				
			||||||
import type { Body_upload_product_image } from '../models/Body_upload_product_image';
 | 
					import type { Body_upload_product_image } from '../models/Body_upload_product_image';
 | 
				
			||||||
 | 
					import type { GetProductBarcodePdfRequest } from '../models/GetProductBarcodePdfRequest';
 | 
				
			||||||
 | 
					import type { GetProductBarcodePdfResponse } from '../models/GetProductBarcodePdfResponse';
 | 
				
			||||||
import type { GetProductBarcodeRequest } from '../models/GetProductBarcodeRequest';
 | 
					import type { GetProductBarcodeRequest } from '../models/GetProductBarcodeRequest';
 | 
				
			||||||
import type { GetProductBarcodeResponse } from '../models/GetProductBarcodeResponse';
 | 
					import type { GetProductBarcodeResponse } from '../models/GetProductBarcodeResponse';
 | 
				
			||||||
import type { ProductAddBarcodeRequest } from '../models/ProductAddBarcodeRequest';
 | 
					import type { ProductAddBarcodeRequest } from '../models/ProductAddBarcodeRequest';
 | 
				
			||||||
@@ -215,6 +217,26 @@ export class ProductService {
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get Product Barcode Pdf
 | 
				
			||||||
 | 
					     * @returns GetProductBarcodePdfResponse Successful Response
 | 
				
			||||||
 | 
					     * @throws ApiError
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static getProductBarcodePdf({
 | 
				
			||||||
 | 
					        requestBody,
 | 
				
			||||||
 | 
					    }: {
 | 
				
			||||||
 | 
					        requestBody: GetProductBarcodePdfRequest,
 | 
				
			||||||
 | 
					    }): CancelablePromise<GetProductBarcodePdfResponse> {
 | 
				
			||||||
 | 
					        return __request(OpenAPI, {
 | 
				
			||||||
 | 
					            method: 'POST',
 | 
				
			||||||
 | 
					            url: '/product/barcode/get-pdf',
 | 
				
			||||||
 | 
					            body: requestBody,
 | 
				
			||||||
 | 
					            mediaType: 'application/json',
 | 
				
			||||||
 | 
					            errors: {
 | 
				
			||||||
 | 
					                422: `Validation Error`,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Upload Product Image
 | 
					     * Upload Product Image
 | 
				
			||||||
     * @returns ProductUploadImageResponse Successful Response
 | 
					     * @returns ProductUploadImageResponse Successful Response
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,11 @@
 | 
				
			|||||||
import {ContextModalProps, modals} from "@mantine/modals";
 | 
					import {ContextModalProps, modals} from "@mantine/modals";
 | 
				
			||||||
import {Button, Divider, Flex, NumberInput, rem, Select} from "@mantine/core";
 | 
					import {Button, Divider, Flex, NumberInput, rem, Select} from "@mantine/core";
 | 
				
			||||||
import {useEffect, useRef, useState} from "react";
 | 
					import {useEffect, useRef, useState} from "react";
 | 
				
			||||||
import {useReactToPrint} from "react-to-print";
 | 
					 | 
				
			||||||
import {BarcodeSchema, ProductService} from "../../client";
 | 
					import {BarcodeSchema, ProductService} from "../../client";
 | 
				
			||||||
import {useGetProductById} from "../../api/product/useGetProductById.tsx";
 | 
					import {useGetProductById} from "../../api/product/useGetProductById.tsx";
 | 
				
			||||||
import {notifications} from "../../shared/lib/notifications.ts";
 | 
					import {notifications} from "../../shared/lib/notifications.ts";
 | 
				
			||||||
import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx";
 | 
					import PrintBarcodeContainer from "./PrintBarcodeContainer.tsx";
 | 
				
			||||||
 | 
					import {base64ToBlob} from "../../shared/lib/utils.ts";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Props = {
 | 
					type Props = {
 | 
				
			||||||
    productId: number;
 | 
					    productId: number;
 | 
				
			||||||
@@ -22,9 +22,9 @@ const PrintBarcodeModal = ({
 | 
				
			|||||||
    const {product, refetch} = useGetProductById(productId);
 | 
					    const {product, refetch} = useGetProductById(productId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const barcodeRef = useRef(null);
 | 
					    const barcodeRef = useRef(null);
 | 
				
			||||||
    const handlePrint = useReactToPrint({
 | 
					    // const handlePrint = useReactToPrint({
 | 
				
			||||||
        content: () => barcodeRef.current
 | 
					    //     content: () => barcodeRef.current
 | 
				
			||||||
    });
 | 
					    // });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const onAdd = (newBarcode: string) => {
 | 
					    const onAdd = (newBarcode: string) => {
 | 
				
			||||||
        ProductService.addProductBarcode({requestBody: {productId, barcode: newBarcode}})
 | 
					        ProductService.addProductBarcode({requestBody: {productId, barcode: newBarcode}})
 | 
				
			||||||
@@ -117,7 +117,26 @@ const PrintBarcodeModal = ({
 | 
				
			|||||||
                    <Button
 | 
					                    <Button
 | 
				
			||||||
                        size={"lg"}
 | 
					                        size={"lg"}
 | 
				
			||||||
                        disabled={!barcode}
 | 
					                        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>
 | 
					                    >Печать</Button>
 | 
				
			||||||
                </Flex>
 | 
					                </Flex>
 | 
				
			||||||
            </Flex>
 | 
					            </Flex>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,3 +51,24 @@ export const IMAGE_MIME_TYPES = [
 | 
				
			|||||||
export const isNilOrEmptyString = (value: unknown): value is null | undefined | '' => {
 | 
					export const isNilOrEmptyString = (value: unknown): value is null | undefined | '' => {
 | 
				
			||||||
    return isNil(value) || (typeof value === 'string' && value.trim() === '');
 | 
					    return isNil(value) || (typeof value === 'string' && value.trim() === '');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function base64ToBlob(base64: string, type: string) {
 | 
				
			||||||
 | 
					    const binaryString = window.atob(base64);
 | 
				
			||||||
 | 
					    const len = binaryString.length;
 | 
				
			||||||
 | 
					    const bytes = new Uint8Array(len);
 | 
				
			||||||
 | 
					    for (let i = 0; i < len; ++i) {
 | 
				
			||||||
 | 
					        bytes[i] = binaryString.charCodeAt(i);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return new Blob([bytes], {type: type});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function writeToFile(data: string, filename: string, type: string) {
 | 
				
			||||||
 | 
					    const blobValue = base64ToBlob(data, type);
 | 
				
			||||||
 | 
					    const blobURL = URL.createObjectURL(blobValue);
 | 
				
			||||||
 | 
					    const blobLink = document.createElement('a');
 | 
				
			||||||
 | 
					    blobLink.setAttribute('download', filename);
 | 
				
			||||||
 | 
					    blobLink.href = blobURL;
 | 
				
			||||||
 | 
					    document.body.appendChild(blobLink);
 | 
				
			||||||
 | 
					    blobLink.click();
 | 
				
			||||||
 | 
					    document.body.removeChild(blobLink);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user