REFACTOR data service
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Complete dashboard hook using your API infrastructure
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useAuth, useData, useForecast } from '../api';
|
||||
import { useAuth, useSales, useExternal, useForecast } from '../api';
|
||||
|
||||
import { useTenantId } from './useTenantId';
|
||||
|
||||
@@ -31,12 +31,16 @@ export const useDashboard = () => {
|
||||
const { user } = useAuth();
|
||||
const {
|
||||
getProductsList,
|
||||
getCurrentWeather,
|
||||
getSalesAnalytics,
|
||||
getDashboardStats,
|
||||
isLoading: dataLoading,
|
||||
error: dataError
|
||||
} = useData();
|
||||
isLoading: salesLoading,
|
||||
error: salesError
|
||||
} = useSales();
|
||||
const {
|
||||
getCurrentWeather,
|
||||
isLoading: externalLoading,
|
||||
error: externalError
|
||||
} = useExternal();
|
||||
|
||||
const {
|
||||
createSingleForecast,
|
||||
@@ -236,8 +240,8 @@ export const useDashboard = () => {
|
||||
|
||||
return {
|
||||
...dashboardData,
|
||||
isLoading: isLoading || dataLoading || forecastLoading,
|
||||
error: error || dataError || forecastError,
|
||||
isLoading: isLoading || salesLoading || externalLoading || forecastLoading,
|
||||
error: error || salesError || externalError || forecastError,
|
||||
reload: () => tenantId ? loadDashboardData(tenantId) : Promise.resolve(),
|
||||
clearError: () => setError(null)
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Real API hook for Order Suggestions using backend data
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { useData, useForecast } from '../api';
|
||||
import { useSales, useExternal, useForecast } from '../api';
|
||||
import { useTenantId } from './useTenantId';
|
||||
import type { DailyOrderItem, WeeklyOrderItem } from '../components/simple/OrderSuggestions';
|
||||
|
||||
@@ -44,9 +44,11 @@ export const useOrderSuggestions = () => {
|
||||
const {
|
||||
getProductsList,
|
||||
getSalesAnalytics,
|
||||
getDashboardStats,
|
||||
getDashboardStats
|
||||
} = useSales();
|
||||
const {
|
||||
getCurrentWeather
|
||||
} = useData();
|
||||
} = useExternal();
|
||||
const {
|
||||
createSingleForecast,
|
||||
getQuickForecasts,
|
||||
@@ -158,8 +160,8 @@ export const useOrderSuggestions = () => {
|
||||
console.log('📊 OrderSuggestions: Generating weekly suggestions for tenant:', tenantId);
|
||||
|
||||
// Get sales analytics for the past month
|
||||
const endDate = new Date().toISOString().split('T')[0];
|
||||
const startDate = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0];
|
||||
const endDate = new Date().toISOString();
|
||||
const startDate = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString();
|
||||
|
||||
let analytics: any = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user