Files
Checkmate/client/src/Pages/PageSpeed/Monitors/index.jsx
T

90 lines
2.4 KiB
React
Raw Normal View History

2025-01-28 11:04:11 -08:00
// Components
import Breadcrumbs from "../../../Components/Breadcrumbs";
2025-01-29 15:06:41 -08:00
import { Stack, Typography } from "@mui/material";
2025-01-30 14:27:11 -08:00
import CreateMonitorHeader from "../../../Components/MonitorCreateHeader";
2025-01-28 11:04:11 -08:00
import MonitorCountHeader from "../../../Components/MonitorCountHeader";
import MonitorGrid from "./Components/MonitorGrid";
import Fallback from "../../../Components/Fallback";
2025-06-12 12:44:46 +08:00
import GenericFallback from "../../../Components/GenericFallback";
2025-01-28 11:04:11 -08:00
// Utils
import { useTheme } from "@emotion/react";
import { useSelector } from "react-redux";
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
2025-03-17 01:16:42 +05:30
import { useTranslation } from "react-i18next";
2025-06-12 12:44:46 +08:00
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
2025-01-28 11:04:11 -08:00
// Constants
const BREADCRUMBS = [{ name: `pagespeed`, path: "/pagespeed" }];
2025-06-12 12:44:46 +08:00
const TYPES = ["pagespeed"];
2025-01-28 11:06:24 -08:00
const PageSpeed = () => {
2025-01-28 11:04:11 -08:00
const theme = useTheme();
2025-03-17 01:16:42 +05:30
const { t } = useTranslation();
2025-01-28 11:04:11 -08:00
const isAdmin = useIsAdmin();
const { user } = useSelector((state) => state.auth);
2025-05-07 18:16:59 -04:00
const { pagespeedApiKey } = useSelector((state) => state.settings);
2025-01-28 11:04:11 -08:00
2025-06-12 12:44:46 +08:00
const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({
2025-01-28 11:04:11 -08:00
teamId: user.teamId,
2025-06-12 12:44:46 +08:00
limit: 10,
types: TYPES,
page: null,
rowsPerPage: null,
filter: null,
field: null,
order: null,
2025-01-28 11:04:11 -08:00
});
2025-01-29 12:32:09 -08:00
if (networkError === true) {
2025-01-29 15:06:41 -08:00
return (
<GenericFallback>
<Typography
variant="h1"
marginY={theme.spacing(4)}
color={theme.palette.primary.contrastTextTertiary}
>
2025-06-07 19:30:55 +02:00
{t("common.toasts.networkError")}
2025-01-29 15:06:41 -08:00
</Typography>
2025-06-07 19:30:55 +02:00
<Typography>{t("common.toasts.checkConnection")}</Typography>
2025-01-29 15:06:41 -08:00
</GenericFallback>
);
2025-01-29 12:32:09 -08:00
}
2025-01-28 11:04:11 -08:00
if (!isLoading && monitors?.length === 0) {
return (
<Fallback
title="pagespeed monitor"
checks={[
"Report on the user experience of a page",
"Help analyze webpage speed",
"Give suggestions on how the page can be improved",
]}
link="/pagespeed/create"
isAdmin={isAdmin}
showPageSpeedWarning={isAdmin && !pagespeedApiKey}
2025-01-28 11:04:11 -08:00
/>
);
}
return (
<Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} />
<CreateMonitorHeader
isAdmin={isAdmin}
2025-05-06 10:53:07 -07:00
isLoading={isLoading}
2025-01-28 11:04:11 -08:00
path="/pagespeed/create"
/>
<MonitorCountHeader
shouldRender={!isLoading}
2025-06-12 12:44:46 +08:00
monitorCount={monitorsSummary?.totalMonitors}
2025-01-28 11:04:11 -08:00
sx={{ mb: theme.spacing(8) }}
/>
<MonitorGrid
size={6}
shouldRender={!isLoading}
monitors={monitors}
/>
</Stack>
);
};
2025-01-28 11:06:24 -08:00
export default PageSpeed;