From fd5e878c29ae927080566473a49e2fe37e2aef28 Mon Sep 17 00:00:00 2001 From: AlexSserb Date: Sun, 2 Nov 2025 11:26:17 +0400 Subject: [PATCH] fix: fixed deal module attributes refetch after module editing --- .../[moduleId]/hooks/useAttributesActions.tsx | 25 +++++++- src/lib/client/sdk.gen.ts | 12 +--- src/lib/client/types.gen.ts | 58 ++++++++----------- src/lib/client/zod.gen.ts | 30 ++++------ 4 files changed, 59 insertions(+), 66 deletions(-) diff --git a/src/app/module-editor/[moduleId]/hooks/useAttributesActions.tsx b/src/app/module-editor/[moduleId]/hooks/useAttributesActions.tsx index 48f376c..924aa51 100644 --- a/src/app/module-editor/[moduleId]/hooks/useAttributesActions.tsx +++ b/src/app/module-editor/[moduleId]/hooks/useAttributesActions.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { useMutation } from "@tanstack/react-query"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; import { AxiosError } from "axios"; import { Text } from "@mantine/core"; import { modals } from "@mantine/modals"; @@ -38,6 +38,8 @@ const useAttributesActions = ({ refetchModule, refetchAttributes, }: Props): AttributesActions => { + const queryClient = useQueryClient(); + const onError = (error: AxiosError) => { console.error(error); notifications.error({ @@ -55,6 +57,24 @@ const useAttributesActions = ({ onError, }); + const removeGetDealModuleAttrQuery = () => { + if (!module) return; + + queryClient.removeQueries({ + predicate: query => { + const key = query.queryKey[0] as { + _id?: string; + path?: { moduleId?: number }; + }; + const isMatch = + key?._id === "getDealModuleAttributes" && + key?.path?.moduleId === module.id; + if (isMatch) console.log(isMatch); + return isMatch; + }, + }); + }; + const toggleAttributeInModule = ( attribute: AttributeSchema, isAdding: boolean @@ -66,7 +86,7 @@ const useAttributesActions = ({ mutation.mutate( { - body: { + path: { moduleId: module.id, attributeId: attribute.id, }, @@ -76,6 +96,7 @@ const useAttributesActions = ({ notifications.success({ message }); refetchModule(); refetchAttributes(); + removeGetDealModuleAttrQuery(); }, } ); diff --git a/src/lib/client/sdk.gen.ts b/src/lib/client/sdk.gen.ts index c0b1ddc..c1427ea 100644 --- a/src/lib/client/sdk.gen.ts +++ b/src/lib/client/sdk.gen.ts @@ -1356,12 +1356,8 @@ export const removeAttributeFromModule = ( responseValidator: async data => { return await zRemoveAttributeFromModuleResponse.parseAsync(data); }, - url: "/crm/v1/module/attribute", + url: "/crm/v1/module/{moduleId}/attribute/{attributeId}", ...options, - headers: { - "Content-Type": "application/json", - ...options.headers, - }, }); }; @@ -1383,12 +1379,8 @@ export const addAttributeToModule = ( responseValidator: async data => { return await zAddAttributeToModuleResponse.parseAsync(data); }, - url: "/crm/v1/module/attribute", + url: "/crm/v1/module/{moduleId}/attribute/{attributeId}", ...options, - headers: { - "Content-Type": "application/json", - ...options.headers, - }, }); }; diff --git a/src/lib/client/types.gen.ts b/src/lib/client/types.gen.ts index 5b5532b..8259f31 100644 --- a/src/lib/client/types.gen.ts +++ b/src/lib/client/types.gen.ts @@ -1,19 +1,5 @@ // This file is auto-generated by @hey-api/openapi-ts -/** - * AddAttributeRequest - */ -export type AddAttributeRequest = { - /** - * Attributeid - */ - attributeId: number; - /** - * Moduleid - */ - moduleId: number; -}; - /** * AddAttributeResponse */ @@ -1282,20 +1268,6 @@ export type DealTagSchema = { tagColor: DealTagColorSchema; }; -/** - * DeleteAttributeRequest - */ -export type DeleteAttributeRequest = { - /** - * Attributeid - */ - attributeId: number; - /** - * Moduleid - */ - moduleId: number; -}; - /** * DeleteAttributeResponse */ @@ -4168,10 +4140,19 @@ export type DeleteModuleResponse2 = DeleteModuleResponses[keyof DeleteModuleResponses]; export type RemoveAttributeFromModuleData = { - body: DeleteAttributeRequest; - path?: never; + body?: never; + path: { + /** + * Moduleid + */ + moduleId: number; + /** + * Attributeid + */ + attributeId: number; + }; query?: never; - url: "/crm/v1/module/attribute"; + url: "/crm/v1/module/{moduleId}/attribute/{attributeId}"; }; export type RemoveAttributeFromModuleErrors = { @@ -4195,10 +4176,19 @@ export type RemoveAttributeFromModuleResponse = RemoveAttributeFromModuleResponses[keyof RemoveAttributeFromModuleResponses]; export type AddAttributeToModuleData = { - body: AddAttributeRequest; - path?: never; + body?: never; + path: { + /** + * Moduleid + */ + moduleId: number; + /** + * Attributeid + */ + attributeId: number; + }; query?: never; - url: "/crm/v1/module/attribute"; + url: "/crm/v1/module/{moduleId}/attribute/{attributeId}"; }; export type AddAttributeToModuleErrors = { diff --git a/src/lib/client/zod.gen.ts b/src/lib/client/zod.gen.ts index 68bd408..c3bb95e 100644 --- a/src/lib/client/zod.gen.ts +++ b/src/lib/client/zod.gen.ts @@ -2,14 +2,6 @@ import { z } from "zod"; -/** - * AddAttributeRequest - */ -export const zAddAttributeRequest = z.object({ - attributeId: z.int(), - moduleId: z.int(), -}); - /** * AddAttributeResponse */ @@ -885,14 +877,6 @@ export const zDealProductAddKitResponse = z.object({ message: z.string(), }); -/** - * DeleteAttributeRequest - */ -export const zDeleteAttributeRequest = z.object({ - attributeId: z.int(), - moduleId: z.int(), -}); - /** * DeleteAttributeResponse */ @@ -2295,8 +2279,11 @@ export const zDeleteModuleData = z.object({ export const zDeleteModuleResponse2 = zDeleteModuleResponse; export const zRemoveAttributeFromModuleData = z.object({ - body: zDeleteAttributeRequest, - path: z.optional(z.never()), + body: z.optional(z.never()), + path: z.object({ + moduleId: z.int(), + attributeId: z.int(), + }), query: z.optional(z.never()), }); @@ -2306,8 +2293,11 @@ export const zRemoveAttributeFromModuleData = z.object({ export const zRemoveAttributeFromModuleResponse = zDeleteAttributeResponse; export const zAddAttributeToModuleData = z.object({ - body: zAddAttributeRequest, - path: z.optional(z.never()), + body: z.optional(z.never()), + path: z.object({ + moduleId: z.int(), + attributeId: z.int(), + }), query: z.optional(z.never()), });