Add notifications to our existing monitors
This commit is contained in:
1 parent
c2b57d1df7
commit
6dc0f019e6
1 file changed
+32
-11
+32
-11
@@ -182,8 +182,10 @@ 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 handleSave = () => {
|
||||||
|
// Get existing notifications
|
||||||
const notifications = [...(monitor?.notifications || [])];
|
const notifications = [...(monitor?.notifications || [])];
|
||||||
|
|
||||||
// Get all notification types IDs
|
// Get all notification types IDs
|
||||||
@@ -191,21 +193,40 @@ const NotificationIntegrationModal = ({
|
|||||||
|
|
||||||
// Filter out notifications that are configurable in this modal
|
// Filter out notifications that are configurable in this modal
|
||||||
const filteredNotifications = notifications.filter(
|
const filteredNotifications = notifications.filter(
|
||||||
notification => !existingTypes.includes(notification.type)
|
notification => {
|
||||||
|
|
||||||
|
if (notification.platform) {
|
||||||
|
return !existingTypes.includes(notification.platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !existingTypes.includes(notification.type);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add each enabled notification with its configured fields
|
// Add each enabled notification with its configured fields
|
||||||
activeNotificationTypes.forEach(type => {
|
activeNotificationTypes.forEach(type => {
|
||||||
if (integrations[type.id]) {
|
if (integrations[type.id]) {
|
||||||
const notificationObject = {
|
// Create a notification object
|
||||||
type: type.id
|
let notificationObject = {
|
||||||
|
type: "webhook", // All platform integrations use webhook type
|
||||||
|
platform: type.id, // Set platform to identify the specific service
|
||||||
|
config: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add each field value to the notification object
|
// Configure based on notification type
|
||||||
type.fields.forEach(field => {
|
switch(type.id) {
|
||||||
const fieldKey = getFieldKey(type.id, field.id);
|
case "slack":
|
||||||
notificationObject[field.id] = integrations[fieldKey];
|
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);
|
filteredNotifications.push(notificationObject);
|
||||||
}
|
}
|
||||||
@@ -218,7 +239,7 @@ const NotificationIntegrationModal = ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
|
|||||||
Reference in new issue
Block a user