mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-10 20:35:17 +02:00
feat: add deleteSearchSpaceMutationAtom
This commit is contained in:
parent
a820598cfd
commit
862288367d
1 changed files with 25 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import { toast } from "sonner";
|
|||
import type {
|
||||
CreateSearchSpaceRequest,
|
||||
UpdateSearchSpaceRequest,
|
||||
DeleteSearchSpaceRequest,
|
||||
} from "@/contracts/types/search-space.types";
|
||||
import { activeSearchSpaceIdAtom } from "./search-space-query.atoms";
|
||||
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||
|
|
@ -48,3 +49,27 @@ export const updateSearchSpaceMutationAtom = atomWithMutation((get) => {
|
|||
},
|
||||
};
|
||||
});
|
||||
|
||||
export const deleteSearchSpaceMutationAtom = atomWithMutation((get) => {
|
||||
const activeSearchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
|
||||
return {
|
||||
mutationKey: ["delete-search-space", activeSearchSpaceId],
|
||||
enabled: !!activeSearchSpaceId,
|
||||
mutationFn: async (request: DeleteSearchSpaceRequest) => {
|
||||
return searchSpacesApiService.deleteSearchSpace(request);
|
||||
},
|
||||
|
||||
onSuccess: (_, request: DeleteSearchSpaceRequest) => {
|
||||
toast.success("Search space deleted successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.searchSpaces.all,
|
||||
});
|
||||
if (request.id) {
|
||||
queryClient.removeQueries({
|
||||
queryKey: cacheKeys.searchSpaces.detail(String(request.id)),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue