use url in hook
This commit is contained in:
1 parent
01d1f8e173
commit
55321ffc3c
3 files changed
+10
-7
No files matched your search
@@ -3,7 +3,7 @@ import { networkService } from "../../../../main";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { createToast } from "../../../../Utils/toastUtils";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
|
|
||||||
const useCreateStatusPage = (isCreate) => {
|
const useCreateStatusPage = (isCreate, url) => {
|
||||||
const { authToken, user } = useSelector((state) => state.auth);
|
const { authToken, user } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@@ -11,7 +11,7 @@ const useCreateStatusPage = (isCreate) => {
|
|||||||
const createStatusPage = async ({ form }) => {
|
const createStatusPage = async ({ form }) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
await networkService.createStatusPage({ authToken, user, form, isCreate });
|
await networkService.createStatusPage({ authToken, user, form, isCreate, url });
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setNetworkError(true);
|
setNetworkError(true);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { networkService } from "../../../../main";
|
|||||||
import { createToast } from "../../../../Utils/toastUtils";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const useStatusPageDelete = (fetchStatusPage, url = "/status/public") => {
|
const useStatusPageDelete = (fetchStatusPage, url) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { createToast } from "../../../../Utils/toastUtils";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
|
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
|
||||||
|
|
||||||
const useStatusPageFetch = (isCreate = false) => {
|
const useStatusPageFetch = (isCreate = false, url) => {
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [networkError, setNetworkError] = useState(false);
|
const [networkError, setNetworkError] = useState(false);
|
||||||
const [statusPage, setStatusPage] = useState(undefined);
|
const [statusPage, setStatusPage] = useState(undefined);
|
||||||
@@ -15,10 +15,13 @@ const useStatusPageFetch = (isCreate = false) => {
|
|||||||
const { getMonitorWithPercentage } = useMonitorUtils();
|
const { getMonitorWithPercentage } = useMonitorUtils();
|
||||||
const fetchStatusPage = useCallback(async () => {
|
const fetchStatusPage = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await networkService.getStatusPage({ authToken });
|
const response = await networkService.getStatusPageByUrl({
|
||||||
|
authToken,
|
||||||
|
url,
|
||||||
|
type: "uptime",
|
||||||
|
});
|
||||||
if (!response?.data?.data) return;
|
if (!response?.data?.data) return;
|
||||||
const { statusPage, monitors } = response.data.data;
|
const { statusPage, monitors } = response.data.data;
|
||||||
|
|
||||||
setStatusPage(statusPage);
|
setStatusPage(statusPage);
|
||||||
|
|
||||||
const monitorsWithPercentage = monitors.map((monitor) =>
|
const monitorsWithPercentage = monitors.map((monitor) =>
|
||||||
@@ -37,7 +40,7 @@ const useStatusPageFetch = (isCreate = false) => {
|
|||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [authToken, theme, getMonitorWithPercentage]);
|
}, [authToken, theme, getMonitorWithPercentage, url]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isCreate === true) {
|
if (isCreate === true) {
|
||||||
|
|||||||
Reference in new issue
Block a user