fix: fixed deal module attributes refetch after module editing

This commit is contained in:
2025-11-02 11:26:17 +04:00
parent e8ffafa6c5
commit fd5e878c29
4 changed files with 59 additions and 66 deletions

View File

@ -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();
},
}
);