Files
Checkmate/Client/src/Pages/PageSpeed/card.jsx
T

80 lines
2.6 KiB
React
Raw Normal View History

2024-09-04 22:51:00 -07:00
import PageSpeedIcon from "../../assets/icons/page-speed.svg?react";
import { StatusLabel } from "../../Components/Label";
import { Box, Grid, Stack, Typography } from "@mui/material";
import { useNavigate } from "react-router";
import { useTheme } from "@emotion/react";
2024-09-14 12:36:20 -04:00
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
import { getLastChecked } from "../../Utils/monitorUtils";
import useUtils from "../Monitors/utils";
2024-09-04 22:51:00 -07:00
import PropTypes from "prop-types";
const Card = ({ monitor }) => {
const { determineState, pagespeedStatusMsg } = useUtils();
2024-09-04 22:51:00 -07:00
const theme = useTheme();
const navigate = useNavigate();
const monitorState = determineState(monitor);
2024-09-04 22:51:00 -07:00
return (
<Grid
item
lg={6}
flexGrow={1}
sx={{
"&:hover > .MuiStack-root": {
backgroundColor: theme.palette.background.accent,
},
}}
>
<Stack
direction="row"
gap={theme.spacing(6)}
p={theme.spacing(8)}
onClick={() => navigate(`/pagespeed/${monitor._id}`)}
2024-09-04 22:51:00 -07:00
border={1}
borderColor={theme.palette.border.light}
borderRadius={theme.shape.borderRadius}
backgroundColor={theme.palette.background.main}
sx={{
cursor: "pointer",
"& svg path": { stroke: theme.palette.other.icon, strokeWidth: 0.8 },
}}
>
<PageSpeedIcon
style={{ width: theme.spacing(8), height: theme.spacing(8) }}
/>
<Box flex={1}>
<Stack direction="row" justifyContent="space-between">
<Typography
component="h2"
mb={theme.spacing(2)}
2024-09-14 12:36:20 -04:00
fontSize={16}
2024-09-04 22:51:00 -07:00
color={theme.palette.primary.main}
>
{monitor.name}
2024-09-04 22:51:00 -07:00
</Typography>
<StatusLabel
status={monitorState}
text={pagespeedStatusMsg[monitorState] || "Pending..."}
customStyles={{ textTransform: "capitalize" }}
2024-09-04 22:51:00 -07:00
/>
</Stack>
2024-09-14 12:36:20 -04:00
<Typography>{monitor.url.replace(/^https?:\/\//, "")}</Typography>
<Typography mt={theme.spacing(12)}>
<Typography component="span" variant="body2" fontWeight={600}>
Last checked:{" "}
</Typography>
{formatDate(getLastChecked(monitor.checks, false))}{" "}
<Typography component="span" variant="body2" fontStyle="italic">
({formatDurationRounded(getLastChecked(monitor.checks))} ago)
</Typography>
2024-09-04 22:51:00 -07:00
</Typography>
</Box>
</Stack>
</Grid>
);
};
Card.propTypes = {
monitor: PropTypes.object.isRequired,
2024-09-04 22:51:00 -07:00
};
export default Card;