Delete legacy alerts
This commit is contained in:
@@ -12,7 +12,6 @@ import {
|
||||
InventoryItem,
|
||||
StockLevel,
|
||||
StockMovement,
|
||||
StockAlert,
|
||||
InventorySearchParams,
|
||||
CreateInventoryItemRequest,
|
||||
UpdateInventoryItemRequest,
|
||||
@@ -31,7 +30,6 @@ interface UseInventoryReturn {
|
||||
items: InventoryItem[];
|
||||
stockLevels: Record<string, StockLevel>;
|
||||
movements: StockMovement[];
|
||||
alerts: StockAlert[];
|
||||
dashboardData: InventoryDashboardData | null;
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
@@ -54,9 +52,6 @@ interface UseInventoryReturn {
|
||||
adjustStock: (itemId: string, adjustment: StockAdjustmentRequest) => Promise<StockMovement | null>;
|
||||
loadMovements: (params?: any) => Promise<void>;
|
||||
|
||||
// Alerts
|
||||
loadAlerts: () => Promise<void>;
|
||||
acknowledgeAlert: (alertId: string) => Promise<boolean>;
|
||||
|
||||
// Dashboard
|
||||
loadDashboard: () => Promise<void>;
|
||||
@@ -69,7 +64,6 @@ interface UseInventoryReturn {
|
||||
|
||||
interface UseInventoryDashboardReturn {
|
||||
dashboardData: InventoryDashboardData | null;
|
||||
alerts: StockAlert[];
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
refresh: () => Promise<void>;
|
||||
@@ -95,7 +89,6 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
|
||||
const [items, setItems] = useState<InventoryItem[]>([]);
|
||||
const [stockLevels, setStockLevels] = useState<Record<string, StockLevel>>({});
|
||||
const [movements, setMovements] = useState<StockMovement[]>([]);
|
||||
const [alerts, setAlerts] = useState<StockAlert[]>([]);
|
||||
const [dashboardData, setDashboardData] = useState<InventoryDashboardData | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -278,34 +271,6 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
|
||||
}
|
||||
}, [tenantId]);
|
||||
|
||||
// Load alerts
|
||||
const loadAlerts = useCallback(async () => {
|
||||
if (!tenantId) return;
|
||||
|
||||
try {
|
||||
const alertsData = await inventoryService.getStockAlerts(tenantId);
|
||||
setAlerts(alertsData);
|
||||
} catch (err: any) {
|
||||
console.error('Error loading alerts:', err);
|
||||
// Don't show toast error for this as it's not critical for forecast page
|
||||
}
|
||||
}, [tenantId]);
|
||||
|
||||
// Acknowledge alert
|
||||
const acknowledgeAlert = useCallback(async (alertId: string): Promise<boolean> => {
|
||||
if (!tenantId) return false;
|
||||
|
||||
try {
|
||||
await inventoryService.acknowledgeAlert(tenantId, alertId);
|
||||
setAlerts(prev => prev.map(a =>
|
||||
a.id === alertId ? { ...a, is_acknowledged: true, acknowledged_at: new Date().toISOString() } : a
|
||||
));
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
toast.error('Error acknowledging alert');
|
||||
return false;
|
||||
}
|
||||
}, [tenantId]);
|
||||
|
||||
// Load dashboard
|
||||
const loadDashboard = useCallback(async () => {
|
||||
@@ -337,10 +302,9 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
|
||||
await Promise.all([
|
||||
loadItems(),
|
||||
loadStockLevels(),
|
||||
loadAlerts(),
|
||||
loadDashboard()
|
||||
]);
|
||||
}, [loadItems, loadStockLevels, loadAlerts, loadDashboard]);
|
||||
}, [loadItems, loadStockLevels, loadDashboard]);
|
||||
|
||||
// Auto-load on mount
|
||||
useEffect(() => {
|
||||
@@ -354,7 +318,6 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
|
||||
items,
|
||||
stockLevels,
|
||||
movements,
|
||||
alerts,
|
||||
dashboardData,
|
||||
isLoading,
|
||||
error,
|
||||
@@ -372,10 +335,6 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
|
||||
adjustStock,
|
||||
loadMovements,
|
||||
|
||||
// Alerts
|
||||
loadAlerts,
|
||||
acknowledgeAlert,
|
||||
|
||||
// Dashboard
|
||||
loadDashboard,
|
||||
|
||||
@@ -391,7 +350,6 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
|
||||
export const useInventoryDashboard = (): UseInventoryDashboardReturn => {
|
||||
const { tenantId } = useTenantId();
|
||||
const [dashboardData, setDashboardData] = useState<InventoryDashboardData | null>(null);
|
||||
const [alerts, setAlerts] = useState<StockAlert[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@@ -402,13 +360,9 @@ export const useInventoryDashboard = (): UseInventoryDashboardReturn => {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const [dashboard, alertsData] = await Promise.all([
|
||||
inventoryService.getDashboardData(tenantId),
|
||||
inventoryService.getStockAlerts(tenantId)
|
||||
]);
|
||||
const dashboard = await inventoryService.getDashboardData(tenantId);
|
||||
|
||||
setDashboardData(dashboard);
|
||||
setAlerts(alertsData);
|
||||
} catch (err: any) {
|
||||
const errorMessage = err.response?.data?.detail || err.message || 'Error loading dashboard';
|
||||
setError(errorMessage);
|
||||
@@ -425,7 +379,6 @@ export const useInventoryDashboard = (): UseInventoryDashboardReturn => {
|
||||
|
||||
return {
|
||||
dashboardData,
|
||||
alerts,
|
||||
isLoading,
|
||||
error,
|
||||
refresh
|
||||
|
||||
@@ -105,22 +105,6 @@ export interface StockMovement {
|
||||
batch_info?: StockBatch;
|
||||
}
|
||||
|
||||
export interface StockAlert {
|
||||
id: string;
|
||||
item_id: string;
|
||||
alert_type: 'low_stock' | 'expired' | 'expiring_soon' | 'overstock';
|
||||
severity: 'low' | 'medium' | 'high' | 'critical';
|
||||
message: string;
|
||||
threshold_value?: number;
|
||||
current_value?: number;
|
||||
is_acknowledged: boolean;
|
||||
created_at: string;
|
||||
acknowledged_at?: string;
|
||||
acknowledged_by?: string;
|
||||
|
||||
// Related data
|
||||
item?: InventoryItem;
|
||||
}
|
||||
|
||||
// ========== REQUEST/RESPONSE TYPES ==========
|
||||
|
||||
@@ -404,32 +388,6 @@ export class InventoryService {
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
// ========== ALERTS ==========
|
||||
|
||||
/**
|
||||
* Get current stock alerts
|
||||
*/
|
||||
async getStockAlerts(tenantId: string): Promise<StockAlert[]> {
|
||||
// TODO: Map to correct endpoint when available
|
||||
return [];
|
||||
// return apiClient.get(`/tenants/${tenantId}/inventory/alerts`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acknowledge alert
|
||||
*/
|
||||
async acknowledgeAlert(tenantId: string, alertId: string): Promise<void> {
|
||||
return apiClient.post(`${this.baseEndpoint}/tenants/${tenantId}/inventory/alerts/${alertId}/acknowledge`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk acknowledge alerts
|
||||
*/
|
||||
async bulkAcknowledgeAlerts(tenantId: string, alertIds: string[]): Promise<void> {
|
||||
return apiClient.post(`${this.baseEndpoint}/tenants/${tenantId}/inventory/alerts/bulk-acknowledge`, {
|
||||
alert_ids: alertIds
|
||||
});
|
||||
}
|
||||
|
||||
// ========== DASHBOARD & ANALYTICS ==========
|
||||
|
||||
@@ -771,23 +729,6 @@ export class InventoryService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get inventory alerts
|
||||
*/
|
||||
async getInventoryAlerts(tenantId: string, params?: {
|
||||
alert_type?: string;
|
||||
severity?: string;
|
||||
status?: string;
|
||||
item_id?: string;
|
||||
limit?: number;
|
||||
}): Promise<any[]> {
|
||||
try {
|
||||
return await apiClient.get(`/tenants/${tenantId}/inventory/alerts`, { params });
|
||||
} catch (error) {
|
||||
console.error('❌ Error fetching inventory alerts:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get restock recommendations
|
||||
|
||||
@@ -344,20 +344,6 @@ export class OrdersService {
|
||||
return apiClient.get(`${this.basePath}/analytics/seasonal`, { params });
|
||||
}
|
||||
|
||||
// Alerts
|
||||
async getOrderAlerts(params?: {
|
||||
severity?: string;
|
||||
status?: string;
|
||||
limit?: number;
|
||||
}): Promise<any[]> {
|
||||
return apiClient.get(`${this.basePath}/alerts`, { params });
|
||||
}
|
||||
|
||||
async acknowledgeAlert(alertId: string): Promise<void> {
|
||||
return apiClient.post(`${this.basePath}/alerts/${alertId}/acknowledge`);
|
||||
}
|
||||
|
||||
async resolveAlert(alertId: string, resolution?: string): Promise<void> {
|
||||
return apiClient.post(`${this.basePath}/alerts/${alertId}/resolve`, { resolution });
|
||||
}
|
||||
}
|
||||
@@ -66,13 +66,11 @@ export interface ProductionDashboardData {
|
||||
equipment_in_use: number;
|
||||
current_efficiency: number;
|
||||
todays_production: number;
|
||||
alerts_count: number;
|
||||
};
|
||||
efficiency_trend: { date: string; efficiency: number }[];
|
||||
quality_trend: { date: string; quality: number }[];
|
||||
equipment_status: Equipment[];
|
||||
active_batches: ProductionBatch[];
|
||||
alerts: any[];
|
||||
}
|
||||
|
||||
export interface BatchCreateRequest {
|
||||
@@ -174,8 +172,7 @@ export class ProductionService {
|
||||
temperature: number;
|
||||
humidity: number;
|
||||
estimated_completion: string;
|
||||
alerts: any[];
|
||||
}> {
|
||||
}> {
|
||||
return apiClient.get(`${this.basePath}/batches/${batchId}/status`);
|
||||
}
|
||||
|
||||
@@ -295,20 +292,5 @@ export class ProductionService {
|
||||
return apiClient.get(`${this.basePath}/analytics/quality`, { params });
|
||||
}
|
||||
|
||||
// Alerts
|
||||
async getProductionAlerts(params?: {
|
||||
severity?: string;
|
||||
status?: string;
|
||||
limit?: number;
|
||||
}): Promise<any[]> {
|
||||
return apiClient.get(`${this.basePath}/alerts`, { params });
|
||||
}
|
||||
|
||||
async acknowledgeAlert(alertId: string): Promise<void> {
|
||||
return apiClient.post(`${this.basePath}/alerts/${alertId}/acknowledge`);
|
||||
}
|
||||
|
||||
async resolveAlert(alertId: string, resolution?: string): Promise<void> {
|
||||
return apiClient.post(`${this.basePath}/alerts/${alertId}/resolve`, { resolution });
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,6 @@ export interface SupplierDashboardData {
|
||||
quality_scores: number[];
|
||||
cost_savings: number[];
|
||||
};
|
||||
alerts: any[];
|
||||
contract_expirations: { supplier_name: string; days_until_expiry: number }[];
|
||||
}
|
||||
|
||||
@@ -320,23 +319,7 @@ export class SuppliersService {
|
||||
return apiClient.get(`${this.basePath}/analytics/risk-analysis`);
|
||||
}
|
||||
|
||||
// Alerts
|
||||
async getSupplierAlerts(params?: {
|
||||
severity?: string;
|
||||
status?: string;
|
||||
supplier_id?: string;
|
||||
limit?: number;
|
||||
}): Promise<any[]> {
|
||||
return apiClient.get(`${this.basePath}/alerts`, { params });
|
||||
}
|
||||
|
||||
async acknowledgeAlert(alertId: string): Promise<void> {
|
||||
return apiClient.post(`${this.basePath}/alerts/${alertId}/acknowledge`);
|
||||
}
|
||||
|
||||
async resolveAlert(alertId: string, resolution?: string): Promise<void> {
|
||||
return apiClient.post(`${this.basePath}/alerts/${alertId}/resolve`, { resolution });
|
||||
}
|
||||
|
||||
// Additional methods for hooks compatibility
|
||||
async getSupplierStatistics(): Promise<SupplierStatistics> {
|
||||
|
||||
Reference in New Issue
Block a user