Files
bakery-ia/fdev-ffrontend/src/api/hooks/useSuppliers.ts

101 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-08-21 20:28:14 +02:00
// Simplified useSuppliers hook for TypeScript compatibility
import { useState } from 'react';
import {
SupplierSummary,
CreateSupplierRequest,
UpdateSupplierRequest,
SupplierSearchParams,
SupplierStatistics,
PurchaseOrder,
CreatePurchaseOrderRequest,
PurchaseOrderSearchParams,
PurchaseOrderStatistics,
Delivery,
DeliverySearchParams,
DeliveryPerformanceStats
} from '../services/suppliers.service';
2025-08-21 20:28:14 +02:00
export const useSuppliers = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
2025-08-21 20:28:14 +02:00
// Simple stub implementations
const getSuppliers = async (params?: SupplierSearchParams) => {
setIsLoading(true);
try {
2025-08-21 20:28:14 +02:00
// Mock data for now
return [];
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error');
throw err;
} finally {
setIsLoading(false);
}
};
2025-08-21 20:28:14 +02:00
const createSupplier = async (data: CreateSupplierRequest) => {
setIsLoading(true);
try {
// Mock implementation
return { id: '1', ...data } as any;
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error');
throw err;
} finally {
setIsLoading(false);
}
};
2025-08-21 20:28:14 +02:00
const updateSupplier = async (id: string, data: UpdateSupplierRequest) => {
setIsLoading(true);
try {
// Mock implementation
return { id, ...data } as any;
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error');
throw err;
} finally {
setIsLoading(false);
}
2025-08-21 20:28:14 +02:00
};
// Return all the expected properties/methods
return {
2025-08-21 20:28:14 +02:00
suppliers: [],
isLoading,
error,
2025-08-21 20:28:14 +02:00
getSuppliers,
createSupplier,
updateSupplier,
deleteSupplier: async () => {},
getSupplierStatistics: async () => ({} as SupplierStatistics),
getActiveSuppliers: async () => [] as SupplierSummary[],
getTopSuppliers: async () => [] as SupplierSummary[],
getSuppliersNeedingReview: async () => [] as SupplierSummary[],
approveSupplier: async () => {},
// Purchase orders
getPurchaseOrders: async () => [] as PurchaseOrder[],
createPurchaseOrder: async () => ({} as PurchaseOrder),
updatePurchaseOrderStatus: async () => ({} as PurchaseOrder),
// Deliveries
getDeliveries: async () => [] as Delivery[],
getTodaysDeliveries: async () => [] as Delivery[],
getDeliveryPerformanceStats: async () => ({} as DeliveryPerformanceStats),
};
2025-08-21 20:28:14 +02:00
};
// Re-export types
export type {
SupplierSummary,
CreateSupplierRequest,
UpdateSupplierRequest,
SupplierSearchParams,
SupplierStatistics,
PurchaseOrder,
CreatePurchaseOrderRequest,
PurchaseOrderSearchParams,
PurchaseOrderStatistics,
Delivery,
DeliverySearchParams,
DeliveryPerformanceStats
};