From acb21cbd839aa07aa7ba79b4c4bead0be97477ac Mon Sep 17 00:00:00 2001 From: Nathan Vieira Marcelino Date: Fri, 19 Apr 2024 14:02:21 -0300 Subject: [PATCH] fix(frontend): invalidate workspaces cache when created or deleted --- .../src/context/workspaces/workspaces.tsx | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/frontend/src/context/workspaces/workspaces.tsx b/frontend/src/context/workspaces/workspaces.tsx index 6de421cc..40f8015e 100644 --- a/frontend/src/context/workspaces/workspaces.tsx +++ b/frontend/src/context/workspaces/workspaces.tsx @@ -79,11 +79,35 @@ export const WorkspacesProvider: FC = ({ pageSize: workspaceUsersTablePageSize, }); - const { mutateAsync: postWorkspace } = useCreateWorkspace(); - const { mutateAsync: deleteWorkspace } = useDeleteWorkspace(); + const { mutateAsync: postWorkspace } = useCreateWorkspace({ + onSuccess: async () => { + await queryClient.invalidateQueries({ + queryKey: ["WORKSPACES"], + }); + }, + }); + const { mutateAsync: deleteWorkspace } = useDeleteWorkspace({ + onSuccess: async () => { + await queryClient.invalidateQueries({ + queryKey: ["WORKSPACES"], + }); + }, + }); - const { mutateAsync: acceptWorkspaceInvite } = useAcceptWorkspaceInvite(); - const { mutateAsync: rejectWorkspaceInvite } = useRejectWorkspaceInvite(); + const { mutateAsync: acceptWorkspaceInvite } = useAcceptWorkspaceInvite({ + onSuccess: async () => { + await queryClient.invalidateQueries({ + queryKey: ["WORKSPACES"], + }); + }, + }); + const { mutateAsync: rejectWorkspaceInvite } = useRejectWorkspaceInvite({ + onSuccess: async () => { + await queryClient.invalidateQueries({ + queryKey: ["WORKSPACES"], + }); + }, + }); const { mutateAsync: inviteWorkspace } = useInviteWorkspace( { workspaceId: workspace?.id, @@ -188,7 +212,7 @@ export const WorkspacesProvider: FC = ({ const handleCreateWorkspace = useCallback( async (name: string) => - postWorkspace({ name }) + await postWorkspace({ name }) .then((data) => { toast.success(`Workspace ${name} created successfully`); return data; @@ -241,7 +265,7 @@ export const WorkspacesProvider: FC = ({ workspaces, workspacesError: !!workspacesError, workspacesLoading, - handleRefreshWorkspaces: async () => workspacesRefresh(), + handleRefreshWorkspaces: async () => await workspacesRefresh(), workspace, handleChangeWorkspace, handleCreateWorkspace,