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

69 lines
2.1 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";
2024-09-16 12:53:59 -04:00
import { IconBox } from "./Details/styled";
2024-09-04 22:51:00 -07:00
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 (
2024-09-16 12:53:59 -04:00
<Grid item lg={6} flexGrow={1}>
<Box
2024-09-04 22:51:00 -07:00
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={{
2024-09-16 12:53:59 -04:00
display: "grid",
gridTemplateColumns: "34px 2fr 1fr",
columnGap: theme.spacing(5),
gridTemplateRows: "34px 1fr 3fr",
2024-09-04 22:51:00 -07:00
cursor: "pointer",
2024-09-16 12:53:59 -04:00
"&:hover": {
backgroundColor: theme.palette.background.accent,
},
2024-09-04 22:51:00 -07:00
}}
>
2024-09-16 12:53:59 -04:00
<IconBox>
<PageSpeedIcon />
</IconBox>
<Typography component="h2" variant="h2" alignSelf="center">
{monitor.name}
</Typography>
<StatusLabel
status={monitorState}
text={pagespeedStatusMsg[monitorState] || "Pending..."}
customStyles={{
width: "max-content",
textTransform: "capitalize",
alignSelf: "flex-start",
justifySelf: "flex-end",
}}
2024-09-04 22:51:00 -07:00
/>
2024-09-16 12:53:59 -04:00
<Typography
variant="body2"
mt={theme.spacing(-1)}
sx={{ gridColumnStart: 2 }}
>
{monitor.url}
</Typography>
</Box>
2024-09-04 22:51:00 -07:00
</Grid>
);
};
Card.propTypes = {
monitor: PropTypes.object.isRequired,
2024-09-04 22:51:00 -07:00
};
export default Card;