fix: fixed deal module attributes refetch after module editing
This commit is contained in:
@ -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<HttpValidationError>) => {
|
||||
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();
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@ -1356,12 +1356,8 @@ export const removeAttributeFromModule = <ThrowOnError extends boolean = false>(
|
||||
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 = <ThrowOnError extends boolean = false>(
|
||||
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,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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()),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user