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

189 lines
5.1 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 { Monitor } from "@/Types/Monitor";
import type { StatusPage, StatusPageResponse, StatusPageTheme } from "@/Types/StatusPage";
2026-04-29 10:51:40 -07:00
import { resolveStatusPageTheme } from "@/Types/StatusPage";
2026-02-02 20:39:16 +00:00
import { HeaderStatusPageControls } from "./Components/HeaderStatusPageControls";
import { StatusPageThemeProvider } from "./themes/StatusPageThemeProvider";
import { RefinedStatusPage } from "./themes/refined/RefinedStatusPage";
import { ModernStatusPage } from "./themes/modern/ModernStatusPage";
import { BoldStatusPage } from "./themes/bold/BoldStatusPage";
import { EditorialStatusPage } from "./themes/editorial/EditorialStatusPage";
import { BrowserFrame } from "./themes/BrowserFrame";
type ThemedRendererProps = {
statusPage: StatusPage;
monitors: (Monitor & { checks?: Monitor["recentChecks"] })[];
};
2026-04-29 10:51:40 -07:00
const THEMED_RENDERERS: Record<
StatusPageTheme,
React.ComponentType<ThemedRendererProps>
> = {
refined: RefinedStatusPage,
modern: ModernStatusPage,
bold: BoldStatusPage,
editorial: EditorialStatusPage,
};
2026-02-02 20:39:16 +00:00
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
2026-03-16 17:46:13 -04: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,
{},
{
refreshInterval: 10000,
}
);
2026-02-02 20:39:16 +00:00
const statusPage = data?.statusPage;
const monitors = data?.monitors ?? [];
2026-02-02 21:51:06 +00:00
if (!statusPage) return null;
2026-02-02 20:39:16 +00:00
if (monitors.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-04-29 10:51:40 -07:00
const ThemedRenderer = THEMED_RENDERERS[resolveStatusPageTheme(statusPage.theme)];
const themedRenderer = (
<ThemedRenderer
statusPage={statusPage}
monitors={monitors}
/>
2026-04-29 10:51:40 -07:00
);
if (themedRenderer) {
// Public route: render directly on the viewport, themed background covers everything.
if (isPublic) {
return (
<StatusPageThemeProvider
theme={statusPage.theme}
themeMode={statusPage.themeMode}
paintBody
>
{themedRenderer}
</StatusPageThemeProvider>
);
}
// Admin preview: wrap in a mock browser frame inside the admin shell.
const publicUrl = `${window.location.origin}/status/public/${statusPage.url}`;
return (
<BasePage
loading={isLoading}
error={error}
breadcrumbOverride={undefined}
sx={{ flex: 1, minHeight: 0 }}
>
<HeaderStatusPageControls
isAdmin={isAdmin}
statusPage={statusPage}
isPublic={false}
/>
<StatusPageThemeProvider
theme={statusPage.theme}
themeMode={statusPage.themeMode}
transparent
>
<BrowserFrame url={publicUrl}>{themedRenderer}</BrowserFrame>
</StatusPageThemeProvider>
</BasePage>
);
}
2026-02-02 20:39:16 +00:00
return (
<StatusPageThemeProvider
theme={statusPage.theme}
themeMode={statusPage.themeMode}
2026-02-02 20:39:16 +00:00
>
<BasePage
loading={isLoading}
error={error}
sx={sx}
breadcrumbOverride={isPublic ? [] : undefined}
>
<HeaderStatusPageControls
isAdmin={isAdmin}
statusPage={statusPage}
isPublic={isPublic}
/>
{logoSrc && (
<Box
component="img"
src={logoSrc}
alignSelf={"flex-start"}
alt={statusPage.companyName}
sx={{
maxHeight: 120,
maxWidth: "100%",
objectFit: "contain",
mb: 2,
}}
/>
)}
<StatusBar monitors={monitors} />
<MonitorsList
statusPage={statusPage}
monitors={monitors}
2026-02-03 22:52:20 +00:00
/>
</BasePage>
</StatusPageThemeProvider>
2026-02-02 20:39:16 +00:00
);
};
export default StatusPageView;