move DU status
This commit is contained in:
1 parent
e0e73ce520
commit
d0bb648492
5 files changed
+61
-17
No files matched your search
File renamed without changes.
+45
-7
@@ -9,8 +9,9 @@ import LogoPlaceholder from "../../../assets/Images/logo_placeholder.svg";
|
|||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useState } 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 { useCreateStatusPage } from "../../StatusPage/Create/Hooks/useCreateStatusPage";
|
import { useCreateStatusPage } from "../../StatusPage/Create/Hooks/useCreateStatusPage";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import { statusPageValidation } from "../../../Validation/validation";
|
import { statusPageValidation } from "../../../Validation/validation";
|
||||||
@@ -20,20 +21,25 @@ import { useNavigate } from "react-router-dom";
|
|||||||
|
|
||||||
const CreateStatus = () => {
|
const CreateStatus = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { monitorId } = useParams();
|
const { monitorId, url } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isCreate = location.pathname.startsWith("/distributed-uptime/status/create");
|
const isCreate = location.pathname.startsWith("/status/distributed/create");
|
||||||
const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate);
|
const [createStatusPage, isLoading, networkError] = useCreateStatusPage(isCreate);
|
||||||
|
|
||||||
|
const [statusPage, statusPageMonitors, statusPageIsLoading, statusPageNetworkError] =
|
||||||
|
useStatusPageFetch(isCreate, url);
|
||||||
|
|
||||||
const BREADCRUMBS = [
|
const BREADCRUMBS = [
|
||||||
{ name: "distributed uptime", path: "/distributed-uptime" },
|
{ name: "distributed uptime", path: "/distributed-uptime" },
|
||||||
{ name: "details", path: `/distributed-uptime/${monitorId}` },
|
{ name: "details", path: `/distributed-uptime/${monitorId}` },
|
||||||
{ name: "create status page", path: `` },
|
{ name: isCreate ? "create status page" : "edit status page", path: `` },
|
||||||
];
|
];
|
||||||
// Local state
|
// Local state
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
|
type: "distributed",
|
||||||
isPublished: false,
|
isPublished: false,
|
||||||
url: Math.floor(Math.random() * 1000000).toFixed(0),
|
url: url ?? Math.floor(Math.random() * 1000000).toFixed(0),
|
||||||
logo: undefined,
|
logo: undefined,
|
||||||
companyName: "",
|
companyName: "",
|
||||||
monitors: [monitorId],
|
monitors: [monitorId],
|
||||||
@@ -87,8 +93,9 @@ const CreateStatus = () => {
|
|||||||
if (typeof error === "undefined") {
|
if (typeof error === "undefined") {
|
||||||
const success = await createStatusPage({ form: formToSubmit });
|
const success = await createStatusPage({ form: formToSubmit });
|
||||||
if (success) {
|
if (success) {
|
||||||
createToast({ body: "Status page created successfully" });
|
const verb = isCreate ? "created" : "updated";
|
||||||
navigate(`/distributed-uptime/status/${form.url}`);
|
createToast({ body: `Status page ${verb} successfully` });
|
||||||
|
navigate(`/status/distributed/${form.url}`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -99,6 +106,36 @@ const CreateStatus = () => {
|
|||||||
setErrors((prev) => ({ ...prev, ...newErrors }));
|
setErrors((prev) => ({ ...prev, ...newErrors }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If we are configuring, populate fields
|
||||||
|
useEffect(() => {
|
||||||
|
if (isCreate) return;
|
||||||
|
if (typeof statusPage === "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let newLogo = undefined;
|
||||||
|
if (statusPage.logo) {
|
||||||
|
newLogo = {
|
||||||
|
src: `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}`,
|
||||||
|
name: "logo",
|
||||||
|
type: statusPage.logo.contentType,
|
||||||
|
size: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
setForm((prev) => {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
companyName: statusPage?.companyName,
|
||||||
|
isPublished: statusPage?.isPublished,
|
||||||
|
timezone: statusPage?.timezone,
|
||||||
|
monitors: statusPageMonitors.map((monitor) => monitor._id),
|
||||||
|
color: statusPage?.color,
|
||||||
|
logo: newLogo,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [isCreate, statusPage, statusPageMonitors]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(10)}>
|
<Stack gap={theme.spacing(10)}>
|
||||||
<Breadcrumbs list={BREADCRUMBS} />
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
@@ -159,6 +196,7 @@ const CreateStatus = () => {
|
|||||||
name="url"
|
name="url"
|
||||||
type="url"
|
type="url"
|
||||||
label="Your status page address"
|
label="Your status page address"
|
||||||
|
disabled={!isCreate}
|
||||||
value={form.url}
|
value={form.url}
|
||||||
onChange={handleFormChange}
|
onChange={handleFormChange}
|
||||||
helperText={errors["url"]}
|
helperText={errors["url"]}
|
||||||
File renamed without changes.
+5
-1
@@ -13,7 +13,11 @@ const useStatusPageFetchByUrl = ({ url }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchStatusPageByUrl = async () => {
|
const fetchStatusPageByUrl = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await networkService.getStatusPageByUrl({ authToken, url });
|
const response = await networkService.getStatusPageByUrl({
|
||||||
|
authToken,
|
||||||
|
url,
|
||||||
|
type: "distributed",
|
||||||
|
});
|
||||||
if (!response?.data?.data) return;
|
if (!response?.data?.data) return;
|
||||||
const statusPage = response.data.data;
|
const statusPage = response.data.data;
|
||||||
setStatusPage(statusPage);
|
setStatusPage(statusPage);
|
||||||
+11
-9
@@ -1,12 +1,12 @@
|
|||||||
//Components
|
//Components
|
||||||
import DistributedUptimeMap from "../Details/Components/DistributedUptimeMap";
|
import DistributedUptimeMap from "../../DistributedUptime/Details/Components/DistributedUptimeMap";
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import { Stack, Typography } from "@mui/material";
|
import { Stack, Typography } from "@mui/material";
|
||||||
import DeviceTicker from "../Details/Components/DeviceTicker";
|
import DeviceTicker from "../../DistributedUptime/Details/Components/DeviceTicker";
|
||||||
import DistributedUptimeResponseChart from "../Details/Components/DistributedUptimeResponseChart";
|
import DistributedUptimeResponseChart from "../../DistributedUptime/Details/Components/DistributedUptimeResponseChart";
|
||||||
import NextExpectedCheck from "../Details/Components/NextExpectedCheck";
|
import NextExpectedCheck from "../../DistributedUptime/Details/Components/NextExpectedCheck";
|
||||||
import Footer from "../Details/Components/Footer";
|
import Footer from "../../DistributedUptime/Details/Components/Footer";
|
||||||
import StatBoxes from "../Details/Components/StatBoxes";
|
import StatBoxes from "../../DistributedUptime/Details/Components/StatBoxes";
|
||||||
import ControlsHeader from "../../StatusPage/Status/Components/ControlsHeader";
|
import ControlsHeader from "../../StatusPage/Status/Components/ControlsHeader";
|
||||||
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
|
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
|
||||||
import GenericFallback from "../../../Components/GenericFallback";
|
import GenericFallback from "../../../Components/GenericFallback";
|
||||||
@@ -16,7 +16,7 @@ import SkeletonLayout from "./Components/Skeleton";
|
|||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useSubscribeToDetails } from "../Details/Hooks/useSubscribeToDetails";
|
import { useSubscribeToDetails } from "../../DistributedUptime/Details/Hooks/useSubscribeToDetails";
|
||||||
import { useStatusPageFetchByUrl } from "./Hooks/useStatusPageFetchByUrl";
|
import { useStatusPageFetchByUrl } from "./Hooks/useStatusPageFetchByUrl";
|
||||||
import { useStatusPageDelete } from "../../StatusPage/Status/Hooks/useStatusPageDelete";
|
import { useStatusPageDelete } from "../../StatusPage/Status/Hooks/useStatusPageDelete";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
@@ -24,7 +24,7 @@ import { useLocation } from "react-router-dom";
|
|||||||
const DistributedUptimeStatus = () => {
|
const DistributedUptimeStatus = () => {
|
||||||
const { url } = useParams();
|
const { url } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isPublic = location.pathname.startsWith("/distributed-uptime/status/public");
|
const isPublic = location.pathname.startsWith("/status/distributed/public");
|
||||||
|
|
||||||
// Local State
|
// Local State
|
||||||
const [dateRange, setDateRange] = useState("day");
|
const [dateRange, setDateRange] = useState("day");
|
||||||
@@ -84,7 +84,7 @@ const DistributedUptimeStatus = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Done loading, a status page exists but is not public
|
// Done loading, a status page exists but is not public
|
||||||
if (!statusPageIsLoading && statusPage.isPublished === false) {
|
if (!statusPageIsLoading && isPublic && statusPage.isPublished === false) {
|
||||||
return (
|
return (
|
||||||
<Stack sx={sx}>
|
<Stack sx={sx}>
|
||||||
<GenericFallback>
|
<GenericFallback>
|
||||||
@@ -141,6 +141,8 @@ const DistributedUptimeStatus = () => {
|
|||||||
isDeleting={isDeleting}
|
isDeleting={isDeleting}
|
||||||
isDeleteOpen={isDeleteOpen}
|
isDeleteOpen={isDeleteOpen}
|
||||||
setIsDeleteOpen={setIsDeleteOpen}
|
setIsDeleteOpen={setIsDeleteOpen}
|
||||||
|
url={url}
|
||||||
|
type="distributed"
|
||||||
/>
|
/>
|
||||||
<StatBoxes
|
<StatBoxes
|
||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
Reference in new issue
Block a user