From 6dc0f019e6ff2017362eaca94b86e3e044fa6df8 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Fri, 21 Mar 2025 16:04:21 -0700 Subject: [PATCH 1/5] Add notifications to our existing monitors --- .../NotificationIntegrationModal.jsx | 89 ++++++++++++------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx index 437b1ca2e..9758c070d 100644 --- a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx +++ b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx @@ -182,43 +182,64 @@ const NotificationIntegrationModal = ({ await sendTestNotification(type, config); }; - const handleSave = () => { - //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) - ); + // In NotificationIntegrationModal.jsx, update the handleSave function: - // Add each enabled notification with its configured fields - activeNotificationTypes.forEach(type => { - if (integrations[type.id]) { - const notificationObject = { - type: type.id - }; - - // Add each field value to the notification object - type.fields.forEach(field => { - const fieldKey = getFieldKey(type.id, field.id); - notificationObject[field.id] = integrations[fieldKey]; - }); - - filteredNotifications.push(notificationObject); +const handleSave = () => { + // Get existing notifications + 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 => { + + if (notification.platform) { + return !existingTypes.includes(notification.platform); } - }); + + return !existingTypes.includes(notification.type); + } + ); - // Update monitor with new notifications - setMonitor(prev => ({ - ...prev, - notifications: filteredNotifications - })); - - onClose(); - }; + // Add each enabled notification with its configured fields + activeNotificationTypes.forEach(type => { + if (integrations[type.id]) { + // Create a notification object + let notificationObject = { + type: "webhook", // All platform integrations use webhook type + 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 ( Date: Fri, 21 Mar 2025 16:25:06 -0700 Subject: [PATCH 2/5] Get rid of unnecessary comments. --- .../Components/NotificationIntegrationModal.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx index 9758c070d..7806ee37e 100644 --- a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx +++ b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx @@ -206,9 +206,9 @@ const handleSave = () => { // Add each enabled notification with its configured fields activeNotificationTypes.forEach(type => { if (integrations[type.id]) { - // Create a notification object + let notificationObject = { - type: "webhook", // All platform integrations use webhook type + type: "webhook", platform: type.id, // Set platform to identify the specific service config: {} }; From 980f055d5c951fa737f16b337ff26108b95e41c5 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Sun, 23 Mar 2025 21:13:49 -0700 Subject: [PATCH 3/5] Extracted strings. --- .../Components/NotificationIntegrationModal.jsx | 4 ++-- src/locales/gb.json | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx index 7806ee37e..93a4cf75b 100644 --- a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx +++ b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx @@ -49,11 +49,11 @@ const NotificationIntegrationModal = ({ // Helper to get the field state key with error handling const getFieldKey = (typeId, fieldId) => { if (typeof typeId !== 'string' || typeId === '') { - throw new Error('Invalid typeId provided to getFieldKey'); + throw new Error(t('errorInvalidTypeId')); } if (typeof fieldId !== 'string' || fieldId === '') { - throw new Error('Invalid fieldId provided to getFieldKey'); + throw new Error(t('errorInvalidFieldId')); } return `${typeId}${fieldId.charAt(0).toUpperCase() + fieldId.slice(1)}`; diff --git a/src/locales/gb.json b/src/locales/gb.json index 4bf9c4814..05a4bdc8e 100644 --- a/src/locales/gb.json +++ b/src/locales/gb.json @@ -184,6 +184,8 @@ "unsupportedType": "Unsupported notification type", "networkError": "Network error occurred" }, + "errorInvalidTypeId": "Invalid notification type provided", + "errorInvalidFieldId": "Invalid field ID provided", "testLocale": "testLocale", "add": "Add", "monitors": "monitors", From 0e63262876ed52665b0e7e60859e5a8c5622b504 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Sun, 23 Mar 2025 22:57:22 -0700 Subject: [PATCH 4/5] Add proptypes. --- .../Components/NotificationIntegrationModal.jsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx index 93a4cf75b..16ebd130c 100644 --- a/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx +++ b/src/Components/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx @@ -1,5 +1,6 @@ import { useState, useMemo } from "react"; import { useTranslation } from "react-i18next"; +import PropTypes from "prop-types"; import { Dialog, @@ -341,4 +342,12 @@ const handleSave = () => { ); }; +NotificationIntegrationModal.propTypes = { + open: PropTypes.bool.isRequired, + onClose: PropTypes.func.isRequired, + monitor: PropTypes.object.isRequired, + setMonitor: PropTypes.func.isRequired, + notificationTypes: PropTypes.array +}; + export default NotificationIntegrationModal; \ No newline at end of file From 5c6ea20b2c5a969d0ae2153d6d6370c978fe4344 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Mon, 24 Mar 2025 11:59:56 -0700 Subject: [PATCH 5/5] Comment out notification button. --- src/Pages/Uptime/Create/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pages/Uptime/Create/index.jsx b/src/Pages/Uptime/Create/index.jsx index bc757984d..6f38a3c83 100644 --- a/src/Pages/Uptime/Create/index.jsx +++ b/src/Pages/Uptime/Create/index.jsx @@ -415,7 +415,7 @@ const CreateMonitor = () => { onChange={(event) => handleNotifications(event, "email")} /> - + {/* - + */}