From 6f133ed7a02b9c7d4c985888c467d4b9a21e2eb8 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 12:15:07 +0800 Subject: [PATCH] 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, };