From 2100639f7e36a9c6dbbf82c094408d6f7ce0d407 Mon Sep 17 00:00:00 2001 From: David Hordiienko Date: Fri, 15 Nov 2024 16:05:29 +0200 Subject: [PATCH] fix: some queryClient behavior --- frontend/src/modules/organizations/delete-organizations.tsx | 2 +- frontend/src/modules/organizations/organization-page.tsx | 2 +- .../src/modules/organizations/organizations-table/index.tsx | 2 +- .../src/modules/organizations/update-organization-form.tsx | 6 +++--- frontend/src/modules/system/requests-table/index.tsx | 2 +- frontend/src/modules/users/users-table/index.tsx | 2 +- frontend/src/routes/organizations.tsx | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/src/modules/organizations/delete-organizations.tsx b/frontend/src/modules/organizations/delete-organizations.tsx index e2d14d9c0..673eadd15 100644 --- a/frontend/src/modules/organizations/delete-organizations.tsx +++ b/frontend/src/modules/organizations/delete-organizations.tsx @@ -19,7 +19,7 @@ const DeleteOrganizations = ({ organizations, callback, dialog: isDialog }: Prop onSuccess: () => { for (const organization of organizations) { queryClient.invalidateQueries({ - queryKey: ['organizations', organization.id], + queryKey: ['organization', organization.id], }); deleteMenuItem(organization.id); } diff --git a/frontend/src/modules/organizations/organization-page.tsx b/frontend/src/modules/organizations/organization-page.tsx index 7d356fb73..d4c71e978 100644 --- a/frontend/src/modules/organizations/organization-page.tsx +++ b/frontend/src/modules/organizations/organization-page.tsx @@ -21,7 +21,7 @@ const organizationTabs: PageNavTab[] = [ export const organizationQueryOptions = (idOrSlug: string) => queryOptions({ - queryKey: ['organizations', idOrSlug], + queryKey: ['organization', idOrSlug], queryFn: () => getOrganization(idOrSlug), }); diff --git a/frontend/src/modules/organizations/organizations-table/index.tsx b/frontend/src/modules/organizations/organizations-table/index.tsx index 5bf54e91b..5f538bebf 100644 --- a/frontend/src/modules/organizations/organizations-table/index.tsx +++ b/frontend/src/modules/organizations/organizations-table/index.tsx @@ -70,7 +70,7 @@ const OrganizationsTable = () => { // Map (updated) query data to rows useMapQueryDataToRows({ queryResult, setSelectedRows, setRows, selectedRows, setTotalCount }); - const mutateQuery = useMutateQueryData(['organizations', 'list'], (item) => ['organizations', item.id], ['update', 'delete']); + const mutateQuery = useMutateQueryData(['organizations', 'list']); // Build columns const [columns, setColumns] = useColumns(mutateQuery.update); diff --git a/frontend/src/modules/organizations/update-organization-form.tsx b/frontend/src/modules/organizations/update-organization-form.tsx index 6aeac5200..b5e6ba0d6 100644 --- a/frontend/src/modules/organizations/update-organization-form.tsx +++ b/frontend/src/modules/organizations/update-organization-form.tsx @@ -38,12 +38,12 @@ type FormValues = z.infer; export const useUpdateOrganizationMutation = (idOrSlug: string) => { return useMutation({ - mutationKey: ['organizations', 'update', idOrSlug], + mutationKey: ['organization', 'update', idOrSlug], mutationFn: (params) => updateOrganization(idOrSlug, params), onSuccess: (updatedOrganization) => { - queryClient.setQueryData(['organizations', idOrSlug], updatedOrganization); + queryClient.setQueryData(['organization', idOrSlug], updatedOrganization); queryClient.invalidateQueries({ - queryKey: ['organizations'], + queryKey: ['organization'], }); }, gcTime: 1000 * 10, diff --git a/frontend/src/modules/system/requests-table/index.tsx b/frontend/src/modules/system/requests-table/index.tsx index 4845dca6f..bdd1a9f32 100644 --- a/frontend/src/modules/system/requests-table/index.tsx +++ b/frontend/src/modules/system/requests-table/index.tsx @@ -46,7 +46,7 @@ export const requestsQueryOptions = ({ const offset = rowsLength; return infiniteQueryOptions({ - queryKey: ['requests', q, sort, order], + queryKey: ['requests', 'list', q, sort, order], initialPageParam: 0, retry: 1, refetchOnWindowFocus: false, diff --git a/frontend/src/modules/users/users-table/index.tsx b/frontend/src/modules/users/users-table/index.tsx index 84bd0b0f5..945e62903 100644 --- a/frontend/src/modules/users/users-table/index.tsx +++ b/frontend/src/modules/users/users-table/index.tsx @@ -77,7 +77,7 @@ const UsersTable = () => { return rows.filter((row) => selectedRows.has(row.id)); }, [selectedRows, rows]); - const mutateQuery = useMutateQueryData(['users', 'list'], (item) => ['user', item.id], ['update', 'delete']); + const mutateQuery = useMutateQueryData(['users', 'list'], (item) => ['user', item.id], ['update']); // Build columns const [columns, setColumns] = useColumns(mutateQuery.update); diff --git a/frontend/src/routes/organizations.tsx b/frontend/src/routes/organizations.tsx index abcb81752..c48e7052c 100644 --- a/frontend/src/routes/organizations.tsx +++ b/frontend/src/routes/organizations.tsx @@ -58,7 +58,7 @@ export const OrganizationMembersRoute = createRoute({ }, component: () => { const { idOrSlug } = useParams({ from: OrganizationMembersRoute.id }); - const organization: OrganizationType | undefined = queryClient.getQueryData(['organizations', idOrSlug]); + const organization: OrganizationType | undefined = queryClient.getQueryData(['organization', idOrSlug]); if (!organization) return; return ( @@ -77,7 +77,7 @@ export const OrganizationAttachmentsRoute = createRoute({ loaderDeps: ({ search: { q, sort, order } }) => ({ q, sort, order }), component: () => { const { idOrSlug } = useParams({ from: OrganizationAttachmentsRoute.id }); - const organization: OrganizationType | undefined = queryClient.getQueryData(['organizations', idOrSlug]); + const organization: OrganizationType | undefined = queryClient.getQueryData(['organization', idOrSlug]); if (!organization) return; return ( @@ -94,7 +94,7 @@ export const OrganizationSettingsRoute = createRoute({ getParentRoute: () => OrganizationRoute, component: () => { const { idOrSlug } = useParams({ from: OrganizationSettingsRoute.id }); - const organization: OrganizationType | undefined = queryClient.getQueryData(['organizations', idOrSlug]); + const organization: OrganizationType | undefined = queryClient.getQueryData(['organization', idOrSlug]); if (!organization) return; return (