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
@@ -13,7 +13,7 @@ import {
useNavigate,
} from 'react-router-dom';
import AssetManager, { getAssetFromVersion } from '../../lib/assets/AssetManager';
import useApiError from '../../hooks/useApiError';
import useNotifyApiError from '../../hooks/useNotifyApiError';
import TagManager from '../../lib/assets/TagManager';
import { useManagementModals } from '../../app/useManagementModals';
import { useAppDispatch, useAppState } from '../../lib/store/appState';
@@ -144,19 +144,7 @@ const useDocumentsWorkspace = ({
? (tenantOptionsRaw as TenantOption[])
: [];
const { showToast } = useStatusToast();
const reportApiError = useApiError({
onReport: useCallback(
({ message, variant }) => showToast(message, variant),
[showToast],
),
});
const notifyApiError = useCallback(
(error, fallbackMessage, variant = 'error') =>
reportApiError(error, { message: fallbackMessage, variant }),
[reportApiError],
);
const notifyApiError = useNotifyApiError();
const [creatingFolder, setCreatingFolder] = useState(false);
@@ -389,7 +377,6 @@ const useDocumentsWorkspace = ({
searchIncludeDescendants,
documentsSortField,
documentsSortDirection,
notifyApiError,
setSearchIncludeDescendants,
documentsManager,
});
@@ -457,7 +444,6 @@ const useDocumentsWorkspace = ({
routeDocumentId: previewDocumentId,
documentsManager,
selectedFolder,
notifyApiError,
navigate,
locationPathname: location.pathname,
locationSearch: location.search,
@@ -506,7 +492,6 @@ const useDocumentsWorkspace = ({
handleTagDelete,
setTags,
} = useTags({
notifyApiError,
tenantIdRef,
tagManager,
setActiveTagFilters,
@@ -535,7 +520,6 @@ const useDocumentsWorkspace = ({
handleCorrespondentDelete,
setCorrespondents,
} = useCorrespondents({
notifyApiError,
tenantIdRef,
mapDocumentCaches,
});
@@ -548,7 +532,6 @@ const useDocumentsWorkspace = ({
} = useDocumentCorrespondentActions({
correspondents,
handleCorrespondentCreate,
notifyApiError,
updateDocumentCaches,
});
@@ -562,7 +545,6 @@ const useDocumentsWorkspace = ({
registerPasskey,
revokePasskey,
} = usePasskeys({
notifyApiError,
token,
});
@@ -594,7 +576,6 @@ const useDocumentsWorkspace = ({
tagManager,
refreshTags,
resolveTargetDocumentIds,
notifyApiError,
updateDocumentCaches,
});
@@ -612,7 +593,6 @@ const useDocumentsWorkspace = ({
ensureFolderData,
refreshCurrentFolder,
shellRef,
notifyApiError,
});
const {
@@ -747,7 +727,6 @@ const useDocumentsWorkspace = ({
focusedDocumentId,
setFocusedEntryKey,
focusedEntryKey,
notifyApiError,
mapDocumentCaches,
folderNodes,
setFolderNodes,
@@ -777,7 +756,6 @@ const useDocumentsWorkspace = ({
setFolderNodes,
selectedFolder,
setSelectedFolder,
notifyApiError,
navigate,
handleFileDrop,
moveDocumentsToFolder,
@@ -1105,7 +1083,6 @@ const useDocumentsWorkspace = ({
appDispatch,
currentTenantId,
resetWorkspaceState,
notifyApiError,
refreshTags,
refreshCorrespondents,
loadFolder,