Update status page to use URL, no longer shows create fallback

This commit is contained in:
Alex Holliday committed 2025-02-10 13:48:10 -08:00
1 parent 61e319ef44
commit 9a67348a83
2 files changed
+43 -27

No files matched your search

@@ -9,17 +9,17 @@ import { useNavigate } from "react-router-dom";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
const Controls = ({ isDeleteOpen, setIsDeleteOpen, isDeleting }) => { const Controls = ({ isDeleteOpen, setIsDeleteOpen, isDeleting, url, type }) => {
const theme = useTheme(); const theme = useTheme();
const location = useLocation(); const location = useLocation();
const currentPath = location.pathname; const currentPath = location.pathname;
const navigate = useNavigate(); const navigate = useNavigate();
if (currentPath === "/status/public") { if (currentPath.startsWith("/status/uptime/public")) {
return null; return null;
} }
if (currentPath.startsWith("/distributed-uptime/status/public")) { if (currentPath.startsWith("/status/distributed/public")) {
return null; return null;
} }
@@ -42,7 +42,13 @@ const Controls = ({ isDeleteOpen, setIsDeleteOpen, isDeleting }) => {
<Button <Button
variant="contained" variant="contained"
color="secondary" color="secondary"
onClick={() => navigate(`/status/configure`)} onClick={() => {
if (type === "uptime") {
navigate(`/status/uptime/configure/${url}`);
} else {
navigate(`/status/distributed/configure/${url}`);
}
}}
sx={{ sx={{
px: theme.spacing(5), px: theme.spacing(5),
"& svg": { "& svg": {
@@ -62,11 +68,19 @@ const Controls = ({ isDeleteOpen, setIsDeleteOpen, isDeleting }) => {
Controls.propTypes = { Controls.propTypes = {
isDeleting: PropTypes.bool, isDeleting: PropTypes.bool,
url: PropTypes.string,
isDeleteOpen: PropTypes.bool.isRequired, isDeleteOpen: PropTypes.bool.isRequired,
setIsDeleteOpen: PropTypes.func.isRequired, setIsDeleteOpen: PropTypes.func.isRequired,
}; };
const ControlsHeader = ({ statusPage, isDeleting, isDeleteOpen, setIsDeleteOpen }) => { const ControlsHeader = ({
statusPage,
isDeleting,
isDeleteOpen,
setIsDeleteOpen,
url,
type = "uptime",
}) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
@@ -95,16 +109,20 @@ const ControlsHeader = ({ statusPage, isDeleting, isDeleteOpen, setIsDeleteOpen
isDeleting={isDeleting} isDeleting={isDeleting}
isDeleteOpen={isDeleteOpen} isDeleteOpen={isDeleteOpen}
setIsDeleteOpen={setIsDeleteOpen} setIsDeleteOpen={setIsDeleteOpen}
url={url}
type={type}
/> />
</Stack> </Stack>
); );
}; };
ControlsHeader.propTypes = { ControlsHeader.propTypes = {
url: PropTypes.string,
statusPage: PropTypes.object, statusPage: PropTypes.object,
isDeleting: PropTypes.bool, isDeleting: PropTypes.bool,
isDeleteOpen: PropTypes.bool.isRequired, isDeleteOpen: PropTypes.bool.isRequired,
setIsDeleteOpen: PropTypes.func.isRequired, setIsDeleteOpen: PropTypes.func.isRequired,
type: PropTypes.string,
}; };
export default ControlsHeader; export default ControlsHeader;
+20 -22
View File
@@ -16,25 +16,29 @@ import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import { useStatusPageDelete } from "./Hooks/useStatusPageDelete"; import { useStatusPageDelete } from "./Hooks/useStatusPageDelete";
import { useState } from "react"; import { useState } from "react";
import { useParams } from "react-router-dom";
const PublicStatus = () => { const PublicStatus = () => {
const { url } = useParams();
// Local state // Local state
const [isDeleteOpen, setIsDeleteOpen] = useState(false); const [isDeleteOpen, setIsDeleteOpen] = useState(false);
// Utils // Utils
const theme = useTheme(); const theme = useTheme();
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const [statusPage, monitors, isLoading, networkError, fetchStatusPage] = const [statusPage, monitors, isLoading, networkError, fetchStatusPage] =
useStatusPageFetch(); useStatusPageFetch(false, url);
const [deleteStatusPage, isDeleting] = useStatusPageDelete(fetchStatusPage); const [deleteStatusPage, isDeleting] = useStatusPageDelete(fetchStatusPage, url);
const location = useLocation(); const location = useLocation();
// Setup // Setup
const currentPath = location.pathname; const currentPath = location.pathname;
let sx = { paddingLeft: theme.spacing(20), paddingRight: theme.spacing(20) }; let sx = { paddingLeft: theme.spacing(20), paddingRight: theme.spacing(20) };
let link = undefined; let link = undefined;
const isPublic = location.pathname.startsWith("/status/uptime/public");
// Public status page // Public status page
if (currentPath === "/status/public") { if (isPublic) {
sx = { sx = {
paddingTop: theme.spacing(20), paddingTop: theme.spacing(20),
paddingLeft: "20vw", paddingLeft: "20vw",
@@ -65,11 +69,7 @@ const PublicStatus = () => {
} }
// Public status page fallback // Public status page fallback
if ( if (!isLoading && typeof statusPage === "undefined" && isPublic) {
!isLoading &&
typeof statusPage === "undefined" &&
currentPath === "/status/public"
) {
return ( return (
<Stack sx={sx}> <Stack sx={sx}>
<GenericFallback> <GenericFallback>
@@ -87,11 +87,7 @@ const PublicStatus = () => {
} }
// Finished loading, but status page is not public // Finished loading, but status page is not public
if ( if (!isLoading && isPublic && statusPage.isPublished === false) {
!isLoading &&
currentPath === "/status/public" &&
statusPage.isPublished === false
) {
return ( return (
<Stack sx={sx}> <Stack sx={sx}>
<GenericFallback> <GenericFallback>
@@ -111,15 +107,16 @@ const PublicStatus = () => {
// Status page doesn't exist // Status page doesn't exist
if (!isLoading && typeof statusPage === "undefined") { if (!isLoading && typeof statusPage === "undefined") {
return ( return (
<Fallback <GenericFallback>
title="status page" <Typography
checks={[ variant="h1"
"Display a list of monitors to track", marginY={theme.spacing(4)}
"Share your monitors with the public", color={theme.palette.primary.contrastTextTertiary}
]} >
link="/status/create" There's no status page here.
isAdmin={isAdmin} </Typography>
/> <Typography>Please contact to your administrator</Typography>
</GenericFallback>
); );
} }
@@ -134,6 +131,7 @@ const PublicStatus = () => {
isDeleting={isDeleting} isDeleting={isDeleting}
isDeleteOpen={isDeleteOpen} isDeleteOpen={isDeleteOpen}
setIsDeleteOpen={setIsDeleteOpen} setIsDeleteOpen={setIsDeleteOpen}
url={url}
/> />
<Typography variant="h2">Service status</Typography> <Typography variant="h2">Service status</Typography>
<StatusBar monitors={monitors} /> <StatusBar monitors={monitors} />