feat: Refactor frontend hooks to use useNavigate and useAppDispatch directly

This commit is contained in:
2025-12-08 00:05:06 +01:00
parent d46db2c701
commit 5840c9d1d0
5 changed files with 11 additions and 19 deletions
@@ -1,7 +1,9 @@
import { MutableRefObject, useCallback } from 'react';
import type { NavigateFunction } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import type { FolderId, TenantId } from '../../types/identifiers';
import { useStatusToast } from '../../lib/context/StatusToastContext';
import { useAppDispatch } from '../../lib/store/appState';
import { api, listTenants, switchTenant } from '../../lib/api/apiClient';
@@ -13,32 +15,30 @@ interface TenantOption {
import useNotifyApiError from '../../hooks/useNotifyApiError';
interface UseTenantManagerOptions {
appDispatch: (action: any) => void;
currentTenantId: TenantId | null;
resetWorkspaceState: () => void;
refreshTags: () => Promise<void>;
refreshCorrespondents: () => Promise<void>;
loadFolder: (folderId: FolderId, options?: { preserveSearch?: boolean }) => Promise<void>;
handleDocumentsViewModeChange: (mode: string) => void;
navigate: NavigateFunction;
tokenRef?: MutableRefObject<string | null>;
tenantIdRef?: MutableRefObject<TenantId | null>;
}
const useTenantManager = ({
appDispatch,
currentTenantId,
resetWorkspaceState,
refreshTags,
refreshCorrespondents,
loadFolder,
handleDocumentsViewModeChange,
navigate,
tokenRef,
tenantIdRef,
}: UseTenantManagerOptions) => {
const { showToast } = useStatusToast();
const notifyApiError = useNotifyApiError();
const navigate = useNavigate();
const appDispatch = useAppDispatch();
const handleTenantSelect = useCallback(
async (tenantOption: TenantOption | null, { refreshOnly = false }: { refreshOnly?: boolean } = {}) => {
const requestedTenantId = tenantOption?.id ?? null;