fix: Add enabled flag to dashboard hooks to prevent premature query execution
Issue: Dashboard components remained in loading state even when APIs returned 200 OK
Root cause: React Query hooks were executing even when tenantId was empty/invalid,
causing queries to fail silently and stay in loading state indefinitely.
Fix: Added `enabled: !!tenantId` flag to all five dashboard hooks:
- useBakeryHealthStatus
- useOrchestrationSummary
- useActionQueue
- useProductionTimeline
- useInsights
This ensures queries only execute when a valid tenantId is available, preventing
the loading state from persisting when tenantId is empty.
API response confirmed working (example):
{"status":"green","headline":"Your bakery is running smoothly",...}
This commit is contained in:
@@ -157,6 +157,7 @@ export function useBakeryHealthStatus(tenantId: string) {
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!tenantId, // Only fetch when tenantId is available
|
||||
refetchInterval: 30000, // Refresh every 30 seconds
|
||||
staleTime: 20000, // Consider stale after 20 seconds
|
||||
retry: 2,
|
||||
@@ -179,6 +180,7 @@ export function useOrchestrationSummary(tenantId: string, runId?: string) {
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!tenantId, // Only fetch when tenantId is available
|
||||
staleTime: 60000, // Summary doesn't change often
|
||||
retry: 2,
|
||||
});
|
||||
@@ -199,6 +201,7 @@ export function useActionQueue(tenantId: string) {
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!tenantId, // Only fetch when tenantId is available
|
||||
refetchInterval: 60000, // Refresh every minute
|
||||
staleTime: 30000,
|
||||
retry: 2,
|
||||
@@ -219,6 +222,7 @@ export function useProductionTimeline(tenantId: string) {
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!tenantId, // Only fetch when tenantId is available
|
||||
refetchInterval: 60000, // Refresh every minute
|
||||
staleTime: 30000,
|
||||
retry: 2,
|
||||
@@ -239,6 +243,7 @@ export function useInsights(tenantId: string) {
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!tenantId, // Only fetch when tenantId is available
|
||||
refetchInterval: 120000, // Refresh every 2 minutes
|
||||
staleTime: 60000,
|
||||
retry: 2,
|
||||
|
||||
Reference in New Issue
Block a user