Exporting Hooks from One File
This commit is contained in:
1 parent
c981b25ef9
commit
bcf883223b
4 files changed
+59
-64
No files matched your search
@@ -2,6 +2,57 @@ import { useState, useEffect } from "react";
|
|||||||
import { networkService } from "../main";
|
import { networkService } from "../main";
|
||||||
import { createToast } from "../Utils/toastUtils";
|
import { createToast } from "../Utils/toastUtils";
|
||||||
|
|
||||||
|
const useFetchChecksTeam = ({
|
||||||
|
teamId,
|
||||||
|
status,
|
||||||
|
sortOrder,
|
||||||
|
limit,
|
||||||
|
dateRange,
|
||||||
|
filter,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
}) => {
|
||||||
|
const [checks, setChecks] = useState(undefined);
|
||||||
|
const [checksCount, setChecksCount] = useState(undefined);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchChecks = async () => {
|
||||||
|
if (!teamId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
status,
|
||||||
|
teamId,
|
||||||
|
sortOrder,
|
||||||
|
limit,
|
||||||
|
dateRange,
|
||||||
|
filter,
|
||||||
|
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();
|
||||||
|
}, [teamId, status, sortOrder, limit, dateRange, filter, page, rowsPerPage]);
|
||||||
|
|
||||||
|
return [checks, checksCount, isLoading, networkError];
|
||||||
|
};
|
||||||
|
|
||||||
const useFetchChecksByMonitor = ({
|
const useFetchChecksByMonitor = ({
|
||||||
monitorId,
|
monitorId,
|
||||||
type,
|
type,
|
||||||
@@ -55,4 +106,4 @@ const useFetchChecksByMonitor = ({
|
|||||||
return [checks, checksCount, isLoading, networkError];
|
return [checks, checksCount, isLoading, networkError];
|
||||||
};
|
};
|
||||||
|
|
||||||
export { useFetchChecksByMonitor };
|
export { useFetchChecksByMonitor, useFetchChecksTeam };
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import { useState, useEffect } from "react";
|
|
||||||
import { networkService } from "../main";
|
|
||||||
import { createToast } from "../Utils/toastUtils";
|
|
||||||
|
|
||||||
const useFetchChecksTeam = ({
|
|
||||||
teamId,
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
}) => {
|
|
||||||
const [checks, setChecks] = useState(undefined);
|
|
||||||
const [checksCount, setChecksCount] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchChecks = async () => {
|
|
||||||
if (!teamId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
status,
|
|
||||||
teamId,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
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();
|
|
||||||
}, [teamId, status, sortOrder, limit, dateRange, filter, page, rowsPerPage]);
|
|
||||||
|
|
||||||
return [checks, checksCount, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { useFetchChecksTeam };
|
|
||||||
@@ -13,8 +13,8 @@ import { useSelector } from "react-redux";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useFetchChecksTeam } from "../../../../Hooks/checkHooksTeam";
|
import { useFetchChecksTeam } from "../../../../Hooks/checkHooks";
|
||||||
import { useFetchChecksByMonitor } from "../../../../Hooks/checkHooksMonitor";
|
import { useFetchChecksByMonitor } from "../../../../Hooks/checkHooks";
|
||||||
|
|
||||||
const IncidentTable = ({
|
const IncidentTable = ({
|
||||||
shouldRender,
|
shouldRender,
|
||||||
@@ -57,10 +57,10 @@ const IncidentTable = ({
|
|||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
});
|
});
|
||||||
|
|
||||||
const checks = selectedMonitor === "0" ? checksTeam : checksMonitor;
|
const checks = checksTeam || checksMonitor;
|
||||||
const checksCount = selectedMonitor === "0" ? checksCountTeam : checksCountMonitor;
|
const checksCount = checksCountTeam || checksCountMonitor;
|
||||||
const isLoading = selectedMonitor === "0" ? isLoadingTeam : isLoadingMonitor;
|
const isLoading = isLoadingTeam || isLoadingMonitor;
|
||||||
const networkError = selectedMonitor === "0" ? networkErrorTeam : networkErrorMonitor;
|
const networkError = networkErrorTeam || networkErrorMonitor;
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { useTheme } from "@emotion/react";
|
|||||||
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
||||||
import { useFetchUptimeMonitorById } from "../../../Hooks/monitorHooks";
|
import { useFetchUptimeMonitorById } from "../../../Hooks/monitorHooks";
|
||||||
import useCertificateFetch from "./Hooks/useCertificateFetch";
|
import useCertificateFetch from "./Hooks/useCertificateFetch";
|
||||||
import { useFetchChecksByMonitor } from "../../../Hooks/checkHooksMonitor";
|
import { useFetchChecksByMonitor } from "../../../Hooks/checkHooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
|||||||
Reference in new issue
Block a user