Fix new Frontend 15
This commit is contained in:
@@ -155,6 +155,73 @@ export const useData = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Get Products List
|
||||
* Add this method to the useData hook
|
||||
*/
|
||||
const getProductsList = useCallback(async (tenantId: string): Promise<string[]> => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
const products = await dataService.getProductsList(tenantId);
|
||||
|
||||
return products;
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to get products list';
|
||||
setError(message);
|
||||
throw error;
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Get Current Weather
|
||||
* Add this method to the useData hook
|
||||
*/
|
||||
const getCurrentWeather = useCallback(async (lat: number, lon: number) => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
const weather = await dataService.getCurrentWeather(lat, lon);
|
||||
|
||||
return weather;
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to get weather data';
|
||||
setError(message);
|
||||
throw error;
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Get Sales Analytics
|
||||
* Add this method to the useData hook
|
||||
*/
|
||||
const getSalesAnalytics = useCallback(async (
|
||||
tenantId: string,
|
||||
startDate?: string,
|
||||
endDate?: string
|
||||
) => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
const analytics = await dataService.getSalesAnalytics(tenantId, startDate, endDate);
|
||||
|
||||
return analytics;
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to get sales analytics';
|
||||
setError(message);
|
||||
throw error;
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return {
|
||||
salesData,
|
||||
dashboardStats,
|
||||
@@ -168,6 +235,9 @@ export const useData = () => {
|
||||
getDashboardStats,
|
||||
getRecentActivity,
|
||||
exportSalesData,
|
||||
getProductsList,
|
||||
getCurrentWeather,
|
||||
getSalesAnalytics,
|
||||
clearError: () => setError(null),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -179,6 +179,85 @@ export class DataService {
|
||||
params: { limit },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Products List from Sales Data
|
||||
* This should be added to the DataService class
|
||||
*/
|
||||
async getProductsList(tenantId: string): Promise<string[]> {
|
||||
const response = await apiClient.get(`/tenants/${tenantId}/sales/products`);
|
||||
|
||||
// Extract product names from the response
|
||||
return response.map((product: any) =>
|
||||
product.name || product.product_name || product
|
||||
).filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Current Weather Data
|
||||
* This should be added to the DataService class
|
||||
*/
|
||||
async getCurrentWeather(lat: number, lon: number): Promise<{
|
||||
temperature: number;
|
||||
description: string;
|
||||
precipitation: number;
|
||||
humidity?: number;
|
||||
wind_speed?: number;
|
||||
}> {
|
||||
return apiClient.get(`/data/weather/current`, {
|
||||
params: { lat, lon }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Weather Forecast
|
||||
* This should be added to the DataService class
|
||||
*/
|
||||
async getWeatherForecast(
|
||||
lat: number,
|
||||
lon: number,
|
||||
days: number = 7
|
||||
): Promise<any[]> {
|
||||
return apiClient.get(`/data/weather/forecast`, {
|
||||
params: { lat, lon, days }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Sales Summary by Period
|
||||
* This should be added to the DataService class
|
||||
*/
|
||||
async getSalesSummary(
|
||||
tenantId: string,
|
||||
period: 'daily' | 'weekly' | 'monthly' = 'daily'
|
||||
): Promise<any> {
|
||||
return apiClient.get(`/tenants/${tenantId}/sales/summary`, {
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Sales Analytics
|
||||
* This should be added to the DataService class
|
||||
*/
|
||||
async getSalesAnalytics(
|
||||
tenantId: string,
|
||||
startDate?: string,
|
||||
endDate?: string
|
||||
): Promise<{
|
||||
total_revenue: number;
|
||||
waste_reduction_percentage?: number;
|
||||
forecast_accuracy?: number;
|
||||
stockout_events?: number;
|
||||
}> {
|
||||
return apiClient.get(`/tenants/${tenantId}/sales/analytics`, {
|
||||
params: {
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const dataService = new DataService();
|
||||
|
||||
Reference in New Issue
Block a user