From 2d1fdf1ad9853a778d02bce4cd4f8159d4872a6f Mon Sep 17 00:00:00 2001 From: fakz9 Date: Fri, 12 Apr 2024 07:35:41 +0300 Subject: [PATCH] crap --- package.json | 4 + src/api/product/useGetProductById.tsx | 11 + src/client/index.ts | 18 ++ src/client/models/DealAddProductRequest.ts | 10 + src/client/models/DealAddProductResponse.ts | 9 + src/client/models/DealDeleteProductRequest.ts | 9 + .../models/DealDeleteProductResponse.ts | 9 + .../models/DealDeleteProductsRequest.ts | 9 + .../models/DealDeleteProductsResponse.ts | 9 + src/client/models/DealGeneralInfoSchema.ts | 10 + src/client/models/DealSchema.ts | 6 + src/client/models/DealStatusHistorySchema.ts | 13 ++ .../models/DealUpdateGeneralInfoRequest.ts | 10 + .../models/DealUpdateGeneralInfoResponse.ts | 9 + .../DealUpdateProductQuantityRequest.ts | 10 + .../DealUpdateProductQuantityResponse.ts | 9 + src/client/models/ProductAddBarcodeRequest.ts | 9 + .../models/ProductAddBarcodeResponse.ts | 9 + .../models/ProductExistsBarcodeResponse.ts | 8 + .../models/ProductGenerateBarcodeRequest.ts | 8 + .../models/ProductGenerateBarcodeResponse.ts | 10 + src/client/models/UserSchema.ts | 11 + src/client/services/DealService.ts | 140 ++++++++++-- src/client/services/ProductService.ts | 91 ++++++++ .../AddBarcodeModal/AddBarcodeModal.tsx | 63 ++++++ .../PrintBarcodeModal.module.css | 9 + .../PrintBarcodeModal/PrintBarcodeModal.tsx | 132 ++++++++++++ src/modals/modals.ts | 6 +- src/pages/ClientsPage/ClientsPage.tsx | 10 +- .../modals/BaseFormModal/BaseFormModal.tsx | 2 - .../DealProductsTable/DealProductsTable.tsx | 81 +++++-- .../components/DealProductsTable/columns.tsx | 57 ++++- .../DealStatusChangeTable.tsx | 28 +++ .../DealStatusChangeTable/columns.tsx | 29 +++ .../drawers/DealEditDrawer/DealEditDrawer.tsx | 201 ++++++++++++++++-- .../tabs/DealEditDrawerGeneralTab.tsx | 148 +++++++++++++ .../LeadsPage/modals/AddDealProductModal.tsx | 7 +- .../ProductsTable/ProductsTable.tsx | 19 +- src/pages/ProductsPage/ui/ProductsPage.tsx | 7 +- src/routes/test.lazy.tsx | 35 ++- src/shared/enums/DealStatus.ts | 9 + 41 files changed, 1199 insertions(+), 85 deletions(-) create mode 100644 src/api/product/useGetProductById.tsx create mode 100644 src/client/models/DealAddProductRequest.ts create mode 100644 src/client/models/DealAddProductResponse.ts create mode 100644 src/client/models/DealDeleteProductRequest.ts create mode 100644 src/client/models/DealDeleteProductResponse.ts create mode 100644 src/client/models/DealDeleteProductsRequest.ts create mode 100644 src/client/models/DealDeleteProductsResponse.ts create mode 100644 src/client/models/DealGeneralInfoSchema.ts create mode 100644 src/client/models/DealStatusHistorySchema.ts create mode 100644 src/client/models/DealUpdateGeneralInfoRequest.ts create mode 100644 src/client/models/DealUpdateGeneralInfoResponse.ts create mode 100644 src/client/models/DealUpdateProductQuantityRequest.ts create mode 100644 src/client/models/DealUpdateProductQuantityResponse.ts create mode 100644 src/client/models/ProductAddBarcodeRequest.ts create mode 100644 src/client/models/ProductAddBarcodeResponse.ts create mode 100644 src/client/models/ProductExistsBarcodeResponse.ts create mode 100644 src/client/models/ProductGenerateBarcodeRequest.ts create mode 100644 src/client/models/ProductGenerateBarcodeResponse.ts create mode 100644 src/client/models/UserSchema.ts create mode 100644 src/modals/AddBarcodeModal/AddBarcodeModal.tsx create mode 100644 src/modals/PrintBarcodeModal/PrintBarcodeModal.module.css create mode 100644 src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx create mode 100644 src/pages/LeadsPage/components/DealStatusChangeTable/DealStatusChangeTable.tsx create mode 100644 src/pages/LeadsPage/components/DealStatusChangeTable/columns.tsx create mode 100644 src/pages/LeadsPage/drawers/DealEditDrawer/tabs/DealEditDrawerGeneralTab.tsx diff --git a/package.json b/package.json index 27f4c2a..163673f 100644 --- a/package.json +++ b/package.json @@ -30,16 +30,20 @@ "clsx": "^2.1.0", "dayjs": "^1.11.10", "dot-object": "^2.1.4", + "lodash": "^4.17.21", "mantine-form-zod-resolver": "^1.1.0", "mantine-react-table": "^2.0.0-beta.0", "react": "^18.2.0", + "react-barcode": "^1.5.1", "react-dom": "^18.2.0", "react-redux": "^9.1.0", + "react-to-print": "^2.15.1", "reactflow": "^11.10.4", "zod": "^3.22.4" }, "devDependencies": { "@types/dot-object": "^2", + "@types/lodash": "^4", "@types/react": "^18.2.56", "@types/react-dom": "^18.2.19", "@typescript-eslint/eslint-plugin": "^7.0.2", diff --git a/src/api/product/useGetProductById.tsx b/src/api/product/useGetProductById.tsx new file mode 100644 index 0000000..978f962 --- /dev/null +++ b/src/api/product/useGetProductById.tsx @@ -0,0 +1,11 @@ +import {ProductService} from "../../client"; +import {useQuery} from "@tanstack/react-query"; + +export const useGetProductById = (id: number) => { + const {data, error, isLoading, refetch} = useQuery({ + queryKey: ['getProductById', id], + queryFn: () => ProductService.getProductById({productId: id}), + select: (data) => data + }); + return {product: data, error, isLoading, refetch} +} \ No newline at end of file diff --git a/src/client/index.ts b/src/client/index.ts index 60327c4..32c861a 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -19,6 +19,8 @@ export type { ClientSchema } from './models/ClientSchema'; export type { ClientUpdateDetailsRequest } from './models/ClientUpdateDetailsRequest'; export type { ClientUpdateRequest } from './models/ClientUpdateRequest'; export type { ClientUpdateResponse } from './models/ClientUpdateResponse'; +export type { DealAddProductRequest } from './models/DealAddProductRequest'; +export type { DealAddProductResponse } from './models/DealAddProductResponse'; export type { DealAddServiceRequest } from './models/DealAddServiceRequest'; export type { DealAddServiceResponse } from './models/DealAddServiceResponse'; export type { DealAddServicesRequest } from './models/DealAddServicesRequest'; @@ -26,26 +28,41 @@ export type { DealAddServicesResponse } from './models/DealAddServicesResponse'; export type { DealChangeStatusRequest } from './models/DealChangeStatusRequest'; export type { DealChangeStatusResponse } from './models/DealChangeStatusResponse'; export type { DealCreateRequest } from './models/DealCreateRequest'; +export type { DealDeleteProductRequest } from './models/DealDeleteProductRequest'; +export type { DealDeleteProductResponse } from './models/DealDeleteProductResponse'; +export type { DealDeleteProductsRequest } from './models/DealDeleteProductsRequest'; +export type { DealDeleteProductsResponse } from './models/DealDeleteProductsResponse'; export type { DealDeleteServiceRequest } from './models/DealDeleteServiceRequest'; export type { DealDeleteServiceResponse } from './models/DealDeleteServiceResponse'; export type { DealDeleteServicesRequest } from './models/DealDeleteServicesRequest'; export type { DealDeleteServicesResponse } from './models/DealDeleteServicesResponse'; +export type { DealGeneralInfoSchema } from './models/DealGeneralInfoSchema'; export type { DealGetAllResponse } from './models/DealGetAllResponse'; export type { DealProductSchema } from './models/DealProductSchema'; export type { DealQuickCreateRequest } from './models/DealQuickCreateRequest'; export type { DealQuickCreateResponse } from './models/DealQuickCreateResponse'; export type { DealSchema } from './models/DealSchema'; export type { DealServiceSchema } from './models/DealServiceSchema'; +export type { DealStatusHistorySchema } from './models/DealStatusHistorySchema'; export type { DealSummary } from './models/DealSummary'; export type { DealSummaryResponse } from './models/DealSummaryResponse'; +export type { DealUpdateGeneralInfoRequest } from './models/DealUpdateGeneralInfoRequest'; +export type { DealUpdateGeneralInfoResponse } from './models/DealUpdateGeneralInfoResponse'; +export type { DealUpdateProductQuantityRequest } from './models/DealUpdateProductQuantityRequest'; +export type { DealUpdateProductQuantityResponse } from './models/DealUpdateProductQuantityResponse'; export type { DealUpdateServiceQuantityRequest } from './models/DealUpdateServiceQuantityRequest'; export type { DealUpdateServiceQuantityResponse } from './models/DealUpdateServiceQuantityResponse'; export type { HTTPValidationError } from './models/HTTPValidationError'; export type { PaginationInfoSchema } from './models/PaginationInfoSchema'; +export type { ProductAddBarcodeRequest } from './models/ProductAddBarcodeRequest'; +export type { ProductAddBarcodeResponse } from './models/ProductAddBarcodeResponse'; export type { ProductCreateRequest } from './models/ProductCreateRequest'; export type { ProductCreateResponse } from './models/ProductCreateResponse'; export type { ProductDeleteRequest } from './models/ProductDeleteRequest'; export type { ProductDeleteResponse } from './models/ProductDeleteResponse'; +export type { ProductExistsBarcodeResponse } from './models/ProductExistsBarcodeResponse'; +export type { ProductGenerateBarcodeRequest } from './models/ProductGenerateBarcodeRequest'; +export type { ProductGenerateBarcodeResponse } from './models/ProductGenerateBarcodeResponse'; export type { ProductGetResponse } from './models/ProductGetResponse'; export type { ProductSchema } from './models/ProductSchema'; export type { ProductUpdateRequest } from './models/ProductUpdateRequest'; @@ -58,6 +75,7 @@ export type { ServiceCreateResponse } from './models/ServiceCreateResponse'; export type { ServiceGetAllCategoriesResponse } from './models/ServiceGetAllCategoriesResponse'; export type { ServiceGetAllResponse } from './models/ServiceGetAllResponse'; export type { ServiceSchema } from './models/ServiceSchema'; +export type { UserSchema } from './models/UserSchema'; export type { ValidationError } from './models/ValidationError'; export { AuthService } from './services/AuthService'; diff --git a/src/client/models/DealAddProductRequest.ts b/src/client/models/DealAddProductRequest.ts new file mode 100644 index 0000000..a338f85 --- /dev/null +++ b/src/client/models/DealAddProductRequest.ts @@ -0,0 +1,10 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealAddProductRequest = { + dealId: number; + productId: number; + quantity: number; +}; + diff --git a/src/client/models/DealAddProductResponse.ts b/src/client/models/DealAddProductResponse.ts new file mode 100644 index 0000000..7509c5c --- /dev/null +++ b/src/client/models/DealAddProductResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealAddProductResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/models/DealDeleteProductRequest.ts b/src/client/models/DealDeleteProductRequest.ts new file mode 100644 index 0000000..e819375 --- /dev/null +++ b/src/client/models/DealDeleteProductRequest.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealDeleteProductRequest = { + dealId: number; + productId: number; +}; + diff --git a/src/client/models/DealDeleteProductResponse.ts b/src/client/models/DealDeleteProductResponse.ts new file mode 100644 index 0000000..f4db1c5 --- /dev/null +++ b/src/client/models/DealDeleteProductResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealDeleteProductResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/models/DealDeleteProductsRequest.ts b/src/client/models/DealDeleteProductsRequest.ts new file mode 100644 index 0000000..56cf861 --- /dev/null +++ b/src/client/models/DealDeleteProductsRequest.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealDeleteProductsRequest = { + dealId: number; + productIds: Array; +}; + diff --git a/src/client/models/DealDeleteProductsResponse.ts b/src/client/models/DealDeleteProductsResponse.ts new file mode 100644 index 0000000..855ecb4 --- /dev/null +++ b/src/client/models/DealDeleteProductsResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealDeleteProductsResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/models/DealGeneralInfoSchema.ts b/src/client/models/DealGeneralInfoSchema.ts new file mode 100644 index 0000000..5d8eddb --- /dev/null +++ b/src/client/models/DealGeneralInfoSchema.ts @@ -0,0 +1,10 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealGeneralInfoSchema = { + name: string; + isDeleted: boolean; + isCompleted: boolean; +}; + diff --git a/src/client/models/DealSchema.ts b/src/client/models/DealSchema.ts index 777317f..e304f4d 100644 --- a/src/client/models/DealSchema.ts +++ b/src/client/models/DealSchema.ts @@ -2,8 +2,10 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ClientSchema } from './ClientSchema'; import type { DealProductSchema } from './DealProductSchema'; import type { DealServiceSchema } from './DealServiceSchema'; +import type { DealStatusHistorySchema } from './DealStatusHistorySchema'; export type DealSchema = { id: number; name: string; @@ -12,5 +14,9 @@ export type DealSchema = { currentStatus: number; services: Array; products: Array; + statusHistory: Array; + isDeleted: boolean; + isCompleted: boolean; + client: ClientSchema; }; diff --git a/src/client/models/DealStatusHistorySchema.ts b/src/client/models/DealStatusHistorySchema.ts new file mode 100644 index 0000000..6fe5349 --- /dev/null +++ b/src/client/models/DealStatusHistorySchema.ts @@ -0,0 +1,13 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { UserSchema } from './UserSchema'; +export type DealStatusHistorySchema = { + user: UserSchema; + changedAt: string; + fromStatus: number; + toStatus: number; + nextStatusDeadline: string; +}; + diff --git a/src/client/models/DealUpdateGeneralInfoRequest.ts b/src/client/models/DealUpdateGeneralInfoRequest.ts new file mode 100644 index 0000000..d3ed77a --- /dev/null +++ b/src/client/models/DealUpdateGeneralInfoRequest.ts @@ -0,0 +1,10 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { DealGeneralInfoSchema } from './DealGeneralInfoSchema'; +export type DealUpdateGeneralInfoRequest = { + dealId: number; + data: DealGeneralInfoSchema; +}; + diff --git a/src/client/models/DealUpdateGeneralInfoResponse.ts b/src/client/models/DealUpdateGeneralInfoResponse.ts new file mode 100644 index 0000000..ea4bc2d --- /dev/null +++ b/src/client/models/DealUpdateGeneralInfoResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealUpdateGeneralInfoResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/models/DealUpdateProductQuantityRequest.ts b/src/client/models/DealUpdateProductQuantityRequest.ts new file mode 100644 index 0000000..87a6d5a --- /dev/null +++ b/src/client/models/DealUpdateProductQuantityRequest.ts @@ -0,0 +1,10 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealUpdateProductQuantityRequest = { + dealId: number; + productId: number; + quantity: number; +}; + diff --git a/src/client/models/DealUpdateProductQuantityResponse.ts b/src/client/models/DealUpdateProductQuantityResponse.ts new file mode 100644 index 0000000..35adaf9 --- /dev/null +++ b/src/client/models/DealUpdateProductQuantityResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type DealUpdateProductQuantityResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/models/ProductAddBarcodeRequest.ts b/src/client/models/ProductAddBarcodeRequest.ts new file mode 100644 index 0000000..8dba148 --- /dev/null +++ b/src/client/models/ProductAddBarcodeRequest.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ProductAddBarcodeRequest = { + productId: number; + barcode: string; +}; + diff --git a/src/client/models/ProductAddBarcodeResponse.ts b/src/client/models/ProductAddBarcodeResponse.ts new file mode 100644 index 0000000..008b714 --- /dev/null +++ b/src/client/models/ProductAddBarcodeResponse.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ProductAddBarcodeResponse = { + ok: boolean; + message: string; +}; + diff --git a/src/client/models/ProductExistsBarcodeResponse.ts b/src/client/models/ProductExistsBarcodeResponse.ts new file mode 100644 index 0000000..8a0b103 --- /dev/null +++ b/src/client/models/ProductExistsBarcodeResponse.ts @@ -0,0 +1,8 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ProductExistsBarcodeResponse = { + exists: boolean; +}; + diff --git a/src/client/models/ProductGenerateBarcodeRequest.ts b/src/client/models/ProductGenerateBarcodeRequest.ts new file mode 100644 index 0000000..5b40cd0 --- /dev/null +++ b/src/client/models/ProductGenerateBarcodeRequest.ts @@ -0,0 +1,8 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ProductGenerateBarcodeRequest = { + productId: number; +}; + diff --git a/src/client/models/ProductGenerateBarcodeResponse.ts b/src/client/models/ProductGenerateBarcodeResponse.ts new file mode 100644 index 0000000..a90becc --- /dev/null +++ b/src/client/models/ProductGenerateBarcodeResponse.ts @@ -0,0 +1,10 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type ProductGenerateBarcodeResponse = { + ok: boolean; + message: string; + barcode: string; +}; + diff --git a/src/client/models/UserSchema.ts b/src/client/models/UserSchema.ts new file mode 100644 index 0000000..2feeee9 --- /dev/null +++ b/src/client/models/UserSchema.ts @@ -0,0 +1,11 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type UserSchema = { + id: number; + telegramId: number; + phoneNumber?: (string | null); + isAdmin: boolean; +}; + diff --git a/src/client/services/DealService.ts b/src/client/services/DealService.ts index 7f9e8df..5902b97 100644 --- a/src/client/services/DealService.ts +++ b/src/client/services/DealService.ts @@ -2,6 +2,8 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { DealAddProductRequest } from '../models/DealAddProductRequest'; +import type { DealAddProductResponse } from '../models/DealAddProductResponse'; import type { DealAddServiceRequest } from '../models/DealAddServiceRequest'; import type { DealAddServiceResponse } from '../models/DealAddServiceResponse'; import type { DealAddServicesRequest } from '../models/DealAddServicesRequest'; @@ -9,6 +11,10 @@ import type { DealAddServicesResponse } from '../models/DealAddServicesResponse' import type { DealChangeStatusRequest } from '../models/DealChangeStatusRequest'; import type { DealChangeStatusResponse } from '../models/DealChangeStatusResponse'; import type { DealCreateRequest } from '../models/DealCreateRequest'; +import type { DealDeleteProductRequest } from '../models/DealDeleteProductRequest'; +import type { DealDeleteProductResponse } from '../models/DealDeleteProductResponse'; +import type { DealDeleteProductsRequest } from '../models/DealDeleteProductsRequest'; +import type { DealDeleteProductsResponse } from '../models/DealDeleteProductsResponse'; import type { DealDeleteServiceRequest } from '../models/DealDeleteServiceRequest'; import type { DealDeleteServiceResponse } from '../models/DealDeleteServiceResponse'; import type { DealDeleteServicesRequest } from '../models/DealDeleteServicesRequest'; @@ -18,6 +24,10 @@ import type { DealQuickCreateRequest } from '../models/DealQuickCreateRequest'; import type { DealQuickCreateResponse } from '../models/DealQuickCreateResponse'; import type { DealSchema } from '../models/DealSchema'; import type { DealSummaryResponse } from '../models/DealSummaryResponse'; +import type { DealUpdateGeneralInfoRequest } from '../models/DealUpdateGeneralInfoRequest'; +import type { DealUpdateGeneralInfoResponse } from '../models/DealUpdateGeneralInfoResponse'; +import type { DealUpdateProductQuantityRequest } from '../models/DealUpdateProductQuantityRequest'; +import type { DealUpdateProductQuantityResponse } from '../models/DealUpdateProductQuantityResponse'; import type { DealUpdateServiceQuantityRequest } from '../models/DealUpdateServiceQuantityRequest'; import type { DealUpdateServiceQuantityResponse } from '../models/DealUpdateServiceQuantityResponse'; import type { CancelablePromise } from '../core/CancelablePromise'; @@ -95,6 +105,58 @@ export class DealService { url: '/deal/summaries', }); } + /** + * Get All + * @returns DealGetAllResponse Successful Response + * @throws ApiError + */ + public static getAllDeals(): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/deal/get-all', + }); + } + /** + * Get Deal By Id + * @returns DealSchema Successful Response + * @throws ApiError + */ + public static getDealById({ + dealId, + }: { + dealId: number, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/deal/get/{deal_id}', + path: { + 'deal_id': dealId, + }, + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Update General Info + * @returns DealUpdateGeneralInfoResponse Successful Response + * @throws ApiError + */ + public static updateDealGeneralInfo({ + requestBody, + }: { + requestBody: DealUpdateGeneralInfoRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/deal/update-general-info', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } /** * Services Add * @returns DealAddServicesResponse Successful Response @@ -196,32 +258,80 @@ export class DealService { }); } /** - * Get All - * @returns DealGetAllResponse Successful Response + * Products Update + * @returns DealUpdateProductQuantityResponse Successful Response * @throws ApiError */ - public static getAllDeals(): CancelablePromise { + public static updateDealProductQuantity({ + requestBody, + }: { + requestBody: DealUpdateProductQuantityRequest, + }): CancelablePromise { return __request(OpenAPI, { - method: 'GET', - url: '/deal/get-all', + method: 'POST', + url: '/deal/products/update-quantity', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, }); } /** - * Get Deal By Id - * @returns DealSchema Successful Response + * Products Add + * @returns DealAddProductResponse Successful Response * @throws ApiError */ - public static getDealById({ - dealId, + public static addDealProduct({ + requestBody, }: { - dealId: number, - }): CancelablePromise { + requestBody: DealAddProductRequest, + }): CancelablePromise { return __request(OpenAPI, { - method: 'GET', - url: '/deal/get/{deal_id}', - path: { - 'deal_id': dealId, + method: 'POST', + url: '/deal/products/add', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, }, + }); + } + /** + * Products Delete + * @returns DealDeleteProductResponse Successful Response + * @throws ApiError + */ + public static deleteDealProduct({ + requestBody, + }: { + requestBody: DealDeleteProductRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/deal/products/delete', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Products Delete + * @returns DealDeleteProductsResponse Successful Response + * @throws ApiError + */ + public static deleteMultipleDealProducts({ + requestBody, + }: { + requestBody: DealDeleteProductsRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/deal/products/delete/multiple', + body: requestBody, + mediaType: 'application/json', errors: { 422: `Validation Error`, }, diff --git a/src/client/services/ProductService.ts b/src/client/services/ProductService.ts index 4ffeb3b..feb466e 100644 --- a/src/client/services/ProductService.ts +++ b/src/client/services/ProductService.ts @@ -2,11 +2,17 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ +import type { ProductAddBarcodeRequest } from '../models/ProductAddBarcodeRequest'; +import type { ProductAddBarcodeResponse } from '../models/ProductAddBarcodeResponse'; import type { ProductCreateRequest } from '../models/ProductCreateRequest'; import type { ProductCreateResponse } from '../models/ProductCreateResponse'; import type { ProductDeleteRequest } from '../models/ProductDeleteRequest'; import type { ProductDeleteResponse } from '../models/ProductDeleteResponse'; +import type { ProductExistsBarcodeResponse } from '../models/ProductExistsBarcodeResponse'; +import type { ProductGenerateBarcodeRequest } from '../models/ProductGenerateBarcodeRequest'; +import type { ProductGenerateBarcodeResponse } from '../models/ProductGenerateBarcodeResponse'; import type { ProductGetResponse } from '../models/ProductGetResponse'; +import type { ProductSchema } from '../models/ProductSchema'; import type { ProductUpdateRequest } from '../models/ProductUpdateRequest'; import type { ProductUpdateResponse } from '../models/ProductUpdateResponse'; import type { CancelablePromise } from '../core/CancelablePromise'; @@ -100,4 +106,89 @@ export class ProductService { }, }); } + /** + * Get Product By Id + * @returns ProductSchema Successful Response + * @throws ApiError + */ + public static getProductById({ + productId, + }: { + productId: number, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/product/get-by-id', + query: { + 'product_id': productId, + }, + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Add Product Barcode + * @returns ProductAddBarcodeResponse Successful Response + * @throws ApiError + */ + public static addProductBarcode({ + requestBody, + }: { + requestBody: ProductAddBarcodeRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/product/barcode/add', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Exists Product Barcode + * @returns ProductExistsBarcodeResponse Successful Response + * @throws ApiError + */ + public static existsProductBarcode({ + productId, + barcode, + }: { + productId: number, + barcode: string, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'GET', + url: '/product/barcode/exists', + query: { + 'product_id': productId, + 'barcode': barcode, + }, + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Generate Product Barcode + * @returns ProductGenerateBarcodeResponse Successful Response + * @throws ApiError + */ + public static generateProductBarcode({ + requestBody, + }: { + requestBody: ProductGenerateBarcodeRequest, + }): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/product/barcode/generate', + body: requestBody, + mediaType: 'application/json', + errors: { + 422: `Validation Error`, + }, + }); + } } diff --git a/src/modals/AddBarcodeModal/AddBarcodeModal.tsx b/src/modals/AddBarcodeModal/AddBarcodeModal.tsx new file mode 100644 index 0000000..6278e6e --- /dev/null +++ b/src/modals/AddBarcodeModal/AddBarcodeModal.tsx @@ -0,0 +1,63 @@ +import {ContextModalProps} from "@mantine/modals"; +import {Button, Flex, rem, TextInput} from "@mantine/core"; +import {useEffect, useState} from "react"; +import {ProductService} from "../../client"; + +type Props = { + productId: number; + onSubmit: (barcode: string) => void; +} +const PrintBarcodeModal = ({ + id, + context, + innerProps + }: ContextModalProps) => { + const {productId, onSubmit} = innerProps; + const [barcode, setBarcode] = useState(); + const [isBarcodeExist, setIsBarcodeExist] = useState(true); + + const getErrorMessage = () => { + if (!barcode) return "Штрихкод не может быть пустым"; + if (isBarcodeExist) return "Штрихкод уже существует"; + return undefined; + } + useEffect(() => { + if (!barcode) return; + ProductService.existsProductBarcode({ + productId: innerProps.productId, + barcode: barcode.trim() + }).then((response) => { + setIsBarcodeExist(response.exists); + }) + }, [productId, barcode]); + + const onSubmitClick = () => { + if (!barcode || isBarcodeExist) return; + onSubmit(barcode.trim()); + context.closeModal(id); + } + return ( + + setBarcode(event.currentTarget.value)} + + /> + + + ) +} + +export default PrintBarcodeModal; \ No newline at end of file diff --git a/src/modals/PrintBarcodeModal/PrintBarcodeModal.module.css b/src/modals/PrintBarcodeModal/PrintBarcodeModal.module.css new file mode 100644 index 0000000..265123a --- /dev/null +++ b/src/modals/PrintBarcodeModal/PrintBarcodeModal.module.css @@ -0,0 +1,9 @@ +.print-only { + display: none; +} + +@media print { + .print-only { + display: block; + } +} \ No newline at end of file diff --git a/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx b/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx new file mode 100644 index 0000000..3273ee1 --- /dev/null +++ b/src/modals/PrintBarcodeModal/PrintBarcodeModal.tsx @@ -0,0 +1,132 @@ +import {ContextModalProps, modals} from "@mantine/modals"; +import {Button, Divider, Flex, NumberInput, rem, Select, Spoiler} from "@mantine/core"; +import Barcode from "react-barcode"; +import {useEffect, useRef, useState} from "react"; +import {useReactToPrint} from "react-to-print"; +import {ProductService} from "../../client"; +import styles from "./PrintBarcodeModal.module.css"; +import {useGetProductById} from "../../api/product/useGetProductById.tsx"; +import {notifications} from "../../shared/lib/notifications.ts"; + +type Props = { + productId: number; + defaultQuantity?: number; +} +const PrintBarcodeModal = ({ + innerProps + }: ContextModalProps) => { + const {productId, defaultQuantity = 1} = innerProps; + const [quantity, setQuantity] = useState(defaultQuantity); + const [barcode, setBarcode] = useState() + + const {product, refetch} = useGetProductById(productId); + + const barcodeRef = useRef(null); + const handlePrint = useReactToPrint({ + content: () => barcodeRef.current + }); + + const onAdd = (newBarcode: string) => { + ProductService.addProductBarcode({requestBody: {productId, barcode: newBarcode}}) + .then(async ({ok, message}) => { + notifications.guess(ok, {message}); + }) + } + const onAddClick = () => { + if (!product) return; + modals.openContextModal({ + modal: "addBarcode", + title: 'Добавление штрихкода', + withCloseButton: true, + innerProps: { + productId: product.id, + onSubmit: onAdd + } + }) + } + + const onGenerateClick = () => { + if (!product) return; + ProductService.generateProductBarcode({requestBody: {productId}}) + .then(async ({ok, message, barcode}) => { + notifications.guess(ok, {message}); + if (!ok) return; + await refetch(); + setBarcode(barcode); + }) + } + useEffect(() => { + if (!product) return; + if (product.barcodes.length === 1) + setBarcode(product.barcodes[0]); + }, [product]); + return ( + <> + +