Skip to content

Commit

Permalink
Use compound key to query tagCategories
Browse files Browse the repository at this point in the history
Signed-off-by: Gilles Dubreuil <[email protected]>
  • Loading branch information
gildub committed Jul 11, 2023
1 parent 4ad3956 commit 28b4237
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion client/src/app/pages/controls/tags/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState } from "react";
import { AxiosError, AxiosResponse } from "axios";
import { useTranslation } from "react-i18next";
import { useSelectionState } from "@migtools/lib-ui";

import {
Button,
ButtonVariant,
Expand Down
22 changes: 7 additions & 15 deletions client/src/app/queries/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useFetchTags = () => {

export const useFetchTagCategories = () => {
const { data, isLoading, error, refetch } = useQuery({
queryKey: [TagCategoriesQueryKey],
queryKey: [TagCategoriesQueryKey, TagsQueryKey],
queryFn: getTagCategories,
onError: (error: AxiosError) => console.log("error, ", error),
});
Expand All @@ -53,13 +53,11 @@ export const useCreateTagMutation = (
mutationFn: createTag,
onSuccess: (res) => {
onSuccess(res);
queryClient.invalidateQueries([TagsQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey, TagsQueryKey]);
},
onError: (err: AxiosError) => {
onError(err);
queryClient.invalidateQueries([TagsQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey, TagsQueryKey]);
},
});
};
Expand All @@ -75,12 +73,10 @@ export const useCreateTagCategoryMutation = (
onSuccess: (res) => {
onSuccess(res);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagsQueryKey]);
},
onError: (err: AxiosError) => {
onError(err);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagsQueryKey]);
},
});
};
Expand All @@ -95,13 +91,11 @@ export const useUpdateTagMutation = (
mutationFn: updateTag,
onSuccess: (res) => {
onSuccess(res);
queryClient.invalidateQueries([TagsQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey, TagsQueryKey]);
},
onError: (err: AxiosError) => {
onError(err);
queryClient.invalidateQueries([TagsQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey, TagsQueryKey]);
},
});
};
Expand All @@ -117,12 +111,10 @@ export const useUpdateTagCategoryMutation = (
onSuccess: (res) => {
onSuccess(res);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagsQueryKey]);
},
onError: (err: AxiosError) => {
onError(err);
queryClient.invalidateQueries([TagCategoriesQueryKey]);
queryClient.invalidateQueries([TagsQueryKey]);
},
});
};
Expand All @@ -136,11 +128,11 @@ export const useDeleteTagMutation = (
mutationFn: deleteTag,
onSuccess: (res) => {
onSuccess(res);
queryClient.invalidateQueries([TagsQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey, TagsQueryKey]);
},
onError: (err: AxiosError) => {
onError(err);
queryClient.invalidateQueries([TagsQueryKey]);
queryClient.invalidateQueries([TagCategoriesQueryKey, TagsQueryKey]);
},
});
};
Expand Down

0 comments on commit 28b4237

Please sign in to comment.