Start integrating the onboarding flow with backend 3
This commit is contained in:
@@ -25,7 +25,12 @@ function App() {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BrowserRouter>
|
||||
<BrowserRouter
|
||||
future={{
|
||||
v7_startTransition: true,
|
||||
v7_relativeSplatPath: true,
|
||||
}}
|
||||
>
|
||||
<ThemeProvider>
|
||||
<AuthProvider>
|
||||
<SSEProvider>
|
||||
|
||||
@@ -87,6 +87,26 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle connection events from backend
|
||||
eventSource.addEventListener('connection', (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
console.log('SSE connection confirmed:', data.message);
|
||||
} catch (error) {
|
||||
console.error('Error parsing connection event:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle heartbeat events
|
||||
eventSource.addEventListener('heartbeat', (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
console.log('SSE heartbeat received:', new Date(data.timestamp * 1000));
|
||||
} catch (error) {
|
||||
console.error('Error parsing heartbeat event:', error);
|
||||
}
|
||||
});
|
||||
|
||||
eventSource.onerror = (error) => {
|
||||
console.error('SSE connection error:', error);
|
||||
setIsConnected(false);
|
||||
@@ -104,7 +124,7 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle custom event types
|
||||
// Handle notification events (alerts and recommendations from alert_processor)
|
||||
eventSource.addEventListener('notification', (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
@@ -116,12 +136,23 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
|
||||
|
||||
setLastEvent(sseEvent);
|
||||
|
||||
// Determine toast type based on severity and item_type
|
||||
let toastType: 'info' | 'success' | 'warning' | 'error' = 'info';
|
||||
if (data.item_type === 'alert') {
|
||||
if (data.severity === 'urgent') toastType = 'error';
|
||||
else if (data.severity === 'high') toastType = 'error';
|
||||
else if (data.severity === 'medium') toastType = 'warning';
|
||||
else toastType = 'info';
|
||||
} else if (data.item_type === 'recommendation') {
|
||||
toastType = 'info';
|
||||
}
|
||||
|
||||
// Show toast notification
|
||||
showToast({
|
||||
type: data.type || 'info',
|
||||
type: toastType,
|
||||
title: data.title || 'Notificación',
|
||||
message: data.message,
|
||||
duration: data.persistent ? 0 : 5000,
|
||||
duration: data.severity === 'urgent' ? 0 : 5000, // Keep urgent alerts until dismissed
|
||||
});
|
||||
|
||||
// Trigger registered listeners
|
||||
@@ -145,10 +176,10 @@ export const SSEProvider: React.FC<SSEProviderProps> = ({ children }) => {
|
||||
|
||||
setLastEvent(sseEvent);
|
||||
|
||||
// Show inventory alert
|
||||
// Show inventory alert (high/urgent alerts from alert_processor)
|
||||
showToast({
|
||||
type: 'warning',
|
||||
title: 'Alerta de Inventario',
|
||||
type: data.severity === 'urgent' ? 'error' : 'warning',
|
||||
title: data.title || 'Alerta de Inventario',
|
||||
message: data.message,
|
||||
duration: 0, // Keep until dismissed
|
||||
});
|
||||
|
||||
@@ -23,6 +23,24 @@ import {
|
||||
|
||||
|
||||
class ProcurementService {
|
||||
private getTenantId(): string {
|
||||
const tenantStorage = localStorage.getItem('tenant-storage');
|
||||
if (tenantStorage) {
|
||||
try {
|
||||
const { state } = JSON.parse(tenantStorage);
|
||||
return state?.currentTenant?.id;
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
private getBaseUrl(): string {
|
||||
const tenantId = this.getTenantId();
|
||||
return `/tenants/${tenantId}`;
|
||||
}
|
||||
|
||||
// Purchase Order management
|
||||
async getPurchaseOrders(params?: {
|
||||
page?: number;
|
||||
@@ -43,34 +61,34 @@ class ProcurementService {
|
||||
}
|
||||
|
||||
const url = queryParams.toString()
|
||||
? `/purchase-orders?${queryParams.toString()}`
|
||||
: `/purchase-orders`;
|
||||
? `${this.getBaseUrl()}/purchase-orders?${queryParams.toString()}`
|
||||
: `${this.getBaseUrl()}/purchase-orders`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
async getPurchaseOrder(orderId: string): Promise<ApiResponse<PurchaseOrderResponse>> {
|
||||
return apiClient.get(`/purchase-orders/${orderId}`);
|
||||
return apiClient.get(`${this.getBaseUrl()}/purchase-orders/${orderId}`);
|
||||
}
|
||||
|
||||
async createPurchaseOrder(orderData: PurchaseOrderCreate): Promise<ApiResponse<PurchaseOrderResponse>> {
|
||||
return apiClient.post(`/purchase-orders`, orderData);
|
||||
return apiClient.post(`${this.getBaseUrl()}/purchase-orders`, orderData);
|
||||
}
|
||||
|
||||
async updatePurchaseOrder(orderId: string, orderData: PurchaseOrderUpdate): Promise<ApiResponse<PurchaseOrderResponse>> {
|
||||
return apiClient.put(`/purchase-orders/${orderId}`, orderData);
|
||||
return apiClient.put(`${this.getBaseUrl()}/purchase-orders/${orderId}`, orderData);
|
||||
}
|
||||
|
||||
async approvePurchaseOrder(orderId: string): Promise<ApiResponse<PurchaseOrderResponse>> {
|
||||
return apiClient.post(`/purchase-orders/${orderId}/approve`);
|
||||
return apiClient.post(`${this.getBaseUrl()}/purchase-orders/${orderId}/approve`);
|
||||
}
|
||||
|
||||
async sendPurchaseOrder(orderId: string, sendEmail: boolean = true): Promise<ApiResponse<{ message: string; sent_at: string }>> {
|
||||
return apiClient.post(`/purchase-orders/${orderId}/send`, { send_email: sendEmail });
|
||||
return apiClient.post(`${this.getBaseUrl()}/purchase-orders/${orderId}/send`, { send_email: sendEmail });
|
||||
}
|
||||
|
||||
async cancelPurchaseOrder(orderId: string, reason?: string): Promise<ApiResponse<PurchaseOrderResponse>> {
|
||||
return apiClient.post(`/purchase-orders/${orderId}/cancel`, { reason });
|
||||
return apiClient.post(`${this.getBaseUrl()}/purchase-orders/${orderId}/cancel`, { reason });
|
||||
}
|
||||
|
||||
// Supplier management
|
||||
@@ -86,42 +104,42 @@ class ProcurementService {
|
||||
}
|
||||
|
||||
const url = queryParams.toString()
|
||||
? `/suppliers?${queryParams.toString()}`
|
||||
: `/suppliers`;
|
||||
? `${this.getBaseUrl()}/suppliers?${queryParams.toString()}`
|
||||
: `${this.getBaseUrl()}/suppliers`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
async getSupplier(supplierId: string): Promise<ApiResponse<SupplierResponse>> {
|
||||
return apiClient.get(`/suppliers/${supplierId}`);
|
||||
return apiClient.get(`${this.getBaseUrl()}/suppliers/${supplierId}`);
|
||||
}
|
||||
|
||||
async createSupplier(supplierData: SupplierCreate): Promise<ApiResponse<SupplierResponse>> {
|
||||
return apiClient.post(`/suppliers`, supplierData);
|
||||
return apiClient.post(`${this.getBaseUrl()}/suppliers`, supplierData);
|
||||
}
|
||||
|
||||
async updateSupplier(supplierId: string, supplierData: SupplierUpdate): Promise<ApiResponse<SupplierResponse>> {
|
||||
return apiClient.put(`/suppliers/${supplierId}`, supplierData);
|
||||
return apiClient.put(`${this.getBaseUrl()}/suppliers/${supplierId}`, supplierData);
|
||||
}
|
||||
|
||||
async deleteSupplier(supplierId: string): Promise<ApiResponse<{ message: string }>> {
|
||||
return apiClient.delete(`/suppliers/${supplierId}`);
|
||||
return apiClient.delete(`${this.getBaseUrl()}/suppliers/${supplierId}`);
|
||||
}
|
||||
|
||||
async approveSupplier(supplierId: string, approval: SupplierApproval): Promise<ApiResponse<SupplierResponse>> {
|
||||
return apiClient.post(`/suppliers/${supplierId}/approve`, approval);
|
||||
return apiClient.post(`${this.getBaseUrl()}/suppliers/${supplierId}/approve`, approval);
|
||||
}
|
||||
|
||||
async getSupplierStatistics(): Promise<ApiResponse<SupplierStatistics>> {
|
||||
return apiClient.get(`/suppliers/statistics`);
|
||||
return apiClient.get(`${this.getBaseUrl()}/suppliers/statistics`);
|
||||
}
|
||||
|
||||
async getActiveSuppliers(): Promise<ApiResponse<SupplierSummary[]>> {
|
||||
return apiClient.get(`/suppliers/active`);
|
||||
return apiClient.get(`${this.getBaseUrl()}/suppliers/active`);
|
||||
}
|
||||
|
||||
async getTopSuppliers(limit: number = 10): Promise<ApiResponse<SupplierSummary[]>> {
|
||||
return apiClient.get(`/suppliers/top?limit=${limit}`);
|
||||
return apiClient.get(`${this.getBaseUrl()}/suppliers/top?limit=${limit}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,30 +164,30 @@ class ProcurementService {
|
||||
}
|
||||
|
||||
const url = queryParams.toString()
|
||||
? `/deliveries?${queryParams.toString()}`
|
||||
: `/deliveries`;
|
||||
? `${this.getBaseUrl()}/deliveries?${queryParams.toString()}`
|
||||
: `${this.getBaseUrl()}/deliveries`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
async getDelivery(deliveryId: string): Promise<ApiResponse<DeliveryResponse>> {
|
||||
return apiClient.get(`/deliveries/${deliveryId}`);
|
||||
return apiClient.get(`${this.getBaseUrl()}/deliveries/${deliveryId}`);
|
||||
}
|
||||
|
||||
async createDelivery(deliveryData: DeliveryCreate): Promise<ApiResponse<DeliveryResponse>> {
|
||||
return apiClient.post(`/deliveries`, deliveryData);
|
||||
return apiClient.post(`${this.getBaseUrl()}/deliveries`, deliveryData);
|
||||
}
|
||||
|
||||
async updateDelivery(deliveryId: string, deliveryData: Partial<DeliveryCreate>): Promise<ApiResponse<DeliveryResponse>> {
|
||||
return apiClient.put(`/deliveries/${deliveryId}`, deliveryData);
|
||||
return apiClient.put(`${this.getBaseUrl()}/deliveries/${deliveryId}`, deliveryData);
|
||||
}
|
||||
|
||||
async updateDeliveryStatus(deliveryId: string, status: DeliveryStatus, notes?: string): Promise<ApiResponse<DeliveryResponse>> {
|
||||
return apiClient.put(`/deliveries/${deliveryId}/status`, { status, notes });
|
||||
return apiClient.put(`${this.getBaseUrl()}/deliveries/${deliveryId}/status`, { status, notes });
|
||||
}
|
||||
|
||||
async confirmDeliveryReceipt(deliveryId: string, confirmation: DeliveryReceiptConfirmation): Promise<ApiResponse<DeliveryResponse>> {
|
||||
return apiClient.post(`/deliveries/${deliveryId}/confirm-receipt`, confirmation);
|
||||
return apiClient.post(`${this.getBaseUrl()}/deliveries/${deliveryId}/confirm-receipt`, confirmation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user