2026-09-19 01:29:10 +05:30
|
|
|
import Dialog from "@mui/material/Dialog";
|
|
|
|
|
import DialogTitle from "@mui/material/DialogTitle";
|
|
|
|
|
import DialogContent from "@mui/material/DialogContent";
|
|
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
|
import Stack from "@mui/material/Stack";
|
|
|
|
|
import IconButton from "@mui/material/IconButton";
|
|
|
|
|
import { X as XIcon } from "lucide-react";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { useGet } from "@/Hooks/UseApi";
|
2026-09-22 03:31:00 +05:30
|
|
|
import { useTheme } from "@mui/material";
|
|
|
|
|
import { SPACING } from "@/Utils/Theme/constants";
|
|
|
|
|
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
2026-09-19 01:29:10 +05:30
|
|
|
|
|
|
|
|
interface Incident {
|
|
|
|
|
id: string;
|
|
|
|
|
message: string | null;
|
|
|
|
|
startTime: string;
|
|
|
|
|
endTime: string | null;
|
|
|
|
|
statusCode: number | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IncidentModalProps {
|
|
|
|
|
url: string;
|
|
|
|
|
monitorId: string | null;
|
|
|
|
|
date: string | null;
|
2026-09-22 03:31:00 +05:30
|
|
|
timezone: string;
|
2026-09-19 01:29:10 +05:30
|
|
|
onClose: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-22 04:41:58 +05:30
|
|
|
export const IncidentModal = ({
|
|
|
|
|
url,
|
|
|
|
|
monitorId,
|
|
|
|
|
date,
|
|
|
|
|
timezone,
|
|
|
|
|
onClose,
|
|
|
|
|
}: IncidentModalProps) => {
|
2026-09-22 03:31:00 +05:30
|
|
|
const theme = useTheme();
|
2026-09-19 01:29:10 +05:30
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const open = Boolean(monitorId && date);
|
|
|
|
|
|
2026-09-22 22:06:38 +05:30
|
|
|
const { data, isLoading, error } = useGet<{ incidents: Incident[] }>(
|
2026-09-19 01:29:10 +05:30
|
|
|
open ? `/status-page/${url}/incidents/${monitorId}?date=${date}` : null,
|
|
|
|
|
{},
|
|
|
|
|
{ revalidateOnFocus: false }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog
|
|
|
|
|
open={open}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
maxWidth="sm"
|
|
|
|
|
fullWidth
|
|
|
|
|
>
|
|
|
|
|
<DialogTitle
|
|
|
|
|
sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}
|
|
|
|
|
>
|
2026-09-22 03:31:00 +05:30
|
|
|
{t("pages.statusPages.monitorsList.incidents.modalTitle", { date })} ({timezone})
|
2026-09-19 01:29:10 +05:30
|
|
|
<IconButton
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
size="small"
|
|
|
|
|
aria-label="close"
|
|
|
|
|
>
|
|
|
|
|
<XIcon size={20} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</DialogTitle>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
{isLoading ? (
|
2026-09-22 03:31:00 +05:30
|
|
|
<Typography mt={SPACING.SM}>
|
2026-09-19 01:29:10 +05:30
|
|
|
{t("pages.statusPages.monitorsList.incidents.loading")}
|
|
|
|
|
</Typography>
|
2026-09-22 22:06:38 +05:30
|
|
|
) : error ? (
|
|
|
|
|
<Typography
|
|
|
|
|
mt={SPACING.SM}
|
|
|
|
|
color="error"
|
|
|
|
|
>
|
|
|
|
|
{t(
|
|
|
|
|
"pages.statusPages.monitorsList.incidents.errorLoading",
|
|
|
|
|
"Failed to load incidents."
|
|
|
|
|
)}
|
|
|
|
|
</Typography>
|
2026-09-19 01:29:10 +05:30
|
|
|
) : data?.incidents && data.incidents.length > 0 ? (
|
|
|
|
|
<Stack
|
2026-09-22 03:31:00 +05:30
|
|
|
gap={SPACING.LG}
|
|
|
|
|
mt={SPACING.SM}
|
2026-09-19 01:29:10 +05:30
|
|
|
>
|
|
|
|
|
{data.incidents.map((incident) => (
|
|
|
|
|
<Stack
|
|
|
|
|
key={incident.id}
|
2026-09-22 03:31:00 +05:30
|
|
|
p={SPACING.LG}
|
2026-09-19 02:39:23 +05:30
|
|
|
border={1}
|
|
|
|
|
borderColor="divider"
|
2026-09-22 03:31:00 +05:30
|
|
|
borderRadius={theme.shape.borderRadius}
|
2026-09-19 01:29:10 +05:30
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
variant="subtitle2"
|
|
|
|
|
fontWeight="bold"
|
|
|
|
|
>
|
|
|
|
|
{incident.message ||
|
|
|
|
|
(incident.statusCode ? `Error ${incident.statusCode}` : "Incident")}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Typography
|
|
|
|
|
variant="body2"
|
2026-09-22 03:31:00 +05:30
|
|
|
color={theme.palette.text.secondary}
|
2026-09-19 01:29:10 +05:30
|
|
|
>
|
2026-09-22 03:31:00 +05:30
|
|
|
{formatDateWithTz(incident.startTime, "h:mm A", timezone)} -{" "}
|
2026-09-19 01:29:10 +05:30
|
|
|
{incident.endTime
|
2026-09-22 03:31:00 +05:30
|
|
|
? formatDateWithTz(incident.endTime, "h:mm A", timezone)
|
2026-09-19 01:29:10 +05:30
|
|
|
: t("pages.statusPages.monitorsList.incidents.ongoing")}
|
|
|
|
|
</Typography>
|
|
|
|
|
</Stack>
|
|
|
|
|
))}
|
|
|
|
|
</Stack>
|
|
|
|
|
) : (
|
2026-09-22 03:31:00 +05:30
|
|
|
<Typography mt={SPACING.SM}>
|
2026-09-19 01:29:10 +05:30
|
|
|
{t("pages.statusPages.monitorsList.incidents.noIncidents")}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|