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

143 lines
3.5 KiB
React
Raw Normal View History

2025-02-02 21:26:48 -08:00
// Components
2025-02-04 15:26:24 -08:00
import { Typography, Stack, Box } from "@mui/material";
2025-02-02 21:26:48 -08:00
import GenericFallback from "../../../Components/GenericFallback";
import Fallback from "../../../Components/Fallback";
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";
2025-02-02 21:26:48 -08:00
// Utils
2025-02-04 13:06:42 -08:00
import { useState, useEffect } from "react";
2025-02-02 21:26:48 -08:00
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 { useNavigate } from "react-router-dom";
import { useStatusPageDelete } from "./Hooks/useStatusPageDelete";
2025-02-04 14:06:37 -08:00
2025-02-02 21:26:48 -08:00
const PublicStatus = () => {
2025-02-04 13:06:42 -08:00
// Local state
2025-02-02 21:26:48 -08:00
// Utils
const theme = useTheme();
const isAdmin = useIsAdmin();
2025-02-04 13:06:42 -08:00
const [statusPage, monitors, isLoading, networkError, fetchStatusPage] =
useStatusPageFetch();
const [deleteStatusPage, isDeleting] = useStatusPageDelete(fetchStatusPage);
const location = useLocation();
2025-02-04 15:30:28 -08:00
2025-02-04 13:06:42 -08:00
// Setup
const currentPath = location.pathname;
let sx = { paddingLeft: theme.spacing(20), paddingRight: theme.spacing(20) };
2025-02-04 15:45:28 -08:00
let link = undefined;
2025-02-04 13:06:42 -08:00
// Public status page
if (currentPath === "/status/public") {
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" &&
currentPath === "/status/public"
) {
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 &&
currentPath === "/status/public" &&
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 (
<Fallback
title="status page"
checks={[
"Display a list of monitors to track",
"Share your monitors with the public",
]}
link="/status/create"
isAdmin={isAdmin}
/>
);
}
2025-02-04 13:06:42 -08:00
return (
<Stack
gap={theme.spacing(10)}
alignItems="center"
sx={sx}
>
2025-02-04 15:26:24 -08:00
<ControlsHeader
statusPage={statusPage}
deleteStatusPage={deleteStatusPage}
isDeleting={isDeleting}
/>
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}
2025-02-04 13:06:42 -08:00
</Stack>
);
2025-02-02 21:26:48 -08:00
};
export default PublicStatus;