Skip to content

Commit

Permalink
Invalidate archetype queries
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Mar 11, 2024
1 parent cb38a68 commit 46f8bde
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ const Archetypes: React.FC = () => {
variant: "danger",
});
}
queryClient.invalidateQueries([ARCHETYPES_QUERY_KEY]);
queryClient.invalidateQueries([ARCHETYPE_QUERY_KEY, archetype.id]);
};

const onDeleteReviewSuccess = (name: string) => {
Expand All @@ -173,9 +171,11 @@ const Archetypes: React.FC = () => {
await deleteReview({
id: archetype.review.id,
name: archetype.name,
queryKeys: [
[ARCHETYPES_QUERY_KEY],
[ARCHETYPE_QUERY_KEY, archetype.id],
],
});
queryClient.invalidateQueries([ARCHETYPES_QUERY_KEY]);
queryClient.invalidateQueries([ARCHETYPE_QUERY_KEY, archetype.id]);
} catch (error) {
console.error("Error while deleting review:", error);
pushNotification({
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
InitialAssessment,
} from "@app/api/models";
import { QuestionnairesQueryKey } from "./questionnaires";
import { ARCHETYPE_QUERY_KEY } from "./archetypes";
import { ARCHETYPES_QUERY_KEY, ARCHETYPE_QUERY_KEY } from "./archetypes";

export const assessmentsQueryKey = "assessments";
export const assessmentQueryKey = "assessment";
Expand Down Expand Up @@ -124,6 +124,7 @@ export const useDeleteAssessmentMutation = (

queryClient.invalidateQueries([assessmentQueryKey, args?.assessmentId]);
queryClient.invalidateQueries([ARCHETYPE_QUERY_KEY, args?.archetypeId]);
queryClient.invalidateQueries([ARCHETYPES_QUERY_KEY]);
queryClient.invalidateQueries([
assessmentsByItemIdQueryKey,
args?.archetypeId,
Expand Down
11 changes: 9 additions & 2 deletions client/src/app/queries/reviews.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
QueryKey,
useMutation,
useQuery,
useQueryClient,
} from "@tanstack/react-query";

import {
createReview,
Expand Down Expand Up @@ -72,10 +77,11 @@ export const useUpdateReviewMutation = (
export interface IReviewMutation {
id: number;
name: string;
queryKeys?: QueryKey[];
}

export const useDeleteReviewMutation = (
onSuccess?: (name: string) => void,
onSuccess?: (name: string, queryKeys?: QueryKey[]) => void,
onError?: (err: AxiosError) => void
) => {
const queryClient = useQueryClient();
Expand All @@ -84,6 +90,7 @@ export const useDeleteReviewMutation = (
mutationFn: (args: IReviewMutation) => deleteReview(args.id),
onSuccess: (_, args) => {
onSuccess && onSuccess(args.name);
args.queryKeys?.forEach((key) => queryClient.invalidateQueries(key));
queryClient.invalidateQueries([reviewsQueryKey]);
},
onError: onError && onError,
Expand Down

0 comments on commit 46f8bde

Please sign in to comment.