Files
Checkmate/client/src/Pages/Incidents/Components/LatestIncidentsPanel/IncidentItem.jsx
T

96 lines
2.3 KiB
React
Raw Normal View History

2025-12-17 18:51:34 -05:00
import PropTypes from "prop-types";
import { Box, Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react";
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
2026-01-26 02:06:37 +00:00
import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js";
import Icon from "@/Components/v1/Icon";
2025-12-17 18:51:34 -05:00
import { useTranslation } from "react-i18next";
import useGetIncidentsDuration from "../../hooks/useGetIncidentsDuration";
2025-12-17 18:51:34 -05:00
const IncidentItem = ({ incident }) => {
const { t } = useTranslation();
const theme = useTheme();
const isActive = incident.status === true;
const duration = useGetIncidentsDuration(incident, isActive);
2025-12-17 18:51:34 -05:00
const iconWrapperStyle = {
display: "flex",
justifyContent: "center",
2026-01-15 21:19:34 -05:00
mx: theme.spacing(2),
2025-12-17 18:51:34 -05:00
color: theme.palette.primary.contrastTextTertiary,
2026-01-15 21:19:34 -05:00
"& svg": {
width: 18,
height: 18,
},
2025-12-17 18:51:34 -05:00
"& svg path": {
stroke: "currentColor",
2026-01-15 21:19:34 -05:00
strokeWidth: 1.5,
2025-12-17 18:51:34 -05:00
},
};
return (
<Box
sx={{
2026-01-15 21:19:34 -05:00
display: "grid",
gridTemplateColumns: "1fr 100px 80px",
alignItems: "center",
gap: theme.spacing(2),
2025-12-17 18:51:34 -05:00
width: "100%",
py: theme.spacing(0.5),
}}
>
<Stack
2026-01-15 21:19:34 -05:00
direction="row"
alignItems="center"
gap={theme.spacing(2)}
2025-12-17 18:51:34 -05:00
>
2026-01-15 21:19:34 -05:00
<Box sx={iconWrapperStyle}>
2026-01-16 14:44:28 -05:00
<Icon
name="Globe"
size={18}
/>
2026-01-15 21:19:34 -05:00
</Box>
<Typography
variant="body1"
fontWeight={500}
noWrap
2025-12-17 18:51:34 -05:00
>
2026-01-15 21:19:34 -05:00
{incident.monitorName || t("incidentsPage.unknownMonitor")}
</Typography>
</Stack>
2025-12-17 18:51:34 -05:00
2026-01-15 21:19:34 -05:00
<Box sx={{ display: "flex", justifyContent: "center" }}>
<StatusLabel
status={isActive ? "down" : "up"}
text={isActive ? t("incidentsPage.active") : t("incidentsPage.resolved")}
customStyles={{
textTransform: "capitalize",
}}
/>
</Box>
2025-12-17 18:51:34 -05:00
2026-01-15 21:19:34 -05:00
<Typography
variant="body1"
fontWeight={500}
textAlign="right"
>
{duration}
</Typography>
2025-12-17 18:51:34 -05:00
</Box>
);
};
IncidentItem.propTypes = {
incident: PropTypes.shape({
_id: PropTypes.string,
id: PropTypes.string,
monitorId: PropTypes.string,
monitorName: PropTypes.string,
status: PropTypes.bool,
startTime: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
endTime: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
resolutionType: PropTypes.oneOf(["automatic", "manual"]),
}),
onClick: PropTypes.func,
};
export default IncidentItem;