2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 11:10:54 +00:00

Better handling of initial state fetching (#9881)

- Wait for states properly
- Order of operations (await)
This commit is contained in:
Oliver
2025-06-27 09:52:44 +10:00
committed by GitHub
parent 55a019c054
commit 1e8d9bd571
3 changed files with 11 additions and 6 deletions

View File

@ -11,7 +11,7 @@ import type { ServerAPIProps } from './states';
interface ServerApiStateProps {
server: ServerAPIProps;
setServer: (newServer: ServerAPIProps) => void;
fetchServerApiState: () => void;
fetchServerApiState: () => Promise<void>;
auth_config?: AuthConfig;
auth_context?: AuthContext;
setAuthContext: (auth_context: AuthContext) => void;

View File

@ -14,7 +14,7 @@ export type StatusLookup = Record<ModelType | string, StatusCodeListInterface>;
interface ServerStateProps {
status?: StatusLookup;
setStatus: (newStatus: StatusLookup) => void;
fetchStatus: () => void;
fetchStatus: () => Promise<void>;
}
export const useGlobalStatusState = create<ServerStateProps>()(

View File

@ -56,14 +56,19 @@ export async function fetchGlobalStates(
setApiDefaults();
useServerApiState.getState().fetchServerApiState();
await useServerApiState.getState().fetchServerApiState();
const result = await useUserSettingsState.getState().fetchSettings();
if (!result && navigate) {
console.log('MFA is required - setting up');
// call mfa setup
navigate('/mfa-setup');
return;
}
useGlobalSettingsState.getState().fetchSettings();
useGlobalStatusState.getState().fetchStatus();
useIconState.getState().fetchIcons();
await Promise.all([
useGlobalSettingsState.getState().fetchSettings(),
useGlobalStatusState.getState().fetchStatus(),
useIconState.getState().fetchIcons()
]);
}