Files
Checkmate/client/src/Pages/StatusPage/Status/index.tsx
T

109 lines
3.0 KiB
TypeScript
Raw Normal View History

2026-02-20 18:13:39 +00:00
import { BasePage, BaseFallback } from "@/Components/design-elements";
2026-02-02 20:39:16 +00:00
import { StatusBar } from "@/Pages/StatusPage/Status/Components/StatusBar";
2026-02-02 20:42:27 +00:00
import { MonitorsList } from "@/Pages/StatusPage/Status/Components/MonitorsList";
2026-02-02 20:39:16 +00:00
import Typography from "@mui/material/Typography";
2026-02-03 19:03:17 +00:00
import { Link } from "react-router-dom";
import Stack from "@mui/material/Stack";
2026-02-03 22:52:20 +00:00
import Box from "@mui/material/Box";
2026-02-02 20:39:16 +00:00
2026-02-03 22:58:09 +00:00
import { useMediaQuery, useTheme } from "@mui/material";
2026-02-02 20:39:16 +00:00
import { useTranslation } from "react-i18next";
import { useIsAdmin } from "@/Hooks/useIsAdmin";
import { useLocation, useParams } from "react-router-dom";
import { useGet } from "@/Hooks/UseApi";
import type { StatusPageResponse } from "@/Types/StatusPage";
import { HeaderStatusPageControls } from "./Components/HeaderStatusPageControls";
const StatusPageView = () => {
2026-02-02 21:51:06 +00:00
const theme = useTheme();
2026-02-02 20:39:16 +00:00
const { t } = useTranslation();
const { url } = useParams();
const isAdmin = useIsAdmin();
const location = useLocation();
2026-02-03 22:58:09 +00:00
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
2026-02-03 21:14:16 +00:00
const isPublic = location.pathname.startsWith("/status/public");
2026-02-02 20:39:16 +00:00
const apiUrl = url ? `/status-page/${url}?type=uptime&type=infrastructure` : null;
2026-02-02 20:39:16 +00:00
const { data, isLoading, error } = useGet<StatusPageResponse>(apiUrl);
const statusPage = data?.statusPage;
const monitors = data?.monitors ?? [];
const infrastructureMonitors = data?.infrastructureMonitors ?? [];
2026-02-02 20:39:16 +00:00
2026-02-02 21:51:06 +00:00
if (!statusPage) return null;
2026-02-02 20:39:16 +00:00
if (monitors?.length === 0 && infrastructureMonitors?.length === 0) {
2026-02-03 19:03:17 +00:00
return (
<BasePage
loading={isLoading}
error={error}
breadcrumbOverride={isPublic ? [] : undefined}
>
<Stack alignItems={"center"}>
<BaseFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.text.secondary}
>
{t("pages.statusPages.details.empty.title")}
</Typography>
{isAdmin && (
2026-02-03 21:14:16 +00:00
<Link to={`/status/configure/${url}`}>
2026-02-03 19:03:17 +00:00
{t("pages.statusPages.details.empty.addMonitor")}
</Link>
)}
</BaseFallback>
</Stack>
</BasePage>
);
}
2026-02-02 21:51:06 +00:00
let sx: React.CSSProperties = {};
if (isPublic) {
sx.paddingTop = theme.spacing(20);
2026-02-03 22:58:09 +00:00
sx.paddingLeft = isSmall ? "5vw" : "20vw";
sx.paddingRight = isSmall ? "5vw" : "20vw";
2026-02-02 20:39:16 +00:00
}
2026-02-03 22:52:20 +00:00
const logoSrc = statusPage.logo?.data
? `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}`
: null;
2026-02-02 20:39:16 +00:00
return (
<BasePage
loading={isLoading}
error={error}
2026-02-02 21:51:06 +00:00
sx={sx}
breadcrumbOverride={isPublic ? [] : undefined}
2026-02-02 20:39:16 +00:00
>
<HeaderStatusPageControls
isAdmin={isAdmin}
statusPage={statusPage}
isPublic={isPublic}
/>
2026-02-03 22:52:20 +00:00
{logoSrc && (
<Box
component="img"
src={logoSrc}
alignSelf={"flex-start"}
alt={statusPage.companyName}
sx={{
maxHeight: 120,
maxWidth: "100%",
objectFit: "contain",
mb: 2,
}}
/>
)}
2026-02-02 20:39:16 +00:00
<StatusBar monitors={monitors} />
2026-02-02 20:42:27 +00:00
<MonitorsList
2026-02-02 21:51:06 +00:00
statusPage={statusPage}
2026-02-02 20:42:27 +00:00
monitors={monitors}
/>
2026-02-02 20:39:16 +00:00
</BasePage>
);
};
export default StatusPageView;