@@ -23,20 +23,59 @@ interface K8sNotification {
2323
2424const ToastNotifications = ( ) => {
2525 useEffect ( ( ) => {
26- // Connect to WebSocket server
27- const socket = io ( import . meta. env . VITE_API_URL || 'http://localhost:3000' ) ;
26+ console . log ( '[Toast] 🚀 Component mounted, attempting WebSocket connection...' ) ;
27+ console . log ( '[Toast] 🔗 Connecting to:' , import . meta. env . VITE_API_URL || 'http://localhost:3000' ) ;
28+
29+ // Connect to WebSocket server with more options
30+ const socket = io ( import . meta. env . VITE_API_URL || 'http://localhost:3000' , {
31+ reconnection : true ,
32+ reconnectionAttempts : 5 ,
33+ reconnectionDelay : 1000 ,
34+ transports : [ 'websocket' , 'polling' ] ,
35+ upgrade : true ,
36+ forceNew : true ,
37+ } ) ;
38+
39+ // Connection events with detailed logging
40+ socket . on ( 'connect' , ( ) => {
41+ console . log ( '[Toast] ✅ Connected to WebSocket server' ) ;
42+ console . log ( '[Toast] 🆔 Socket ID:' , socket . id ) ;
43+ console . log ( '[Toast] 🌐 Socket connected:' , socket . connected ) ;
44+ toast . success ( 'Connected to monitoring server' ) ;
45+ } ) ;
46+
47+ socket . on ( 'disconnect' , ( reason ) => {
48+ console . log ( '[Toast] ❌ Disconnected from WebSocket server. Reason:' , reason ) ;
49+ toast . warning ( 'Disconnected from monitoring server' ) ;
50+ } ) ;
51+
52+ socket . on ( 'connect_error' , ( error ) => {
53+ console . error ( '[Toast] 🔥 Connection error:' , error ) ;
54+ toast . error ( 'Failed to connect to monitoring server' ) ;
55+ } ) ;
2856
2957 // Listen for K8s notifications
3058 socket . on ( 'k8s-notification' , ( notification : K8sNotification ) => {
31- console . log ( '[Toast] Received K8s notification:' , notification ) ;
59+ console . log ( '[Toast] 📢 Received K8s notification:' , notification ) ;
60+ console . log ( '[Toast] 📋 Notification details:' , {
61+ id : notification . id ,
62+ type : notification . type ,
63+ title : notification . title ,
64+ severity : notification . metadata . severity ,
65+ namespace : notification . metadata . namespace ,
66+ pod : notification . metadata . pod
67+ } ) ;
3268
3369 // Create toast message
3470 const message = `${ notification . title } \n${ notification . metadata . namespace } /${ notification . metadata . pod } \n${ notification . message } ` ;
71+
72+ console . log ( '[Toast] 🍞 Showing toast for:' , notification . type , notification . metadata . severity ) ;
3573
3674 // Show toast based on type and severity
3775 switch ( notification . type ) {
3876 case 'error' :
3977 if ( notification . metadata . severity === 'critical' ) {
78+ console . log ( '[Toast] 🔴 Showing CRITICAL error toast' ) ;
4079 toast . error ( message , {
4180 duration : 15000 ,
4281 action : {
@@ -46,30 +85,42 @@ const ToastNotifications = () => {
4685 } ,
4786 } ) ;
4887 } else {
88+ console . log ( '[Toast] 🟠 Showing HIGH error toast' ) ;
4989 toast . error ( message , { duration : 10000 } ) ;
5090 }
5191 break ;
5292 case 'warning' :
93+ console . log ( '[Toast] 🟡 Showing warning toast' ) ;
5394 toast . warning ( message , { duration : 7000 } ) ;
5495 break ;
5596 case 'info' :
97+ console . log ( '[Toast] 🔵 Showing info toast' ) ;
5698 toast . info ( message , { duration : 5000 } ) ;
5799 break ;
100+ default :
101+ console . log ( '[Toast] ❓ Unknown notification type:' , notification . type ) ;
102+ toast . info ( message , { duration : 5000 } ) ;
58103 }
59104 } ) ;
60105
61- socket . on ( 'connect' , ( ) => {
62- console . log ( '[Toast] Connected to WebSocket server' ) ;
63- toast . success ( 'Connected to monitoring server' ) ;
106+ // Listen for ALL events for debugging
107+ socket . onAny ( ( eventName , ... args ) => {
108+ console . log ( '[Toast] 📡 Received event:' , eventName , 'with data:' , args ) ;
64109 } ) ;
65110
66- socket . on ( 'disconnect' , ( ) => {
67- console . log ( '[Toast] Disconnected from WebSocket server' ) ;
68- toast . warning ( 'Disconnected from monitoring server' ) ;
69- } ) ;
111+ // Test connection after a short delay
112+ setTimeout ( ( ) => {
113+ console . log ( '[Toast] 🧪 Connection status check:' ) ;
114+ console . log ( '[Toast] 🔌 Connected:' , socket . connected ) ;
115+ console . log ( '[Toast] 🆔 Socket ID:' , socket . id ) ;
116+
117+ // Test toast to make sure Sonner is working
118+ toast . info ( 'Toast component loaded and ready!' ) ;
119+ } , 2000 ) ;
70120
71121 // Cleanup on unmount
72122 return ( ) => {
123+ console . log ( '[Toast] 🧹 Component unmounting, disconnecting socket...' ) ;
73124 socket . disconnect ( ) ;
74125 } ;
75126 } , [ ] ) ;
0 commit comments