Files
Checkmate/src/Pages/StatusPage/Status/index.jsx
T

157 lines
4.2 KiB
React
Raw Normal View History

2025-02-02 21:26:48 -08:00
// Components
2025-02-05 10:57:28 -08:00
import { Typography, Stack } from "@mui/material";
2025-02-02 21:26:48 -08:00
import GenericFallback from "../../../Components/GenericFallback";
2025-02-04 15:45:28 -08:00
import AdminLink from "./Components/AdminLink";
2025-02-04 15:26:24 -08:00
import ControlsHeader from "./Components/ControlsHeader";
2025-02-04 14:06:37 -08:00
import SkeletonLayout from "./Components/Skeleton";
2025-02-04 15:26:24 -08:00
import StatusBar from "./Components/StatusBar";
import MonitorsList from "./Components/MonitorsList";
import Dialog from "../../../Components/Dialog";
2025-02-02 21:26:48 -08:00
// Utils
import { useStatusPageFetch } from "./Hooks/useStatusPageFetch";
import { useTheme } from "@emotion/react";
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
2025-02-04 13:06:42 -08:00
import { useLocation } from "react-router-dom";
import { useStatusPageDelete } from "./Hooks/useStatusPageDelete";
import { useState } from "react";
import { useParams } from "react-router-dom";
2025-02-10 14:02:52 -08:00
import { useNavigate } from "react-router-dom";
2025-02-02 21:26:48 -08:00
const PublicStatus = () => {
const { url } = useParams();
2025-02-04 13:06:42 -08:00
// Local state
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
2025-02-02 21:26:48 -08:00
// Utils
const theme = useTheme();
2025-02-10 14:02:52 -08:00
const location = useLocation();
const navigate = useNavigate();
2025-02-04 13:06:42 -08:00
const [statusPage, monitors, isLoading, networkError, fetchStatusPage] =
useStatusPageFetch(false, url);
const [deleteStatusPage, isDeleting] = useStatusPageDelete(fetchStatusPage, url);
2025-02-04 15:30:28 -08:00
2025-02-04 13:06:42 -08:00
// Setup
let sx = { paddingLeft: theme.spacing(20), paddingRight: theme.spacing(20) };
2025-02-04 15:45:28 -08:00
let link = undefined;
const isPublic = location.pathname.startsWith("/status/uptime/public");
2025-02-04 13:06:42 -08:00
// Public status page
if (isPublic) {
2025-02-04 13:06:42 -08:00
sx = {
paddingTop: theme.spacing(20),
paddingLeft: "20vw",
paddingRight: "20vw",
};
2025-02-04 15:45:28 -08:00
link = <AdminLink />;
2025-02-04 13:06:42 -08:00
}
2025-02-04 15:45:28 -08:00
// Loading
2025-02-04 14:06:37 -08:00
if (isLoading) {
return <SkeletonLayout />;
}
2025-02-04 13:06:42 -08:00
2025-02-04 15:45:28 -08:00
// Error fetching data
2025-02-02 21:26:48 -08:00
if (networkError === true) {
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
Network error
</Typography>
<Typography>Please check your connection</Typography>
</GenericFallback>
);
}
2025-02-04 15:45:28 -08:00
// Public status page fallback
if (!isLoading && typeof statusPage === "undefined" && isPublic) {
2025-02-04 14:06:37 -08:00
return (
<Stack sx={sx}>
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
A public status page is not set up.
</Typography>
<Typography>Please contact to your administrator</Typography>
</GenericFallback>
</Stack>
);
}
2025-02-04 15:45:28 -08:00
// Finished loading, but status page is not public
if (!isLoading && isPublic && statusPage.isPublished === false) {
2025-02-04 14:06:37 -08:00
return (
<Stack sx={sx}>
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
This status page is not public.
</Typography>
<Typography>Please contact to your administrator</Typography>
</GenericFallback>
</Stack>
);
}
2025-02-04 15:45:28 -08:00
// Status page doesn't exist
if (!isLoading && typeof statusPage === "undefined") {
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
There's no status page here.
</Typography>
<Typography>Please contact to your administrator</Typography>
</GenericFallback>
2025-02-04 15:45:28 -08:00
);
}
2025-02-04 13:06:42 -08:00
return (
<Stack
gap={theme.spacing(10)}
alignItems="center"
sx={{ ...sx, position: "relative" }}
2025-02-04 13:06:42 -08:00
>
2025-02-04 15:26:24 -08:00
<ControlsHeader
statusPage={statusPage}
isDeleting={isDeleting}
isDeleteOpen={isDeleteOpen}
setIsDeleteOpen={setIsDeleteOpen}
url={url}
2025-02-04 15:26:24 -08:00
/>
2025-02-04 13:06:42 -08:00
<Typography variant="h2">Service status</Typography>
2025-02-04 15:45:28 -08:00
<StatusBar monitors={monitors} />
2025-02-04 15:26:24 -08:00
<MonitorsList monitors={monitors} />
2025-02-04 15:45:28 -08:00
{link}
<Dialog
title="Do you want to delete this status page?"
onConfirm={() => {
deleteStatusPage();
setIsDeleteOpen(false);
2025-02-10 14:02:52 -08:00
navigate("/status");
}}
onCancel={() => {
setIsDeleteOpen(false);
}}
open={isDeleteOpen}
confirmationButtonLabel="Yes, delete status page"
description="Once deleted, your status page cannot be retrieved."
isLoading={isDeleting || isLoading}
/>
2025-02-04 13:06:42 -08:00
</Stack>
);
2025-02-02 21:26:48 -08:00
};
export default PublicStatus;