Skip to content

Commit

Permalink
Add queryInvalidation on creating workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 24, 2024
1 parent d208591 commit e2c980e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/modals/CreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function CreateModal(props: CreateModalProps) {
<TextFieldElement
variant="standard"
name="title"
label="Title of new note"
label={`Title of New ${title}`}
required
fullWidth
inputProps={{
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/hooks/api/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useInfiniteQuery, useMutation, useQuery } from "@tanstack/react-query";
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import axios from "axios";
import {
CreateWorkspaceInviteTokenRequest,
Expand Down Expand Up @@ -55,12 +55,19 @@ export const useGetWorkspaceListQuery = () => {
};

export const useCreateWorkspaceMutation = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (data: CreateWorkspaceRequest) => {
const res = await axios.post<CreateWorkspaceResponse>("/workspaces", data);

return res.data;
},
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: generateGetWorkspaceListQueryKey(),
});
},
});
};

Expand Down

0 comments on commit e2c980e

Please sign in to comment.