2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +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 { interface ServerApiStateProps {
server: ServerAPIProps; server: ServerAPIProps;
setServer: (newServer: ServerAPIProps) => void; setServer: (newServer: ServerAPIProps) => void;
fetchServerApiState: () => void; fetchServerApiState: () => Promise<void>;
auth_config?: AuthConfig; auth_config?: AuthConfig;
auth_context?: AuthContext; auth_context?: AuthContext;
setAuthContext: (auth_context: AuthContext) => void; setAuthContext: (auth_context: AuthContext) => void;

View File

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

View File

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