import Stack from "@mui/material/Stack"; import Typography from "@mui/material/Typography"; import { useTheme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import { useMemo } from "react"; import { useGet } from "@/Hooks/UseApi"; import { Dot } from "@/Components/design-elements"; import { LAYOUT } from "@/Utils/Theme/constants"; import { typographyLevels } from "@/Utils/Theme/Palette"; import { formatTimestamp } from "@/Utils/TimeUtils"; import { DashboardCard, CardMessage } from "../DashboardCard"; import { CardFigure, CardRow, CardRowLabel, CardStatLine } from "../CardPrimitives"; import type { IncidentSummary } from "@/Types/Incident"; import type { Notification } from "@/Types/Notification"; import type { MaintenanceWindow } from "@/Types/MaintenanceWindow"; import type { StatusPage } from "@/Types/StatusPage"; /** Free when Recent incidents is present — same summary call, shared by SWR. */ export const IncidentStatsCard = () => { const theme = useTheme(); const { t } = useTranslation(); const { data, isLoading, isValidating, error } = useGet( "/incidents/team/summary" ); return ( {data && ( 0 ? theme.palette.error.main : theme.palette.text.primary } /> {data.topMonitor?.monitorName && ( )} )} ); }; export const NotificationChannelsCard = () => { const theme = useTheme(); const { t } = useTranslation(); const { data, isLoading, isValidating, error } = useGet("/notifications/team"); // The response also carries accessToken and accountSid. Only `type` is read // here — credential fields must never reach the DOM. const byType = useMemo(() => { const counts = new Map(); for (const notification of data ?? []) { counts.set(notification.type, (counts.get(notification.type) ?? 0) + 1); } return [...counts.entries()].sort((a, b) => b[1] - a[1]); }, [data]); return ( {byType.length === 0 ? ( ) : ( {byType.map(([type, count]) => ( ))} )} ); }; export const MaintenanceCard = () => { const theme = useTheme(); const { t } = useTranslation(); const { data, isLoading, isValidating, error } = useGet<{ maintenanceWindows: MaintenanceWindow[]; maintenanceWindowCount: number; }>("/maintenance-window/team?page=0&rowsPerPage=0"); // `active` is a user on/off flag, not "running now" — compare the window // client-side. repeat > 0 means recurring, so `end` may sit in the past for // a window that is currently live. const { running, next } = useMemo(() => { const now = Date.now(); const windows = (data?.maintenanceWindows ?? []).filter((entry) => entry.active); const live = windows.filter((entry) => { const start = new Date(entry.start).getTime(); const end = new Date(entry.end).getTime(); return start <= now && (now <= end || entry.repeat > 0); }); const upcoming = windows .filter((entry) => new Date(entry.start).getTime() > now) .sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime()); return { running: live.length, next: upcoming[0] ?? null }; }, [data]); return ( {!data || data.maintenanceWindows.length === 0 ? ( ) : ( {next && ( )} )} ); }; export const StatusPagesCard = () => { const theme = useTheme(); const { t } = useTranslation(); const { data, isLoading, isValidating, error } = useGet("/status-page/team"); return ( {!data || data.length === 0 ? ( ) : ( {data.map((page) => ( {page.isPublished ? t("pages.dashboard.cards.statusPages.published") : t("pages.dashboard.cards.statusPages.draft")} ))} )} ); };