Files
Checkmate/client/src/pages/incidents/IncidentDetails.tsx
T

103 lines
3.5 KiB
TypeScript
Raw Normal View History

2025-12-07 04:38:37 +00:00
import { BasePage, StatBox } from "@/components/design-elements";
2025-12-08 02:29:52 +00:00
import ResolutionCard from "@/components/design-elements/ResolutionCard";
2025-12-07 04:38:37 +00:00
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
2025-12-12 10:54:26 -08:00
2025-12-07 04:38:37 +00:00
import { useTheme } from "@mui/material/styles";
2025-12-08 02:29:52 +00:00
import { useNavigate, useParams } from "react-router";
2025-12-07 04:38:37 +00:00
import { useGet } from "@/hooks/UseApi";
2025-12-16 19:09:08 +00:00
import type { ApiResponse } from "@/types/api";
2025-12-07 04:38:37 +00:00
import type { IIncident } from "@/types/incident";
import { formatDateWithTz } from "@/utils/TimeUtils";
import { useAppSelector } from "@/hooks/AppHooks";
import prettyMilliseconds from "pretty-ms";
2025-12-08 02:29:52 +00:00
import { getMonitorPath } from "@/utils/MonitorUtils";
import type { MonitorType } from "@/types/monitor";
2025-12-12 10:54:26 -08:00
import { useTranslation } from "react-i18next";
2025-12-07 04:38:37 +00:00
const IncidentDetailsPage = () => {
const theme = useTheme();
2025-12-12 10:54:26 -08:00
const { t } = useTranslation();
2025-12-07 04:38:37 +00:00
const { id } = useParams<{ id: string }>();
const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
2025-12-08 02:29:52 +00:00
const navigate = useNavigate();
2025-12-07 04:38:37 +00:00
const { response } = useGet<ApiResponse<IIncident>>(`/incidents/${id}`);
const incident = response?.data || null;
if (!incident) {
return null;
}
const startMs = new Date(incident.startedAt).getTime();
const endMs = incident.endedAt
? new Date(incident.endedAt).getTime()
: Date.now();
const duration = Math.max(0, endMs - startMs);
return (
<BasePage>
<Stack spacing={theme.spacing(8)}>
<Typography variant="h4" color="textPrimary">
2025-12-12 10:54:26 -08:00
{t("incidents.title")}
2025-12-07 04:38:37 +00:00
</Typography>
<Stack direction={{ xs: "column", md: "row" }} gap={theme.spacing(8)}>
<StatBox
2025-12-12 10:54:26 -08:00
title={t("monitors.common.stats.monitor")}
2025-12-07 04:38:37 +00:00
subtitle={incident.monitorId?.name || "N/A"}
2025-12-08 02:29:52 +00:00
onClick={() => {
const type = incident.monitorId.type as MonitorType;
const path = getMonitorPath(type);
const id = (incident.monitorId as any)?._id;
if (id) navigate(`/${path}/${id}`);
}}
2025-12-07 04:38:37 +00:00
/>
<StatBox
2025-12-12 10:54:26 -08:00
title={t("monitors.common.stats.start")}
2025-12-07 04:38:37 +00:00
subtitle={formatDateWithTz(
incident.startedAt,
"ddd, MMMM D, YYYY, HH:mm A",
uiTimezone
)}
/>
<StatBox
2025-12-12 10:54:26 -08:00
title={t("monitors.common.stats.end")}
2025-12-07 04:38:37 +00:00
subtitle={
incident.endedAt
? formatDateWithTz(
incident.endedAt,
"ddd, MMMM D, YYYY, HH:mm A",
uiTimezone
)
2025-12-12 10:54:26 -08:00
: t("monitors.common.stats.ongoing")
2025-12-07 04:38:37 +00:00
}
/>
</Stack>
2025-12-08 02:29:52 +00:00
<ResolutionCard
resolved={incident.resolved}
type={incident.resolutionType}
by={incident.resolvedBy?.email}
note={incident.resolutionNote}
timestampLabel={
incident.resolved && incident.endedAt
2025-12-12 10:54:26 -08:00
? `${t("incidents.details.resolutionCard.resolvedAt")}: ${formatDateWithTz(
2025-12-08 02:29:52 +00:00
incident.endedAt,
"ddd, MMMM D, YYYY, HH:mm A",
uiTimezone
)}`
2025-12-12 10:54:26 -08:00
: `${t("incidents.details.resolutionCard.ongoingSince")}: ${formatDateWithTz(
2025-12-08 02:29:52 +00:00
incident.startedAt,
"ddd, MMMM D, YYYY, HH:mm A",
uiTimezone
)}`
}
durationLabel={`Duration: ${prettyMilliseconds(duration, { secondsDecimalDigits: 0 })}`}
/>
2025-12-07 04:38:37 +00:00
</Stack>
</BasePage>
);
};
export default IncidentDetailsPage;