Fix new services implementation 8

This commit is contained in:
Urtzi Alfaro
2025-08-15 23:11:53 +02:00
parent 399ba80067
commit 055ce10c66
5 changed files with 161 additions and 80 deletions

View File

@@ -120,15 +120,31 @@ export const useForecast = () => {
}
}, []);
const getForecastAlerts = useCallback(async (tenantId: string): Promise<ForecastAlert[]> => {
const getForecastAlerts = useCallback(async (tenantId: string): Promise<any> => {
try {
setIsLoading(true);
setError(null);
const response = await forecastingService.getForecastAlerts(tenantId);
setAlerts(response.data);
return response.data;
// Handle different response formats
if (response && response.alerts) {
// New format: { alerts: [...], total_returned: N, ... }
setAlerts(response.alerts);
return response;
} else if (response && response.data) {
// Old format: { data: [...] }
setAlerts(response.data);
return { alerts: response.data };
} else if (Array.isArray(response)) {
// Direct array format
setAlerts(response);
return { alerts: response };
} else {
// Unknown format - return empty
setAlerts([]);
return { alerts: [] };
}
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to get forecast alerts';
setError(message);