refactor: extracting condition for showing create monitor button
This commit is contained in:
1 parent
32b0c2039e
commit
63a4223d9c
1 file changed
+23
-24
@@ -4,13 +4,7 @@ import { useSelector, useDispatch } from "react-redux";
|
|||||||
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import {
|
import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
CircularProgress,
|
|
||||||
Stack,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import Fallback from "./fallback";
|
import Fallback from "./fallback";
|
||||||
@@ -40,16 +34,18 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch]);
|
||||||
|
|
||||||
const loading =
|
console.log(monitorState);
|
||||||
monitorState?.isLoading &&
|
const loading = true;
|
||||||
monitorState?.monitorsSummary?.monitors?.length === 0;
|
/* monitorState?.isLoading &&
|
||||||
|
monitorState?.monitorsSummary?.monitors?.length === 0; */
|
||||||
|
const canCreateMonitor =
|
||||||
|
isAdmin && monitorState?.monitorsSummary?.monitors?.length !== 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className="monitors" gap={theme.spacing(8)}>
|
<Stack
|
||||||
{loading ? (
|
className="monitors"
|
||||||
<SkeletonLayout />
|
gap={theme.spacing(8)}
|
||||||
) : (
|
>
|
||||||
<>
|
|
||||||
<Box>
|
<Box>
|
||||||
<Breadcrumbs list={[{ name: `monitors`, path: "/monitors" }]} />
|
<Breadcrumbs list={[{ name: `monitors`, path: "/monitors" }]} />
|
||||||
<Stack
|
<Stack
|
||||||
@@ -59,8 +55,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
mt={theme.spacing(5)}
|
mt={theme.spacing(5)}
|
||||||
>
|
>
|
||||||
<Greeting type="uptime" />
|
<Greeting type="uptime" />
|
||||||
{isAdmin &&
|
{canCreateMonitor && (
|
||||||
monitorState?.monitorsSummary?.monitors?.length !== 0 && (
|
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
@@ -74,6 +69,10 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
{loading ? (
|
||||||
|
<SkeletonLayout />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
{isAdmin && monitorState?.monitorsSummary?.monitors?.length === 0 && (
|
{isAdmin && monitorState?.monitorsSummary?.monitors?.length === 0 && (
|
||||||
<Fallback isAdmin={isAdmin} />
|
<Fallback isAdmin={isAdmin} />
|
||||||
)}
|
)}
|
||||||
@@ -91,15 +90,11 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
/>
|
/>
|
||||||
<StatusBox
|
<StatusBox
|
||||||
title="down"
|
title="down"
|
||||||
value={
|
value={monitorState?.monitorsSummary?.monitorCounts?.down ?? 0}
|
||||||
monitorState?.monitorsSummary?.monitorCounts?.down ?? 0
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<StatusBox
|
<StatusBox
|
||||||
title="paused"
|
title="paused"
|
||||||
value={
|
value={monitorState?.monitorsSummary?.monitorCounts?.paused ?? 0}
|
||||||
monitorState?.monitorsSummary?.monitorCounts?.paused ?? 0
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box
|
<Box
|
||||||
@@ -133,7 +128,11 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
>
|
>
|
||||||
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
||||||
</Box>
|
</Box>
|
||||||
<Box width="25%" minWidth={150} ml="auto">
|
<Box
|
||||||
|
width="25%"
|
||||||
|
minWidth={150}
|
||||||
|
ml="auto"
|
||||||
|
>
|
||||||
<Search
|
<Search
|
||||||
options={monitorState?.monitorsSummary?.monitors ?? []}
|
options={monitorState?.monitorsSummary?.monitors ?? []}
|
||||||
filteredBy="name"
|
filteredBy="name"
|
||||||
|
|||||||
Reference in new issue
Block a user