mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-08 23:32:40 +02:00
add delete chat mutation
This commit is contained in:
parent
bd4e5d627d
commit
b866170e6a
11 changed files with 486 additions and 445 deletions
|
|
@ -0,0 +1,33 @@
|
|||
import { atomWithMutation } from "jotai-tanstack-query";
|
||||
import { deleteChat } from "@/lib/apis/chat-apis";
|
||||
import { activeSearchSpaceIdAtom } from "../../seach-spaces/active-seach-space.atom";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export const deleteChatMutationAtom = atomWithMutation((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
const authToken = localStorage.getItem("surfsense_bearer_token");
|
||||
|
||||
return {
|
||||
mutationKey: cacheKeys.activeSearchSpace.chats(searchSpaceId ?? ""),
|
||||
enabled: !!searchSpaceId && !!authToken,
|
||||
mutationFn: async (chatId: number) => {
|
||||
if (!authToken) {
|
||||
throw new Error("No authentication token found");
|
||||
}
|
||||
if (!searchSpaceId) {
|
||||
throw new Error("No search space id found");
|
||||
}
|
||||
|
||||
return deleteChat(chatId, authToken);
|
||||
},
|
||||
|
||||
onSuccess: () => {
|
||||
toast.success("Chat deleted successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.activeSearchSpace.chats(searchSpaceId!),
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue