implement config
This commit is contained in:
1 parent
73df0837bb
commit
e9c7f1d7be
4 files changed
+52
-9
No files matched your search
@@ -5,13 +5,16 @@ import GenericFallback from "../../../Components/GenericFallback";
|
|||||||
import SkeletonLayout from "./Components/Skeleton";
|
import SkeletonLayout from "./Components/Skeleton";
|
||||||
//Utils
|
//Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useState, useRef, useCallback } from "react";
|
import { useState, useEffect, useRef, useCallback } from "react";
|
||||||
import { statusPageValidation } from "../../../Validation/validation";
|
import { statusPageValidation } from "../../../Validation/validation";
|
||||||
import { buildErrors } from "../../../Validation/error";
|
import { buildErrors } from "../../../Validation/error";
|
||||||
import { useMonitorsFetch } from "./Hooks/useMonitorsFetch";
|
import { useMonitorsFetch } from "./Hooks/useMonitorsFetch";
|
||||||
import { useCreateStatusPage } from "./Hooks/useCreateStatusPage";
|
import { useCreateStatusPage } from "./Hooks/useCreateStatusPage";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
import { useStatusPageFetch } from "../Status/Hooks/useStatusPageFetch";
|
||||||
|
|
||||||
//Constants
|
//Constants
|
||||||
const TAB_LIST = ["General settings", "Contents"];
|
const TAB_LIST = ["General settings", "Contents"];
|
||||||
|
|
||||||
@@ -40,12 +43,18 @@ const CreateStatusPage = () => {
|
|||||||
// Refs
|
// Refs
|
||||||
const intervalRef = useRef(null);
|
const intervalRef = useRef(null);
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
const location = useLocation();
|
||||||
|
const isCreate = location.pathname === "/status/create";
|
||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [monitors, isLoading, networkError] = useMonitorsFetch();
|
const [monitors, isLoading, networkError] = useMonitorsFetch();
|
||||||
const [createStatusPage, createSatusIsLoading, createStatusPageNetworkError] =
|
const [createStatusPage, createStatusIsLoading, createStatusPageNetworkError] =
|
||||||
useCreateStatusPage();
|
useCreateStatusPage(isCreate);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [statusPage, statusPageMonitors, statusPageIsLoading, statusPageNetworkError] =
|
||||||
|
useStatusPageFetch(isCreate);
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
const handleFormChange = (e) => {
|
const handleFormChange = (e) => {
|
||||||
@@ -145,6 +154,37 @@ const CreateStatusPage = () => {
|
|||||||
setTab(errorTabs[0]);
|
setTab(errorTabs[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
setSelectedMonitors(statusPageMonitors);
|
||||||
|
}, [isCreate, statusPage, statusPageMonitors]);
|
||||||
|
|
||||||
if (networkError === true) {
|
if (networkError === true) {
|
||||||
return (
|
return (
|
||||||
<GenericFallback>
|
<GenericFallback>
|
||||||
@@ -162,6 +202,7 @@ const CreateStatusPage = () => {
|
|||||||
|
|
||||||
if (isLoading) return <SkeletonLayout />;
|
if (isLoading) return <SkeletonLayout />;
|
||||||
|
|
||||||
|
// Load fields
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(10)}>
|
<Stack gap={theme.spacing(10)}>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const Controls = ({ deleteStatusPage, isDeleting }) => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={() => navigate(`/status/create`)}
|
onClick={() => navigate(`/status/configure`)}
|
||||||
sx={{
|
sx={{
|
||||||
px: theme.spacing(5),
|
px: theme.spacing(5),
|
||||||
"& svg": {
|
"& svg": {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const getMonitorWithPercentage = (monitor, theme) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const useStatusPageFetch = () => {
|
const useStatusPageFetch = (isCreate = false) => {
|
||||||
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);
|
||||||
@@ -59,9 +59,13 @@ const useStatusPageFetch = () => {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [authToken, theme]);
|
}, [authToken, theme]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isCreate === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fetchStatusPage();
|
fetchStatusPage();
|
||||||
}, [fetchStatusPage]);
|
}, [isCreate, fetchStatusPage]);
|
||||||
|
|
||||||
return [statusPage, monitors, isLoading, networkError, fetchStatusPage];
|
return [statusPage, monitors, isLoading, networkError, fetchStatusPage];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Components
|
// Components
|
||||||
import { Typography, Stack, Box } from "@mui/material";
|
import { Typography, Stack } from "@mui/material";
|
||||||
import GenericFallback from "../../../Components/GenericFallback";
|
import GenericFallback from "../../../Components/GenericFallback";
|
||||||
import Fallback from "../../../Components/Fallback";
|
import Fallback from "../../../Components/Fallback";
|
||||||
import AdminLink from "./Components/AdminLink";
|
import AdminLink from "./Components/AdminLink";
|
||||||
@@ -8,12 +8,10 @@ import SkeletonLayout from "./Components/Skeleton";
|
|||||||
import StatusBar from "./Components/StatusBar";
|
import StatusBar from "./Components/StatusBar";
|
||||||
import MonitorsList from "./Components/MonitorsList";
|
import MonitorsList from "./Components/MonitorsList";
|
||||||
// Utils
|
// Utils
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { useStatusPageFetch } from "./Hooks/useStatusPageFetch";
|
import { useStatusPageFetch } from "./Hooks/useStatusPageFetch";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { useStatusPageDelete } from "./Hooks/useStatusPageDelete";
|
import { useStatusPageDelete } from "./Hooks/useStatusPageDelete";
|
||||||
|
|
||||||
const PublicStatus = () => {
|
const PublicStatus = () => {
|
||||||
|
|||||||
Reference in new issue
Block a user