Spaces:
Running

axeronis commited on
Commit
730cd07
·
1 Parent(s): 035faf3

fix: ensure all notification settings are sent from frontend

Browse files
frontend/app/settings/notifications/page.tsx CHANGED
@@ -52,28 +52,15 @@ export default function NotificationSettingsPage() {
52
 
53
  if (settingsData) {
54
  setChannelId(settingsData.telegram_channel_id || '')
55
- setNotifyOrder(settingsData.notify_hot_leads !== false) // Wait, logic mapping check below!
56
- // settingsData has: notify_hot_leads, notify_qualification_complete, dashboard_enabled, telegram_enabled
57
- // But UI has: notifyOrder, notifyBooking, notifyLeads
58
-
59
- // Re-mapping based on NotificationSettingsResponse from backend:
60
- // telegram_enabled, telegram_chat_id, telegram_channel_id, dashboard_enabled,
61
- // notify_hot_leads, notify_qualification_complete,
62
- // notify_escalation_high, notify_escalation_medium, notify_escalation_low.
63
-
64
- // MISSING in Response: notify_on_order, notify_on_booking (from Tenant model legacy?)
65
- // Ah, NotificationSettings model (backend/models/notification.py) HAS notify_orders, notify_bookings!
66
- // But my NotificationSettingsResponse (api/notifications.py) DOES NOT HAVE THEM!
67
- // I missed them in Step 4758!
68
-
69
- // I need to add notify_orders and notify_bookings to NotificationSettingsResponse in api/notifications.py first!
70
- // Otherwise they will reset too!
71
-
72
- // For now let's map what we have correctly and I will do a follow-up tool call to fix backend response for order/booking.
73
 
 
 
 
 
74
  setNotifyLeads(settingsData.notify_hot_leads !== false)
75
  setNotifyQualification(settingsData.notify_qualification_complete !== false)
76
 
 
77
  setNotifyEscalationHigh(settingsData.notify_escalation_high !== false)
78
  setNotifyEscalationMedium(settingsData.notify_escalation_medium !== false)
79
  setNotifyEscalationLow(settingsData.notify_escalation_low === true)
@@ -93,19 +80,18 @@ export default function NotificationSettingsPage() {
93
  // Use correct endpoint for NotificationSettings
94
  await api.put('/api/v1/notifications/settings', {
95
  telegram_channel_id: channelId,
96
- dashboard_enabled: true, // Defaulting to true as per UI
 
 
97
  notify_hot_leads: notifyLeads,
98
  notify_qualification_complete: notifyQualification,
 
 
99
 
100
- // We need to verify if backend supports these escalation fields in UpdateNotificationSettingsRequest
101
- // Based on previous step, we didn't add them to UpdateNotificationSettingsRequest explicitly?
102
- // Let's check api/notifications.py.
103
- // Wait, in Step 4640 I ONLY added telegram_channel_id.
104
- // I did NOT add notify_escalation_... fields to UpdateNotificationSettingsRequest!
105
- // I need to update backend too if I want to save escalations.
106
- // For now, let's allow saving the main fields which fixes the user's immediate issue.
107
- // IMPORTANT: The backend Pydantic model UpdateNotificationSettingsRequest needs to support these keys,
108
- // otherwise they will be ignored or cause error.
109
  })
110
  queryClient.invalidateQueries({ queryKey: ['notification-settings'] })
111
  }
 
52
 
53
  if (settingsData) {
54
  setChannelId(settingsData.telegram_channel_id || '')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ // Correct Mapping for UI Toggles
57
+ // Note: notify_orders and notify_bookings are now available in API response
58
+ setNotifyOrder(settingsData.notify_orders !== false)
59
+ setNotifyBooking(settingsData.notify_bookings !== false)
60
  setNotifyLeads(settingsData.notify_hot_leads !== false)
61
  setNotifyQualification(settingsData.notify_qualification_complete !== false)
62
 
63
+ // Escalation Levels
64
  setNotifyEscalationHigh(settingsData.notify_escalation_high !== false)
65
  setNotifyEscalationMedium(settingsData.notify_escalation_medium !== false)
66
  setNotifyEscalationLow(settingsData.notify_escalation_low === true)
 
80
  // Use correct endpoint for NotificationSettings
81
  await api.put('/api/v1/notifications/settings', {
82
  telegram_channel_id: channelId,
83
+ dashboard_enabled: true,
84
+
85
+ // Main Toggles
86
  notify_hot_leads: notifyLeads,
87
  notify_qualification_complete: notifyQualification,
88
+ notify_orders: notifyOrder,
89
+ notify_bookings: notifyBooking,
90
 
91
+ // Escalation
92
+ notify_escalation_high: notifyEscalationHigh,
93
+ notify_escalation_medium: notifyEscalationMedium,
94
+ notify_escalation_low: notifyEscalationLow
 
 
 
 
 
95
  })
96
  queryClient.invalidateQueries({ queryKey: ['notification-settings'] })
97
  }