From 6f133ed7a02b9c7d4c985888c467d4b9a21e2eb8 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 12:15:07 +0800 Subject: [PATCH 1/7] add test all hook --- client/src/Hooks/useNotifications.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/client/src/Hooks/useNotifications.js b/client/src/Hooks/useNotifications.js index f19b76dde..303453655 100644 --- a/client/src/Hooks/useNotifications.js +++ b/client/src/Hooks/useNotifications.js @@ -174,6 +174,30 @@ const useTestNotification = () => { return [testNotification, isLoading, error]; }; +const useTestAllNotifications = () => { + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(undefined); + const { t } = useTranslation(); + const testAllNotifications = async ({ monitorId }) => { + try { + setIsLoading(true); + await networkService.testAllNotifications({ monitorId }); + createToast({ + body: t("notifications.test.success"), + }); + } catch (error) { + createToast({ + body: error.response?.data?.msg || error.message, + }); + setError(error); + } finally { + setIsLoading(false); + } + }; + + return [testAllNotifications, isLoading, error]; +}; + export { useCreateNotification, useGetNotificationsByTeamId, @@ -181,4 +205,5 @@ export { useGetNotificationById, useEditNotification, useTestNotification, + useTestAllNotifications, }; From 9bba8440caef7be1e2d15164e85409ddc16c4fcd Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 12:15:29 +0800 Subject: [PATCH 2/7] update monitor details header --- .../Components/MonitorDetailsControlHeader/index.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/Components/MonitorDetailsControlHeader/index.jsx b/client/src/Components/MonitorDetailsControlHeader/index.jsx index 8c9f845e9..d569ec840 100644 --- a/client/src/Components/MonitorDetailsControlHeader/index.jsx +++ b/client/src/Components/MonitorDetailsControlHeader/index.jsx @@ -14,6 +14,7 @@ import { useTheme } from "@mui/material/styles"; import { usePauseMonitor } from "../../Hooks/monitorHooks"; import { useSendTestEmail } from "../../Hooks/useSendTestEmail"; import { useTranslation } from "react-i18next"; +import { useTestAllNotifications } from "../../Hooks/useNotifications"; /** * MonitorDetailsControlHeader component displays the control header for monitor details. * It includes status display, pause/resume button, and a configure button for admins. @@ -39,7 +40,10 @@ const MonitorDetailsControlHeader = ({ const { t } = useTranslation(); const [pauseMonitor, isPausing, error] = usePauseMonitor(); - const [isSending, emailError, sendTestEmail] = useSendTestEmail(); + // const [isSending, emailError, sendTestEmail] = useSendTestEmail(); + + const [testAllNotifications, isSending, errorAllNotifications] = + useTestAllNotifications(); if (isLoading) { return ; @@ -62,10 +66,10 @@ const MonitorDetailsControlHeader = ({ loading={isSending} startIcon={} onClick={() => { - sendTestEmail(); + testAllNotifications({ monitorId: monitor?._id }); }} > - {t("sendTestEmail")} + {t("sendTestNotifications")}