Add notifications to our existing monitors

This commit is contained in:
Skorpios committed 2025-03-21 16:04:21 -07:00
1 parent c2b57d1df7
commit 6dc0f019e6
1 file changed
+55 -34
@@ -182,43 +182,64 @@ const NotificationIntegrationModal = ({
await sendTestNotification(type, config); await sendTestNotification(type, config);
}; };
const handleSave = () => { // In NotificationIntegrationModal.jsx, update the handleSave function:
//notifications array for selected integrations
const notifications = [...(monitor?.notifications || [])];
// Get all notification types IDs
const existingTypes = activeNotificationTypes.map(type => type.id);
// Filter out notifications that are configurable in this modal
const filteredNotifications = notifications.filter(
notification => !existingTypes.includes(notification.type)
);
// Add each enabled notification with its configured fields const handleSave = () => {
activeNotificationTypes.forEach(type => { // Get existing notifications
if (integrations[type.id]) { const notifications = [...(monitor?.notifications || [])];
const notificationObject = {
type: type.id // Get all notification types IDs
}; const existingTypes = activeNotificationTypes.map(type => type.id);
// Add each field value to the notification object // Filter out notifications that are configurable in this modal
type.fields.forEach(field => { const filteredNotifications = notifications.filter(
const fieldKey = getFieldKey(type.id, field.id); notification => {
notificationObject[field.id] = integrations[fieldKey];
}); if (notification.platform) {
return !existingTypes.includes(notification.platform);
filteredNotifications.push(notificationObject);
} }
});
return !existingTypes.includes(notification.type);
}
);
// Update monitor with new notifications // Add each enabled notification with its configured fields
setMonitor(prev => ({ activeNotificationTypes.forEach(type => {
...prev, if (integrations[type.id]) {
notifications: filteredNotifications // Create a notification object
})); let notificationObject = {
type: "webhook", // All platform integrations use webhook type
onClose(); platform: type.id, // Set platform to identify the specific service
}; config: {}
};
// Configure based on notification type
switch(type.id) {
case "slack":
case "discord":
notificationObject.config.webhookUrl = integrations[getFieldKey(type.id, 'webhook')];
break;
case "telegram":
notificationObject.config.botToken = integrations[getFieldKey(type.id, 'token')];
notificationObject.config.chatId = integrations[getFieldKey(type.id, 'chatId')];
break;
case "webhook":
notificationObject.config.webhookUrl = integrations[getFieldKey(type.id, 'url')];
break;
}
filteredNotifications.push(notificationObject);
}
});
// Update monitor with new notifications
setMonitor(prev => ({
...prev,
notifications: filteredNotifications
}));
onClose();
};
return ( return (
<Dialog <Dialog