use new hook, fix logo and monitor loading
This commit is contained in:
1 parent
b9a89469c6
commit
844a2f0ae3
1 file changed
+13
-6
@@ -13,7 +13,7 @@ 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 { useStatusPageFetch } from "../../StatusPage/Status/Hooks/useStatusPageFetch";
|
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";
|
||||||
@@ -26,10 +26,13 @@ const CreateStatus = () => {
|
|||||||
const { monitorId, url } = useParams();
|
const { monitorId, url } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isCreate = typeof url === "undefined";
|
const isCreate = typeof url === "undefined";
|
||||||
|
|
||||||
const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate);
|
const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate);
|
||||||
|
|
||||||
const [statusPage, statusPageMonitors, statusPageIsLoading, statusPageNetworkError] =
|
const [statusPage, statusPageIsLoading, statusPageNetworkError] = useDUStatusPageFetch(
|
||||||
useStatusPageFetch(isCreate, url);
|
isCreate,
|
||||||
|
url
|
||||||
|
);
|
||||||
|
|
||||||
const [monitors, monitorsIsLoading, monitorsNetworkError] = useMonitorsFetch();
|
const [monitors, monitorsIsLoading, monitorsNetworkError] = useMonitorsFetch();
|
||||||
|
|
||||||
@@ -90,13 +93,15 @@ const CreateStatus = () => {
|
|||||||
let logoToSubmit = undefined;
|
let logoToSubmit = undefined;
|
||||||
|
|
||||||
// Handle image
|
// Handle image
|
||||||
if (typeof form.logo !== "undefined") {
|
if (typeof form.logo !== "undefined" && typeof form.logo.src === "undefined") {
|
||||||
logoToSubmit = {
|
logoToSubmit = {
|
||||||
src: URL.createObjectURL(form.logo),
|
src: URL.createObjectURL(form.logo),
|
||||||
name: form.logo.name,
|
name: form.logo.name,
|
||||||
type: form.logo.type,
|
type: form.logo.type,
|
||||||
size: form.logo.size,
|
size: form.logo.size,
|
||||||
};
|
};
|
||||||
|
} else if (typeof form.logo !== "undefined") {
|
||||||
|
logoToSubmit = form.logo;
|
||||||
}
|
}
|
||||||
const formToSubmit = { ...form };
|
const formToSubmit = { ...form };
|
||||||
if (typeof logoToSubmit !== "undefined") {
|
if (typeof logoToSubmit !== "undefined") {
|
||||||
@@ -143,12 +148,14 @@ const CreateStatus = () => {
|
|||||||
companyName: statusPage?.companyName,
|
companyName: statusPage?.companyName,
|
||||||
isPublished: statusPage?.isPublished,
|
isPublished: statusPage?.isPublished,
|
||||||
timezone: statusPage?.timezone,
|
timezone: statusPage?.timezone,
|
||||||
monitors: statusPageMonitors.map((monitor) => monitor._id),
|
monitors: statusPage?.monitors,
|
||||||
|
subMonitors: statusPage?.subMonitors.map((monitor) => monitor._id),
|
||||||
color: statusPage?.color,
|
color: statusPage?.color,
|
||||||
logo: newLogo,
|
logo: newLogo,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}, [isCreate, statusPage, statusPageMonitors]);
|
setSelectedMonitors(statusPage?.subMonitors);
|
||||||
|
}, [isCreate, statusPage]);
|
||||||
|
|
||||||
const imgSrc = form?.logo?.src
|
const imgSrc = form?.logo?.src
|
||||||
? form.logo.src
|
? form.logo.src
|
||||||
|
|||||||
Reference in new issue
Block a user