From c84a547f35c4c7d0352a3c75a3b42fac1f8b5208 Mon Sep 17 00:00:00 2001 From: Skorpios Date: Sun, 16 Mar 2025 14:46:17 -0700 Subject: [PATCH] Extracted string to use i18n implementation. --- .../Hooks/useNotification.js | 5 ++++- src/Pages/Uptime/Create/index.jsx | 6 +++-- src/Utils/NetworkService.js | 22 +++++++++++++++++++ src/locales/en.json | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Components/NotificationIntegrationModal/Hooks/useNotification.js b/src/Components/NotificationIntegrationModal/Hooks/useNotification.js index 60b9783a4..08343760b 100644 --- a/src/Components/NotificationIntegrationModal/Hooks/useNotification.js +++ b/src/Components/NotificationIntegrationModal/Hooks/useNotification.js @@ -90,7 +90,10 @@ const useNotifications = () => { } try { - const response = await networkService.axiosInstance.post('/notifications/test-webhook', payload); + const response = await networkService.testNotification({ + platform: type, + payload: payload + }); if (response.data.success === true) { toast.success(t('notifications.testSuccess')); diff --git a/src/Pages/Uptime/Create/index.jsx b/src/Pages/Uptime/Create/index.jsx index 05b42766d..2f0908c24 100644 --- a/src/Pages/Uptime/Create/index.jsx +++ b/src/Pages/Uptime/Create/index.jsx @@ -4,6 +4,7 @@ import { useNavigate, useParams } from "react-router-dom"; import { useEffect } from "react"; import { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; +import { useTranslation } from "react-i18next"; // Utility and Network import { checkEndpointResolution } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice"; @@ -74,6 +75,7 @@ const CreateMonitor = () => { const dispatch = useDispatch(); const navigate = useNavigate(); const theme = useTheme(); + const { t } = useTranslation(); const { monitorId } = useParams(); const crumbs = [ { name: "uptime", path: "/uptime" }, @@ -418,8 +420,8 @@ const CreateMonitor = () => { variant="contained" color="accent" onClick={handleOpenNotificationModal} - > - Notification Integration + > + {t('notifications.integrationButton')} diff --git a/src/Utils/NetworkService.js b/src/Utils/NetworkService.js index ec8a10abf..8924d6466 100644 --- a/src/Utils/NetworkService.js +++ b/src/Utils/NetworkService.js @@ -669,6 +669,28 @@ class NetworkService { }); } + /** + * ************************************ + * Test a notification integration + * ************************************ + * + * @async + * @param {Object} config - The configuration object. + * @param {string} config.platform - The notification platform (slack, discord, telegram, webhook). + * @param {Object} config.payload - The payload with configuration for the notification. + * @returns {Promise} The response from the axios POST request. + */ + async testNotification(config) { + return this.axiosInstance.post('/notifications/test-webhook', { + platform: config.platform, + ...config.payload + }, { + headers: { + "Content-Type": "application/json", + }, + }); + } + /** * ************************************ * Creates a maintenance window diff --git a/src/locales/en.json b/src/locales/en.json index 7b99214d2..bf2cf3316 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -147,6 +147,7 @@ "enableNotifications": "Enable {{platform}} notifications", "testNotification": "Test notification", "addOrEditNotifications": "Add or edit notifications", + "integrationButton": "Notification Integration", "slack": { "label": "Slack", "description": "To enable Slack notifications, create a Slack app and enable incoming webhooks. After that, simply provide the webhook URL here.",