2025-06-16 12:56:08 +05:30
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
import { networkService } from "../main";
|
|
|
|
|
import { createToast } from "../Utils/toastUtils";
|
|
|
|
|
|
2025-06-17 13:13:21 +05:30
|
|
|
const useFetchChecksTeam = ({
|
|
|
|
|
status,
|
|
|
|
|
sortOrder,
|
|
|
|
|
limit,
|
|
|
|
|
dateRange,
|
|
|
|
|
filter,
|
2025-06-24 14:44:02 +05:30
|
|
|
ack,
|
2025-06-17 13:13:21 +05:30
|
|
|
page,
|
|
|
|
|
rowsPerPage,
|
2025-06-17 13:27:51 +05:30
|
|
|
enabled = true,
|
2025-07-03 02:15:37 +05:30
|
|
|
updateTrigger,
|
2025-06-17 13:13:21 +05:30
|
|
|
}) => {
|
|
|
|
|
const [checks, setChecks] = useState(undefined);
|
|
|
|
|
const [checksCount, setChecksCount] = useState(undefined);
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [networkError, setNetworkError] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchChecks = async () => {
|
2025-06-17 13:27:51 +05:30
|
|
|
if (!enabled) {
|
2025-06-17 13:13:21 +05:30
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
|
status,
|
|
|
|
|
sortOrder,
|
|
|
|
|
limit,
|
|
|
|
|
dateRange,
|
|
|
|
|
filter,
|
2025-06-24 14:44:02 +05:30
|
|
|
ack,
|
2025-06-17 13:13:21 +05:30
|
|
|
page,
|
|
|
|
|
rowsPerPage,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
const res = await networkService.getChecksByTeam(config);
|
|
|
|
|
setChecks(res.data.data.checks);
|
|
|
|
|
setChecksCount(res.data.data.checksCount);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
setNetworkError(true);
|
|
|
|
|
createToast({ body: error.message });
|
|
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fetchChecks();
|
2025-07-03 02:15:37 +05:30
|
|
|
}, [
|
|
|
|
|
status,
|
|
|
|
|
sortOrder,
|
|
|
|
|
limit,
|
|
|
|
|
dateRange,
|
|
|
|
|
filter,
|
|
|
|
|
ack,
|
|
|
|
|
page,
|
|
|
|
|
rowsPerPage,
|
|
|
|
|
enabled,
|
|
|
|
|
updateTrigger,
|
|
|
|
|
]);
|
2025-06-17 13:13:21 +05:30
|
|
|
|
|
|
|
|
return [checks, checksCount, isLoading, networkError];
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-16 12:56:08 +05:30
|
|
|
const useFetchChecksByMonitor = ({
|
|
|
|
|
monitorId,
|
|
|
|
|
type,
|
|
|
|
|
status,
|
|
|
|
|
sortOrder,
|
|
|
|
|
limit,
|
|
|
|
|
dateRange,
|
|
|
|
|
filter,
|
2025-06-24 14:44:02 +05:30
|
|
|
ack,
|
2025-06-16 12:56:08 +05:30
|
|
|
page,
|
|
|
|
|
rowsPerPage,
|
2025-06-17 13:27:51 +05:30
|
|
|
enabled = true,
|
2025-07-03 02:15:37 +05:30
|
|
|
updateTrigger,
|
2025-06-16 12:56:08 +05:30
|
|
|
}) => {
|
2025-06-16 13:51:15 +05:30
|
|
|
const [checks, setChecks] = useState(undefined);
|
2025-06-16 12:56:08 +05:30
|
|
|
const [checksCount, setChecksCount] = useState(undefined);
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [networkError, setNetworkError] = useState(false);
|
|
|
|
|
|
2025-06-16 13:51:15 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchChecks = async () => {
|
2025-06-18 11:13:42 +05:30
|
|
|
if (!enabled || !type) {
|
2025-06-16 13:51:15 +05:30
|
|
|
return;
|
|
|
|
|
}
|
2025-06-16 12:56:08 +05:30
|
|
|
|
2025-06-16 13:51:15 +05:30
|
|
|
const config = {
|
|
|
|
|
monitorId,
|
|
|
|
|
type,
|
|
|
|
|
status,
|
|
|
|
|
sortOrder,
|
|
|
|
|
limit,
|
|
|
|
|
dateRange,
|
|
|
|
|
filter,
|
2025-06-24 14:44:02 +05:30
|
|
|
ack,
|
2025-06-16 13:51:15 +05:30
|
|
|
page,
|
|
|
|
|
rowsPerPage,
|
|
|
|
|
};
|
2025-06-16 12:56:08 +05:30
|
|
|
|
2025-06-16 13:51:15 +05:30
|
|
|
try {
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
const res = await networkService.getChecksByMonitor(config);
|
|
|
|
|
setChecks(res.data.data.checks);
|
|
|
|
|
setChecksCount(res.data.data.checksCount);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
setNetworkError(true);
|
|
|
|
|
createToast({ body: error.message });
|
|
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-06-16 12:56:08 +05:30
|
|
|
|
2025-06-16 13:51:15 +05:30
|
|
|
fetchChecks();
|
2025-06-17 13:27:51 +05:30
|
|
|
}, [
|
|
|
|
|
monitorId,
|
|
|
|
|
type,
|
|
|
|
|
status,
|
|
|
|
|
sortOrder,
|
|
|
|
|
limit,
|
|
|
|
|
dateRange,
|
|
|
|
|
filter,
|
2025-06-24 14:44:02 +05:30
|
|
|
ack,
|
2025-06-17 13:27:51 +05:30
|
|
|
page,
|
|
|
|
|
rowsPerPage,
|
|
|
|
|
enabled,
|
2025-07-03 02:15:37 +05:30
|
|
|
updateTrigger,
|
2025-06-17 13:27:51 +05:30
|
|
|
]);
|
2025-06-16 12:56:08 +05:30
|
|
|
|
2025-06-16 13:51:15 +05:30
|
|
|
return [checks, checksCount, isLoading, networkError];
|
2025-06-16 12:56:08 +05:30
|
|
|
};
|
|
|
|
|
|
2025-07-03 02:15:37 +05:30
|
|
|
const useFetchChecksSummaryByTeamId = ({ updateTrigger } = {}) => {
|
2025-07-01 18:10:35 +05:30
|
|
|
const [summary, setSummary] = useState(undefined);
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [networkError, setNetworkError] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchSummary = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
|
|
|
|
|
const res = await networkService.getChecksAndSummaryByTeamId();
|
|
|
|
|
setSummary(res.data.data);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
setNetworkError(true);
|
|
|
|
|
createToast({ body: error.message });
|
|
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fetchSummary();
|
2025-07-03 02:15:37 +05:30
|
|
|
}, [updateTrigger]);
|
2025-07-01 18:10:35 +05:30
|
|
|
|
|
|
|
|
return [summary, isLoading, networkError];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export { useFetchChecksByMonitor, useFetchChecksTeam, useFetchChecksSummaryByTeamId };
|