Feat: One Hook for Incidents Ack

This commit is contained in:
Br0wnHammer committed 2025-07-24 01:54:58 +05:30
1 parent 3650c400ca
commit b7093b5de5
6 files changed
+212 -123

No files matched your search

+27
View File
@@ -226,6 +226,32 @@ const useAckAllChecks = () => {
return [ackAllChecks, isLoading];
};
const useAcknowledgeChecks = () => {
const [isLoading, setIsLoading] = useState(false);
const { t } = useTranslation();
const acknowledge = async (setUpdateTrigger, monitorId = null) => {
setIsLoading(true);
try {
if (monitorId) {
await networkService.updateMonitorChecksStatus({ monitorId, ack: true });
} else {
await networkService.updateAllChecksStatus({ ack: true });
}
setUpdateTrigger((prev) => !prev);
} catch (error) {
const toastMessage = monitorId
? t("checkHooks.failureResolveMonitor")
: t("checkHooks.failureResolveAll");
createToast({ body: toastMessage });
} finally {
setIsLoading(false);
}
};
return { acknowledge, isLoading };
};
export {
useFetchChecksByMonitor,
useFetchChecksTeam,
@@ -233,4 +259,5 @@ export {
useResolveIncident,
useAckMonitorChecks,
useAckAllChecks,
useAcknowledgeChecks,
};
+16 -4
View File
@@ -11,7 +11,11 @@ import { Box, Button } from "@mui/material";
import { useTheme } from "@emotion/react";
import { useFetchMonitorsByTeamId } from "../../Hooks/monitorHooks";
import { useFetchChecksSummaryByTeamId } from "../../Hooks/checkHooks";
import { useAckAllChecks, useAckMonitorChecks } from "../../Hooks/checkHooks";
import {
useAckAllChecks,
useAckMonitorChecks,
useAcknowledgeChecks,
} from "../../Hooks/checkHooks";
import { useState, useEffect } from "react";
import NetworkError from "../../Components/GenericFallback/NetworkError";
import { useTranslation } from "react-i18next";
@@ -36,6 +40,7 @@ const Incidents = () => {
//Hooks
const [ackAllChecks, ackAllLoading] = useAckAllChecks();
const [ackMonitorChecks, ackMonitorLoading] = useAckMonitorChecks();
const { acknowledge, isLoadingAcknowledge } = useAcknowledgeChecks();
//Utils
const theme = useTheme();
@@ -71,6 +76,11 @@ const Incidents = () => {
}
};
const handleAcknowledge = () => {
const monitorId = selectedMonitor === "0" ? null : selectedMonitor;
acknowledge(setUpdateTrigger, monitorId);
};
if (networkError || networkErrorSummary) {
return (
<GenericFallback>
@@ -86,10 +96,12 @@ const Incidents = () => {
<Button
variant="contained"
color="accent"
onClick={handleAckAllChecks}
disabled={selectedMonitor === "0" ? ackAllLoading : ackMonitorLoading}
onClick={handleAcknowledge}
disabled={isLoadingAcknowledge}
>
{selectedMonitor === "0" ? t("incidentsPageActionResolveAll") : t("incidentsPageActionResolveMonitor")}
{selectedMonitor === "0"
? t("incidentsPageActionResolveAll")
: t("incidentsPageActionResolveMonitor")}
</Button>
</Box>
<StatusBoxes