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, };