diff --git a/src/client/index.ts b/src/client/index.ts index 98b7b67..807b3dc 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -82,6 +82,8 @@ export type { GetAllBarcodeTemplateSizesResponse } from './models/GetAllBarcodeT export type { GetAllBarcodeTemplatesResponse } from './models/GetAllBarcodeTemplatesResponse'; export type { GetBarcodeTemplateByIdRequest } from './models/GetBarcodeTemplateByIdRequest'; 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 { GetProductBarcodeResponse } from './models/GetProductBarcodeResponse'; export type { HTTPValidationError } from './models/HTTPValidationError'; @@ -96,6 +98,7 @@ export type { ProductExistsBarcodeResponse } from './models/ProductExistsBarcode export type { ProductGenerateBarcodeRequest } from './models/ProductGenerateBarcodeRequest'; export type { ProductGenerateBarcodeResponse } from './models/ProductGenerateBarcodeResponse'; export type { ProductGetResponse } from './models/ProductGetResponse'; +export type { ProductImageSchema } from './models/ProductImageSchema'; export type { ProductSchema } from './models/ProductSchema'; export type { ProductUpdateRequest } from './models/ProductUpdateRequest'; export type { ProductUpdateResponse } from './models/ProductUpdateResponse'; diff --git a/src/client/models/GetProductBarcodePdfRequest.ts b/src/client/models/GetProductBarcodePdfRequest.ts new file mode 100644 index 0000000..9e3a387 --- /dev/null +++ b/src/client/models/GetProductBarcodePdfRequest.ts @@ -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; +}; + diff --git a/src/client/models/GetProductBarcodePdfResponse.ts b/src/client/models/GetProductBarcodePdfResponse.ts new file mode 100644 index 0000000..8c75ec0 --- /dev/null +++ b/src/client/models/GetProductBarcodePdfResponse.ts @@ -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; +}; + diff --git a/src/client/models/ProductCreateRequest.ts b/src/client/models/ProductCreateRequest.ts index bff4025..9f401b1 100644 --- a/src/client/models/ProductCreateRequest.ts +++ b/src/client/models/ProductCreateRequest.ts @@ -3,6 +3,7 @@ /* tslint:disable */ /* eslint-disable */ import type { BarcodeTemplateSchema } from './BarcodeTemplateSchema'; +import type { ProductImageSchema } from './ProductImageSchema'; export type ProductCreateRequest = { name: string; article?: (string | null); @@ -15,5 +16,6 @@ export type ProductCreateRequest = { size?: (string | null); additionalInfo?: (string | null); imageUrl?: (string | null); + images?: (Array | null); }; diff --git a/src/client/models/ProductImageSchema.ts b/src/client/models/ProductImageSchema.ts new file mode 100644 index 0000000..6ce7da2 --- /dev/null +++ b/src/client/models/ProductImageSchema.ts @@ -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; +}; + diff --git a/src/client/models/ProductSchema.ts b/src/client/models/ProductSchema.ts index a520df9..9754752 100644 --- a/src/client/models/ProductSchema.ts +++ b/src/client/models/ProductSchema.ts @@ -3,6 +3,7 @@ /* tslint:disable */ /* eslint-disable */ import type { BarcodeTemplateSchema } from './BarcodeTemplateSchema'; +import type { ProductImageSchema } from './ProductImageSchema'; export type ProductSchema = { name: string; article?: (string | null); @@ -15,6 +16,7 @@ export type ProductSchema = { size?: (string | null); additionalInfo?: (string | null); imageUrl?: (string | null); + images?: (Array | null); id: number; }; diff --git a/src/client/services/ProductService.ts b/src/client/services/ProductService.ts index 7076184..ec89585 100644 --- a/src/client/services/ProductService.ts +++ b/src/client/services/ProductService.ts @@ -3,6 +3,8 @@ /* tslint:disable */ /* eslint-disable */ 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 { GetProductBarcodeResponse } from '../models/GetProductBarcodeResponse'; 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 { + return __request(OpenAPI, { + method: 'POST', + url: '/product/barcode/get-pdf', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } /** * Upload Product Image * @returns ProductUploadImageResponse Successful Response diff --git a/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx b/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx index f91f7bc..e0dca2f 100644 --- a/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx +++ b/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx @@ -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 = ({ diff --git a/src/shared/lib/utils.ts b/src/shared/lib/utils.ts index fe5567b..5ee2fe3 100644 --- a/src/shared/lib/utils.ts +++ b/src/shared/lib/utils.ts @@ -50,4 +50,25 @@ export const IMAGE_MIME_TYPES = [ export const isNilOrEmptyString = (value: unknown): value is null | undefined | '' => { return isNil(value) || (typeof value === 'string' && value.trim() === ''); -} \ No newline at end of file +} + +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); +}