From d927da46dfe8a95ea821e127f94db6841cc3ffa0 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Tue, 16 Sep 2025 18:13:35 +0400 Subject: [PATCH] feat: adding services kit to deal --- src/lib/client/@tanstack/react-query.gen.ts | 154 ++++++++++++------ src/lib/client/sdk.gen.ts | 86 +++++++--- src/lib/client/types.gen.ts | 104 +++++++++--- src/lib/client/zod.gen.ts | 48 ++++-- .../components/ServicesActions.tsx | 46 ++++-- 5 files changed, 305 insertions(+), 133 deletions(-) diff --git a/src/lib/client/@tanstack/react-query.gen.ts b/src/lib/client/@tanstack/react-query.gen.ts index bd9e7e5..855d22c 100644 --- a/src/lib/client/@tanstack/react-query.gen.ts +++ b/src/lib/client/@tanstack/react-query.gen.ts @@ -9,6 +9,7 @@ import { import type { AxiosError } from "axios"; import { client as _heyApiClient } from "../client.gen"; import { + addKitToDeal, addKitToDealProduct, createBoard, createDeal, @@ -54,9 +55,12 @@ import { type Options, } from "../sdk.gen"; import type { + AddKitToDealData, + AddKitToDealError, AddKitToDealProductData, AddKitToDealProductError, AddKitToDealProductResponse, + AddKitToDealResponse, CreateBoardData, CreateBoardError, CreateBoardResponse2, @@ -932,57 +936,6 @@ export const updateDealProductMutation = ( return mutationOptions; }; -export const addKitToDealProductQueryKey = ( - options: Options -) => createQueryKey("addKitToDealProduct", options); - -/** - * Add Kit To Deal Product - */ -export const addKitToDealProductOptions = ( - options: Options -) => { - return queryOptions({ - queryFn: async ({ queryKey, signal }) => { - const { data } = await addKitToDealProduct({ - ...options, - ...queryKey[0], - signal, - throwOnError: true, - }); - return data; - }, - queryKey: addKitToDealProductQueryKey(options), - }); -}; - -/** - * Add Kit To Deal Product - */ -export const addKitToDealProductMutation = ( - options?: Partial> -): UseMutationOptions< - AddKitToDealProductResponse, - AxiosError, - Options -> => { - const mutationOptions: UseMutationOptions< - AddKitToDealProductResponse, - AxiosError, - Options - > = { - mutationFn: async localOptions => { - const { data } = await addKitToDealProduct({ - ...options, - ...localOptions, - throwOnError: true, - }); - return data; - }, - }; - return mutationOptions; -}; - export const createDealProductServiceQueryKey = ( options: Options ) => createQueryKey("createDealProductService", options); @@ -1139,6 +1092,57 @@ export const duplicateProductServicesMutation = ( return mutationOptions; }; +export const addKitToDealProductQueryKey = ( + options: Options +) => createQueryKey("addKitToDealProduct", options); + +/** + * Add Kit To Deal Product + */ +export const addKitToDealProductOptions = ( + options: Options +) => { + return queryOptions({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await addKitToDealProduct({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + }); + return data; + }, + queryKey: addKitToDealProductQueryKey(options), + }); +}; + +/** + * Add Kit To Deal Product + */ +export const addKitToDealProductMutation = ( + options?: Partial> +): UseMutationOptions< + AddKitToDealProductResponse, + AxiosError, + Options +> => { + const mutationOptions: UseMutationOptions< + AddKitToDealProductResponse, + AxiosError, + Options + > = { + mutationFn: async localOptions => { + const { data } = await addKitToDealProduct({ + ...options, + ...localOptions, + throwOnError: true, + }); + return data; + }, + }; + return mutationOptions; +}; + export const getDealServicesQueryKey = ( options: Options ) => createQueryKey("getDealServices", options); @@ -1268,6 +1272,54 @@ export const updateDealServiceMutation = ( return mutationOptions; }; +export const addKitToDealQueryKey = (options: Options) => + createQueryKey("addKitToDeal", options); + +/** + * Add Kit To Deal Product + */ +export const addKitToDealOptions = (options: Options) => { + return queryOptions({ + queryFn: async ({ queryKey, signal }) => { + const { data } = await addKitToDeal({ + ...options, + ...queryKey[0], + signal, + throwOnError: true, + }); + return data; + }, + queryKey: addKitToDealQueryKey(options), + }); +}; + +/** + * Add Kit To Deal Product + */ +export const addKitToDealMutation = ( + options?: Partial> +): UseMutationOptions< + AddKitToDealResponse, + AxiosError, + Options +> => { + const mutationOptions: UseMutationOptions< + AddKitToDealResponse, + AxiosError, + Options + > = { + mutationFn: async localOptions => { + const { data } = await addKitToDeal({ + ...options, + ...localOptions, + throwOnError: true, + }); + return data; + }, + }; + return mutationOptions; +}; + export const getProductsQueryKey = (options?: Options) => createQueryKey("getProducts", options); diff --git a/src/lib/client/sdk.gen.ts b/src/lib/client/sdk.gen.ts index 4113260..39db30b 100644 --- a/src/lib/client/sdk.gen.ts +++ b/src/lib/client/sdk.gen.ts @@ -3,9 +3,12 @@ import type { Client, Options as ClientOptions, TDataShape } from "./client"; import { client as _heyApiClient } from "./client.gen"; import type { + AddKitToDealData, + AddKitToDealErrors, AddKitToDealProductData, AddKitToDealProductErrors, AddKitToDealProductResponses, + AddKitToDealResponses, CreateBoardData, CreateBoardErrors, CreateBoardResponses, @@ -127,8 +130,10 @@ import type { UpdateStatusResponses, } from "./types.gen"; import { + zAddKitToDealData, zAddKitToDealProductData, zAddKitToDealProductResponse, + zAddKitToDealResponse, zCreateBoardData, zCreateBoardResponse2, zCreateDealData, @@ -753,33 +758,6 @@ export const updateDealProduct = ( }); }; -/** - * Add Kit To Deal Product - */ -export const addKitToDealProduct = ( - options: Options -) => { - return (options.client ?? _heyApiClient).post< - AddKitToDealProductResponses, - AddKitToDealProductErrors, - ThrowOnError - >({ - requestValidator: async data => { - return await zAddKitToDealProductData.parseAsync(data); - }, - responseType: "json", - responseValidator: async data => { - return await zAddKitToDealProductResponse.parseAsync(data); - }, - url: "/modules/fulfillment-base/deal-product/add-services-kit", - ...options, - headers: { - "Content-Type": "application/json", - ...options.headers, - }, - }); -}; - /** * Create Deal Product Service */ @@ -884,6 +862,33 @@ export const duplicateProductServices = ( }); }; +/** + * Add Kit To Deal Product + */ +export const addKitToDealProduct = ( + options: Options +) => { + return (options.client ?? _heyApiClient).post< + AddKitToDealProductResponses, + AddKitToDealProductErrors, + ThrowOnError + >({ + requestValidator: async data => { + return await zAddKitToDealProductData.parseAsync(data); + }, + responseType: "json", + responseValidator: async data => { + return await zAddKitToDealProductResponse.parseAsync(data); + }, + url: "/modules/fulfillment-base/deal-product/add-services-kit", + ...options, + headers: { + "Content-Type": "application/json", + ...options.headers, + }, + }); +}; + /** * Get Deal Services */ @@ -984,6 +989,33 @@ export const updateDealService = ( }); }; +/** + * Add Kit To Deal Product + */ +export const addKitToDeal = ( + options: Options +) => { + return (options.client ?? _heyApiClient).post< + AddKitToDealResponses, + AddKitToDealErrors, + ThrowOnError + >({ + requestValidator: async data => { + return await zAddKitToDealData.parseAsync(data); + }, + responseType: "json", + responseValidator: async data => { + return await zAddKitToDealResponse.parseAsync(data); + }, + url: "/modules/fulfillment-base/deal-service/add-services-kit", + ...options, + headers: { + "Content-Type": "application/json", + ...options.headers, + }, + }); +}; + /** * Get Products */ diff --git a/src/lib/client/types.gen.ts b/src/lib/client/types.gen.ts index fbfffc1..5a72ac2 100644 --- a/src/lib/client/types.gen.ts +++ b/src/lib/client/types.gen.ts @@ -453,6 +453,30 @@ export type CreateStatusSchema = { lexorank: string; }; +/** + * DealAddKitRequest + */ +export type DealAddKitRequest = { + /** + * Dealid + */ + dealId: number; + /** + * Kitid + */ + kitId: number; +}; + +/** + * DealAddKitResponse + */ +export type DealAddKitResponse = { + /** + * Message + */ + message: string; +}; + /** * DealProductAddKitRequest */ @@ -2071,33 +2095,6 @@ export type UpdateDealProductResponses = { export type UpdateDealProductResponse2 = UpdateDealProductResponses[keyof UpdateDealProductResponses]; -export type AddKitToDealProductData = { - body: DealProductAddKitRequest; - path?: never; - query?: never; - url: "/modules/fulfillment-base/deal-product/add-services-kit"; -}; - -export type AddKitToDealProductErrors = { - /** - * Validation Error - */ - 422: HttpValidationError; -}; - -export type AddKitToDealProductError = - AddKitToDealProductErrors[keyof AddKitToDealProductErrors]; - -export type AddKitToDealProductResponses = { - /** - * Successful Response - */ - 200: DealProductAddKitResponse; -}; - -export type AddKitToDealProductResponse = - AddKitToDealProductResponses[keyof AddKitToDealProductResponses]; - export type CreateDealProductServiceData = { body: CreateProductServiceRequest; path?: never; @@ -2232,6 +2229,33 @@ export type DuplicateProductServicesResponses = { export type DuplicateProductServicesResponse = DuplicateProductServicesResponses[keyof DuplicateProductServicesResponses]; +export type AddKitToDealProductData = { + body: DealProductAddKitRequest; + path?: never; + query?: never; + url: "/modules/fulfillment-base/deal-product/add-services-kit"; +}; + +export type AddKitToDealProductErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type AddKitToDealProductError = + AddKitToDealProductErrors[keyof AddKitToDealProductErrors]; + +export type AddKitToDealProductResponses = { + /** + * Successful Response + */ + 200: DealProductAddKitResponse; +}; + +export type AddKitToDealProductResponse = + AddKitToDealProductResponses[keyof AddKitToDealProductResponses]; + export type GetDealServicesData = { body?: never; path: { @@ -2363,6 +2387,32 @@ export type UpdateDealServiceResponses = { export type UpdateDealServiceResponse2 = UpdateDealServiceResponses[keyof UpdateDealServiceResponses]; +export type AddKitToDealData = { + body: DealAddKitRequest; + path?: never; + query?: never; + url: "/modules/fulfillment-base/deal-service/add-services-kit"; +}; + +export type AddKitToDealErrors = { + /** + * Validation Error + */ + 422: HttpValidationError; +}; + +export type AddKitToDealError = AddKitToDealErrors[keyof AddKitToDealErrors]; + +export type AddKitToDealResponses = { + /** + * Successful Response + */ + 200: DealAddKitResponse; +}; + +export type AddKitToDealResponse = + AddKitToDealResponses[keyof AddKitToDealResponses]; + export type GetProductsData = { body?: never; path?: never; diff --git a/src/lib/client/zod.gen.ts b/src/lib/client/zod.gen.ts index b36237e..c1f98d1 100644 --- a/src/lib/client/zod.gen.ts +++ b/src/lib/client/zod.gen.ts @@ -402,6 +402,21 @@ export const zCreateStatusResponse = z.object({ entity: zStatusSchema, }); +/** + * DealAddKitRequest + */ +export const zDealAddKitRequest = z.object({ + dealId: z.int(), + kitId: z.int(), +}); + +/** + * DealAddKitResponse + */ +export const zDealAddKitResponse = z.object({ + message: z.string(), +}); + /** * DealProductAddKitRequest */ @@ -1118,17 +1133,6 @@ export const zUpdateDealProductData = z.object({ */ export const zUpdateDealProductResponse2 = zUpdateDealProductResponse; -export const zAddKitToDealProductData = z.object({ - body: zDealProductAddKitRequest, - path: z.optional(z.never()), - query: z.optional(z.never()), -}); - -/** - * Successful Response - */ -export const zAddKitToDealProductResponse = zDealProductAddKitResponse; - export const zCreateDealProductServiceData = z.object({ body: zCreateProductServiceRequest, path: z.optional(z.never()), @@ -1182,6 +1186,17 @@ export const zDuplicateProductServicesData = z.object({ export const zDuplicateProductServicesResponse = zProductServicesDuplicateResponse; +export const zAddKitToDealProductData = z.object({ + body: zDealProductAddKitRequest, + path: z.optional(z.never()), + query: z.optional(z.never()), +}); + +/** + * Successful Response + */ +export const zAddKitToDealProductResponse = zDealProductAddKitResponse; + export const zGetDealServicesData = z.object({ body: z.optional(z.never()), path: z.object({ @@ -1234,6 +1249,17 @@ export const zUpdateDealServiceData = z.object({ */ export const zUpdateDealServiceResponse2 = zUpdateDealServiceResponse; +export const zAddKitToDealData = z.object({ + body: zDealAddKitRequest, + path: z.optional(z.never()), + query: z.optional(z.never()), +}); + +/** + * Successful Response + */ +export const zAddKitToDealResponse = zDealAddKitResponse; + export const zGetProductsData = z.object({ body: z.optional(z.never()), path: z.optional(z.never()), diff --git a/src/modules/dealModules/dealEditorTabs/FulfillmentBaseTab/components/DealServicesTable/components/ServicesActions.tsx b/src/modules/dealModules/dealEditorTabs/FulfillmentBaseTab/components/DealServicesTable/components/ServicesActions.tsx index 01395eb..a86a385 100644 --- a/src/modules/dealModules/dealEditorTabs/FulfillmentBaseTab/components/DealServicesTable/components/ServicesActions.tsx +++ b/src/modules/dealModules/dealEditorTabs/FulfillmentBaseTab/components/DealServicesTable/components/ServicesActions.tsx @@ -1,6 +1,8 @@ import { Button, Flex, rem } from "@mantine/core"; import { modals } from "@mantine/modals"; +import { addKitToDeal, ServicesKitSchema } from "@/lib/client"; import { useFulfillmentBaseContext } from "@/modules/dealModules/dealEditorTabs/FulfillmentBaseTab/contexts/FulfillmentBaseContext"; +import { ServiceType } from "@/modules/dealModules/dealEditorTabs/FulfillmentBaseTab/types/service"; const ServicesActions = () => { const { dealServicesList, dealServicesCrud, deal } = @@ -22,17 +24,27 @@ const ServicesActions = () => { }); }; - // const onAddKitClick = () => { - // if (!onKitAdd) return; - // modals.openContextModal({ - // modal: "servicesKitSelectModal", - // innerProps: { - // onSelect: onKitAdd, - // serviceType: ServiceType.DEAL_SERVICE, - // }, - // withCloseButton: false, - // }); - // }; + const onServicesKitAdd = (servicesKit: ServicesKitSchema) => { + addKitToDeal({ + body: { + dealId: deal.id, + kitId: servicesKit.id, + }, + }) + .then(() => dealServicesList.refetch()) + .catch(err => console.error(err)); + }; + + const onAddKitClick = () => { + modals.openContextModal({ + modal: "servicesKitSelectModal", + innerProps: { + onSelect: onServicesKitAdd, + serviceType: ServiceType.DEAL_SERVICE, + }, + withCloseButton: false, + }); + }; return ( { variant={"default"}> Добавить услугу - {/**/} - {/* Добавить набор услуг*/} - {/**/} + ); };