New alert service

This commit is contained in:
Urtzi Alfaro
2025-12-05 20:07:01 +01:00
parent 1fe3a73549
commit 667e6e0404
393 changed files with 26002 additions and 61033 deletions

View File

@@ -1,37 +1,23 @@
/**
* Smart Action Handlers - Complete Implementation
* Handles execution of all 14 smart action types from enriched alerts
* Handles execution of all smart action types from enriched alerts
*
* NO PLACEHOLDERS - All action types fully implemented
*/
import { useNavigate } from 'react-router-dom';
import { SmartAction as ImportedSmartAction, SmartActionType } from '../api/types/events';
// ============================================================
// Types (matching backend SmartActionType enum)
// Types (using imported types from events.ts)
// ============================================================
export enum SmartActionType {
APPROVE_PO = 'approve_po',
REJECT_PO = 'reject_po',
MODIFY_PO = 'modify_po',
CALL_SUPPLIER = 'call_supplier',
NAVIGATE = 'navigate',
ADJUST_PRODUCTION = 'adjust_production',
START_PRODUCTION_BATCH = 'start_production_batch',
NOTIFY_CUSTOMER = 'notify_customer',
CANCEL_AUTO_ACTION = 'cancel_auto_action',
MARK_DELIVERY_RECEIVED = 'mark_delivery_received',
COMPLETE_STOCK_RECEIPT = 'complete_stock_receipt',
OPEN_REASONING = 'open_reasoning',
SNOOZE = 'snooze',
DISMISS = 'dismiss',
MARK_READ = 'mark_read',
}
// Legacy interface for backwards compatibility with existing handler code
export interface SmartAction {
label: string;
type: SmartActionType;
label?: string;
label_key?: string;
action_type: string;
type?: string; // For backward compatibility
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
metadata?: Record<string, any>;
disabled?: boolean;
@@ -40,6 +26,9 @@ export interface SmartAction {
consequence?: string;
}
// Re-export types from events.ts
export { SmartActionType };
// ============================================================
// Smart Action Handler Class
// ============================================================
@@ -65,7 +54,10 @@ export class SmartActionHandler {
try {
let result = false;
switch (action.type) {
// Support both legacy (type) and new (action_type) field names
const actionType = action.action_type || action.type;
switch (actionType) {
case SmartActionType.APPROVE_PO:
result = await this.handleApprovePO(action);
break;
@@ -78,6 +70,10 @@ export class SmartActionHandler {
result = this.handleModifyPO(action);
break;
case SmartActionType.VIEW_PO_DETAILS:
result = this.handleViewPODetails(action);
break;
case SmartActionType.CALL_SUPPLIER:
result = this.handleCallSupplier(action);
break;
@@ -127,8 +123,8 @@ export class SmartActionHandler {
break;
default:
console.warn('Unknown action type:', action.type);
this.onError?.(`Unknown action type: ${action.type}`);
console.warn('Unknown action type:', actionType);
this.onError?.(`Unknown action type: ${actionType}`);
return false;
}
@@ -269,6 +265,28 @@ export class SmartActionHandler {
return true;
}
/**
* 3.5. VIEW_PO_DETAILS - Open PO in view mode
*/
private handleViewPODetails(action: SmartAction): boolean {
const { po_id, tenant_id } = action.metadata || {};
if (!po_id) {
console.error('Missing PO ID');
this.onError?.('Missing PO ID for viewing details');
return false;
}
// Emit event to open PO modal in view mode
window.dispatchEvent(
new CustomEvent('po:open-details', {
detail: { po_id, tenant_id, mode: 'view' },
})
);
return true;
}
/**
* 4. CALL_SUPPLIER - Initiate phone call
*/