Skip to content

Commit

Permalink
Merge pull request #281 from Tauffer-Consulting/fix/invalidate-workps…
Browse files Browse the repository at this point in the history
…aces-cache-when-created-or-deleted

fix(frontend): invalidate workspaces cache when created or deleted
  • Loading branch information
vinicvaz authored Apr 19, 2024
2 parents b3670c3 + acb21cb commit 1da2d26
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions frontend/src/context/workspaces/workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,35 @@ export const WorkspacesProvider: FC<IWorkspacesProviderProps> = ({
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,
Expand Down Expand Up @@ -188,7 +212,7 @@ export const WorkspacesProvider: FC<IWorkspacesProviderProps> = ({

const handleCreateWorkspace = useCallback(
async (name: string) =>
postWorkspace({ name })
await postWorkspace({ name })
.then((data) => {
toast.success(`Workspace ${name} created successfully`);
return data;
Expand Down Expand Up @@ -241,7 +265,7 @@ export const WorkspacesProvider: FC<IWorkspacesProviderProps> = ({
workspaces,
workspacesError: !!workspacesError,
workspacesLoading,
handleRefreshWorkspaces: async () => workspacesRefresh(),
handleRefreshWorkspaces: async () => await workspacesRefresh(),
workspace,
handleChangeWorkspace,
handleCreateWorkspace,
Expand Down

0 comments on commit 1da2d26

Please sign in to comment.