refactor: centralize API error notifications with a new useNotifyApiError hook

This commit is contained in:
2025-12-07 23:55:47 +01:00
parent 595c170c00
commit d46db2c701
14 changed files with 59 additions and 55 deletions
@@ -40,8 +40,6 @@ type RemoveDocumentsFromCaches = (documentIds: DocumentId[]) => void;
type CloseDocumentPreview = () => void;
type NotifyApiError = (error: unknown, fallbackMessage?: string) => void;
interface Tag {
id: DocumentId;
label: string;
@@ -73,6 +71,8 @@ interface DocumentTagExtras {
input?: { value?: string } | null;
}
import useNotifyApiError from '../../hooks/useNotifyApiError';
interface UseDocumentMutationsArgs {
token?: string | null;
documentLookup: Map<DocumentId, Document>;
@@ -90,7 +90,6 @@ interface UseDocumentMutationsArgs {
focusedDocumentId: DocumentId | null;
setFocusedEntryKey: Dispatch<SetStateAction<string | null>>;
focusedEntryKey: string | null;
notifyApiError: NotifyApiError;
mapDocumentCaches: MapDocumentCaches;
folderNodes: Map<FolderId, FolderNode>;
setFolderNodes: Dispatch<SetStateAction<Map<FolderId, FolderNode>>>;
@@ -160,7 +159,6 @@ const useDocumentMutations = ({
focusedDocumentId,
setFocusedEntryKey,
focusedEntryKey,
notifyApiError,
mapDocumentCaches,
folderNodes,
setFolderNodes,
@@ -177,6 +175,7 @@ const useDocumentMutations = ({
ingestDocuments,
}: UseDocumentMutationsArgs): UseDocumentMutationsResult => {
const { showToast } = useStatusToast();
const notifyApiError = useNotifyApiError();
const moveDocumentsToFolder = useCallback(
async (documentIds: Array<DocumentId | Document>, targetFolderId?: NullableFolderId) => {