mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-21 18:55:16 +02:00
Closes #1371. Retarget of #1385 onto dev per maintainer request. surfsense_web/lib/query-client/client.ts configures a global MutationCache.onError that shows an error toast for every failed mutation unless meta.suppressGlobalErrorToast is set. The opt-out hook existed in the consumer but had zero producers — every mutation atom that already had its own onError: toast.error(...) was double-toasting on failure. Add meta: { suppressGlobalErrorToast: true } to the 30 mutations across 9 atom files that own their own error toast: - atoms/prompts/prompts-mutation.atoms.ts (4) - atoms/invites/invites-mutation.atoms.ts (4) - atoms/chat-comments/comments-mutation.atoms.ts (4) - atoms/new-llm-config/new-llm-config-mutation.atoms.ts (4) - atoms/members/members-mutation.atoms.ts (3) - atoms/roles/roles-mutation.atoms.ts (3) - atoms/image-gen-config/image-gen-config-mutation.atoms.ts (3) - atoms/vision-llm-config/vision-llm-config-mutation.atoms.ts (3) - atoms/public-chat-snapshots/public-chat-snapshots-mutation.atoms.ts (2) Atoms intentionally left alone (no local onError, rely on global): auth, user, search-spaces, logs, documents, connectors. Local validation (against dev): pnpm biome check on the 9 touched files is clean; tsc --noEmit shows no new errors in the touched files (pre-existing errors elsewhere unrelated). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { atomWithMutation } from "jotai-tanstack-query";
|
|
import { toast } from "sonner";
|
|
import type {
|
|
PublicChatSnapshotCreateRequest,
|
|
PublicChatSnapshotCreateResponse,
|
|
PublicChatSnapshotDeleteRequest,
|
|
} from "@/contracts/types/chat-threads.types";
|
|
import { chatThreadsApiService } from "@/lib/apis/chat-threads-api.service";
|
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
|
import { queryClient } from "@/lib/query-client/client";
|
|
|
|
export const createPublicChatSnapshotMutationAtom = atomWithMutation(() => ({
|
|
meta: { suppressGlobalErrorToast: true },
|
|
mutationFn: async (request: PublicChatSnapshotCreateRequest) => {
|
|
return chatThreadsApiService.createPublicChatSnapshot(request);
|
|
},
|
|
onSuccess: (response: PublicChatSnapshotCreateResponse) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.publicChatSnapshots.all,
|
|
});
|
|
|
|
const publicUrl = `${window.location.origin}/public/${response.share_token}`;
|
|
navigator.clipboard.writeText(publicUrl);
|
|
if (response.is_new) {
|
|
toast.success("Public link created and copied to clipboard", {
|
|
description: "Anyone with this link can view a snapshot of this chat",
|
|
});
|
|
} else {
|
|
toast.success("Public link copied to clipboard", {
|
|
description: "This snapshot already exists",
|
|
});
|
|
}
|
|
},
|
|
onError: (error: Error) => {
|
|
console.error("Failed to create snapshot:", error);
|
|
toast.error("Failed to create public link");
|
|
},
|
|
}));
|
|
|
|
export const deletePublicChatSnapshotMutationAtom = atomWithMutation(() => ({
|
|
meta: { suppressGlobalErrorToast: true },
|
|
mutationFn: async (request: PublicChatSnapshotDeleteRequest) => {
|
|
return chatThreadsApiService.deletePublicChatSnapshot(request);
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: cacheKeys.publicChatSnapshots.all,
|
|
});
|
|
toast.success("Public link deleted");
|
|
},
|
|
onError: (error: Error) => {
|
|
console.error("Failed to delete public chat link:", error);
|
|
toast.error("Failed to delete public link");
|
|
},
|
|
}));
|