use correct hook
This commit is contained in:
1 parent
20fd2e313c
commit
aea2977f62
2 files changed
+6
-51
No files matched your search
@@ -1,46 +0,0 @@
|
|||||||
import { useEffect, useState, useCallback } from "react";
|
|
||||||
import { networkService } from "../../../../main";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { createToast } from "../../../../Utils/toastUtils";
|
|
||||||
|
|
||||||
const useDUStatusPageFetch = (isCreate = false, url) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
const [statusPage, setStatusPage] = useState(undefined);
|
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
|
||||||
const fetchStatusPage = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
const response = await networkService.getStatusPageByUrl({
|
|
||||||
authToken,
|
|
||||||
url,
|
|
||||||
type: "distributed",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response?.data?.data) return;
|
|
||||||
|
|
||||||
const statusPage = response.data.data;
|
|
||||||
setStatusPage(statusPage);
|
|
||||||
} catch (error) {
|
|
||||||
// If there is a 404, status page is not found
|
|
||||||
if (error?.response?.status === 404) {
|
|
||||||
setStatusPage(undefined);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
createToast({ body: error.message });
|
|
||||||
setNetworkError(true);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}, [authToken, url]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isCreate === true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fetchStatusPage();
|
|
||||||
}, [isCreate, fetchStatusPage]);
|
|
||||||
|
|
||||||
return [statusPage, isLoading, networkError, fetchStatusPage];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { useDUStatusPageFetch };
|
|
||||||
@@ -13,13 +13,13 @@ import MonitorList from "../../StatusPage/Create/Components/MonitorList";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useDUStatusPageFetch } from "./Hooks/useDUStatusPageFetch";
|
|
||||||
import { useCreateStatusPage } from "../../StatusPage/Create/Hooks/useCreateStatusPage";
|
import { useCreateStatusPage } from "../../StatusPage/Create/Hooks/useCreateStatusPage";
|
||||||
import { statusPageValidation } from "../../../Validation/validation";
|
import { statusPageValidation } from "../../../Validation/validation";
|
||||||
import { buildErrors } from "../../../Validation/error";
|
import { buildErrors } from "../../../Validation/error";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useMonitorsFetch } from "../../StatusPage/Create/Hooks/useMonitorsFetch";
|
import { useMonitorsFetch } from "../../StatusPage/Create/Hooks/useMonitorsFetch";
|
||||||
|
import { useStatusPageFetchByUrl } from "../Status/Hooks/useStatusPageFetchByUrl";
|
||||||
|
|
||||||
const CreateStatus = () => {
|
const CreateStatus = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -29,10 +29,11 @@ const CreateStatus = () => {
|
|||||||
|
|
||||||
const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate);
|
const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate);
|
||||||
|
|
||||||
const [statusPage, statusPageIsLoading, statusPageNetworkError] = useDUStatusPageFetch(
|
const [statusPageIsLoading, statusPageNetworkError, statusPage, _, isPublished] =
|
||||||
isCreate,
|
useStatusPageFetchByUrl({
|
||||||
url
|
url,
|
||||||
);
|
timeFrame: 30,
|
||||||
|
});
|
||||||
|
|
||||||
const [monitors, monitorsIsLoading, monitorsNetworkError] = useMonitorsFetch();
|
const [monitors, monitorsIsLoading, monitorsNetworkError] = useMonitorsFetch();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user