fix: fixed deal module attributes refetch after module editing
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { Text } from "@mantine/core";
|
import { Text } from "@mantine/core";
|
||||||
import { modals } from "@mantine/modals";
|
import { modals } from "@mantine/modals";
|
||||||
@ -38,6 +38,8 @@ const useAttributesActions = ({
|
|||||||
refetchModule,
|
refetchModule,
|
||||||
refetchAttributes,
|
refetchAttributes,
|
||||||
}: Props): AttributesActions => {
|
}: Props): AttributesActions => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const onError = (error: AxiosError<HttpValidationError>) => {
|
const onError = (error: AxiosError<HttpValidationError>) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
notifications.error({
|
notifications.error({
|
||||||
@ -55,6 +57,24 @@ const useAttributesActions = ({
|
|||||||
onError,
|
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 = (
|
const toggleAttributeInModule = (
|
||||||
attribute: AttributeSchema,
|
attribute: AttributeSchema,
|
||||||
isAdding: boolean
|
isAdding: boolean
|
||||||
@ -66,7 +86,7 @@ const useAttributesActions = ({
|
|||||||
|
|
||||||
mutation.mutate(
|
mutation.mutate(
|
||||||
{
|
{
|
||||||
body: {
|
path: {
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
attributeId: attribute.id,
|
attributeId: attribute.id,
|
||||||
},
|
},
|
||||||
@ -76,6 +96,7 @@ const useAttributesActions = ({
|
|||||||
notifications.success({ message });
|
notifications.success({ message });
|
||||||
refetchModule();
|
refetchModule();
|
||||||
refetchAttributes();
|
refetchAttributes();
|
||||||
|
removeGetDealModuleAttrQuery();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1356,12 +1356,8 @@ export const removeAttributeFromModule = <ThrowOnError extends boolean = false>(
|
|||||||
responseValidator: async data => {
|
responseValidator: async data => {
|
||||||
return await zRemoveAttributeFromModuleResponse.parseAsync(data);
|
return await zRemoveAttributeFromModuleResponse.parseAsync(data);
|
||||||
},
|
},
|
||||||
url: "/crm/v1/module/attribute",
|
url: "/crm/v1/module/{moduleId}/attribute/{attributeId}",
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
...options.headers,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1383,12 +1379,8 @@ export const addAttributeToModule = <ThrowOnError extends boolean = false>(
|
|||||||
responseValidator: async data => {
|
responseValidator: async data => {
|
||||||
return await zAddAttributeToModuleResponse.parseAsync(data);
|
return await zAddAttributeToModuleResponse.parseAsync(data);
|
||||||
},
|
},
|
||||||
url: "/crm/v1/module/attribute",
|
url: "/crm/v1/module/{moduleId}/attribute/{attributeId}",
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
...options.headers,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,5 @@
|
|||||||
// This file is auto-generated by @hey-api/openapi-ts
|
// This file is auto-generated by @hey-api/openapi-ts
|
||||||
|
|
||||||
/**
|
|
||||||
* AddAttributeRequest
|
|
||||||
*/
|
|
||||||
export type AddAttributeRequest = {
|
|
||||||
/**
|
|
||||||
* Attributeid
|
|
||||||
*/
|
|
||||||
attributeId: number;
|
|
||||||
/**
|
|
||||||
* Moduleid
|
|
||||||
*/
|
|
||||||
moduleId: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AddAttributeResponse
|
* AddAttributeResponse
|
||||||
*/
|
*/
|
||||||
@ -1282,20 +1268,6 @@ export type DealTagSchema = {
|
|||||||
tagColor: DealTagColorSchema;
|
tagColor: DealTagColorSchema;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* DeleteAttributeRequest
|
|
||||||
*/
|
|
||||||
export type DeleteAttributeRequest = {
|
|
||||||
/**
|
|
||||||
* Attributeid
|
|
||||||
*/
|
|
||||||
attributeId: number;
|
|
||||||
/**
|
|
||||||
* Moduleid
|
|
||||||
*/
|
|
||||||
moduleId: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeleteAttributeResponse
|
* DeleteAttributeResponse
|
||||||
*/
|
*/
|
||||||
@ -4168,10 +4140,19 @@ export type DeleteModuleResponse2 =
|
|||||||
DeleteModuleResponses[keyof DeleteModuleResponses];
|
DeleteModuleResponses[keyof DeleteModuleResponses];
|
||||||
|
|
||||||
export type RemoveAttributeFromModuleData = {
|
export type RemoveAttributeFromModuleData = {
|
||||||
body: DeleteAttributeRequest;
|
body?: never;
|
||||||
path?: never;
|
path: {
|
||||||
|
/**
|
||||||
|
* Moduleid
|
||||||
|
*/
|
||||||
|
moduleId: number;
|
||||||
|
/**
|
||||||
|
* Attributeid
|
||||||
|
*/
|
||||||
|
attributeId: number;
|
||||||
|
};
|
||||||
query?: never;
|
query?: never;
|
||||||
url: "/crm/v1/module/attribute";
|
url: "/crm/v1/module/{moduleId}/attribute/{attributeId}";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RemoveAttributeFromModuleErrors = {
|
export type RemoveAttributeFromModuleErrors = {
|
||||||
@ -4195,10 +4176,19 @@ export type RemoveAttributeFromModuleResponse =
|
|||||||
RemoveAttributeFromModuleResponses[keyof RemoveAttributeFromModuleResponses];
|
RemoveAttributeFromModuleResponses[keyof RemoveAttributeFromModuleResponses];
|
||||||
|
|
||||||
export type AddAttributeToModuleData = {
|
export type AddAttributeToModuleData = {
|
||||||
body: AddAttributeRequest;
|
body?: never;
|
||||||
path?: never;
|
path: {
|
||||||
|
/**
|
||||||
|
* Moduleid
|
||||||
|
*/
|
||||||
|
moduleId: number;
|
||||||
|
/**
|
||||||
|
* Attributeid
|
||||||
|
*/
|
||||||
|
attributeId: number;
|
||||||
|
};
|
||||||
query?: never;
|
query?: never;
|
||||||
url: "/crm/v1/module/attribute";
|
url: "/crm/v1/module/{moduleId}/attribute/{attributeId}";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AddAttributeToModuleErrors = {
|
export type AddAttributeToModuleErrors = {
|
||||||
|
|||||||
@ -2,14 +2,6 @@
|
|||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
/**
|
|
||||||
* AddAttributeRequest
|
|
||||||
*/
|
|
||||||
export const zAddAttributeRequest = z.object({
|
|
||||||
attributeId: z.int(),
|
|
||||||
moduleId: z.int(),
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AddAttributeResponse
|
* AddAttributeResponse
|
||||||
*/
|
*/
|
||||||
@ -885,14 +877,6 @@ export const zDealProductAddKitResponse = z.object({
|
|||||||
message: z.string(),
|
message: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* DeleteAttributeRequest
|
|
||||||
*/
|
|
||||||
export const zDeleteAttributeRequest = z.object({
|
|
||||||
attributeId: z.int(),
|
|
||||||
moduleId: z.int(),
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeleteAttributeResponse
|
* DeleteAttributeResponse
|
||||||
*/
|
*/
|
||||||
@ -2295,8 +2279,11 @@ export const zDeleteModuleData = z.object({
|
|||||||
export const zDeleteModuleResponse2 = zDeleteModuleResponse;
|
export const zDeleteModuleResponse2 = zDeleteModuleResponse;
|
||||||
|
|
||||||
export const zRemoveAttributeFromModuleData = z.object({
|
export const zRemoveAttributeFromModuleData = z.object({
|
||||||
body: zDeleteAttributeRequest,
|
body: z.optional(z.never()),
|
||||||
path: z.optional(z.never()),
|
path: z.object({
|
||||||
|
moduleId: z.int(),
|
||||||
|
attributeId: z.int(),
|
||||||
|
}),
|
||||||
query: z.optional(z.never()),
|
query: z.optional(z.never()),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2306,8 +2293,11 @@ export const zRemoveAttributeFromModuleData = z.object({
|
|||||||
export const zRemoveAttributeFromModuleResponse = zDeleteAttributeResponse;
|
export const zRemoveAttributeFromModuleResponse = zDeleteAttributeResponse;
|
||||||
|
|
||||||
export const zAddAttributeToModuleData = z.object({
|
export const zAddAttributeToModuleData = z.object({
|
||||||
body: zAddAttributeRequest,
|
body: z.optional(z.never()),
|
||||||
path: z.optional(z.never()),
|
path: z.object({
|
||||||
|
moduleId: z.int(),
|
||||||
|
attributeId: z.int(),
|
||||||
|
}),
|
||||||
query: z.optional(z.never()),
|
query: z.optional(z.never()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user