mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
feat: add updateSearchSpaceMutationAtom
This commit is contained in:
parent
00b5b7dec8
commit
d3dd2fc886
1 changed files with 26 additions and 0 deletions
|
|
@ -2,7 +2,9 @@ import { atomWithMutation } from "jotai-tanstack-query";
|
|||
import { toast } from "sonner";
|
||||
import type {
|
||||
CreateSearchSpaceRequest,
|
||||
UpdateSearchSpaceRequest,
|
||||
} from "@/contracts/types/search-space.types";
|
||||
import { activeSearchSpaceIdAtom } from "./search-space-query.atoms";
|
||||
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
|
@ -22,3 +24,27 @@ export const createSearchSpaceMutationAtom = atomWithMutation(() => {
|
|||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const updateSearchSpaceMutationAtom = atomWithMutation((get) => {
|
||||
const activeSearchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
|
||||
return {
|
||||
mutationKey: ["update-search-space", activeSearchSpaceId],
|
||||
enabled: !!activeSearchSpaceId,
|
||||
mutationFn: async (request: UpdateSearchSpaceRequest) => {
|
||||
return searchSpacesApiService.updateSearchSpace(request);
|
||||
},
|
||||
|
||||
onSuccess: (_, request: UpdateSearchSpaceRequest) => {
|
||||
toast.success("Search space updated successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.searchSpaces.all,
|
||||
});
|
||||
if (request.pathParams?.search_space_id) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.searchSpaces.detail(request.pathParams.search_space_id),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue