Hooked up fields to monitor state

This commit is contained in:
Daniel Cojocea committed 2024-07-19 17:48:47 -04:00
1 parent 98dad2b5ed
commit 4a14d1c8d9
2 files changed
+197 -134

No files matched your search

+17 -3
View File
@@ -8,10 +8,12 @@
font-weight: 600; font-weight: 600;
} }
.configure-monitor h2.MuiTypography-root, .configure-monitor h2.MuiTypography-root,
.configure-monitor .config-box p.MuiTypography-root { .configure-monitor .config-box p.MuiTypography-root,
.configure-monitor .MuiSelect-select {
color: var(--env-var-color-5); color: var(--env-var-color-5);
} }
.configure-monitor p.MuiTypography-root { .configure-monitor p.MuiTypography-root,
.configure-monitor .MuiSelect-select {
font-size: var(--env-var-font-size-medium); font-size: var(--env-var-font-size-medium);
} }
.configure-monitor h6.MuiTypography-root { .configure-monitor h6.MuiTypography-root {
@@ -40,4 +42,16 @@
.configure-monitor .config-box .MuiBox-root, .configure-monitor .config-box .MuiBox-root,
.configure-monitor .config-box .MuiStack-root { .configure-monitor .config-box .MuiStack-root {
flex: 1; flex: 1;
} }
.MuiInputBase-root:has(#monitor-interval) {
height: 34px;
}
#monitor-interval {
padding: 0 10px;
height: 100%;
display: flex;
align-items: center;
}
.MuiInputBase-root:not(.Mui-focused):has(#monitor-interval):hover fieldset {
border-color: var(--env-var-color-29);
}
+180 -131
View File
@@ -4,15 +4,16 @@ import { useDispatch, useSelector } from "react-redux";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import axiosInstance from "../../../Utils/axiosConfig"; import axiosInstance from "../../../Utils/axiosConfig";
import Button from "../../../Components/Button"; import Button from "../../../Components/Button";
import { Box, Stack, Typography } from "@mui/material"; import Field from "../../../Components/Inputs/Field";
import RadioButton from "../../../Components/RadioButton";
import { Box, MenuItem, Select, Stack, Typography } from "@mui/material";
import WestRoundedIcon from "@mui/icons-material/WestRounded"; import WestRoundedIcon from "@mui/icons-material/WestRounded";
import GreenCheck from "../../../assets/icons/checkbox-green.svg?react"; import GreenCheck from "../../../assets/icons/checkbox-green.svg?react";
import RedCheck from "../../../assets/icons/checkbox-red.svg?react"; import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline"; import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import "./index.css"; import "./index.css";
import Field from "../../../Components/Inputs/Field";
import RadioButton from "../../../Components/RadioButton";
const formatDurationRounded = (ms) => { const formatDurationRounded = (ms) => {
const seconds = Math.floor(ms / 1000); const seconds = Math.floor(ms / 1000);
@@ -58,13 +59,15 @@ const getLastChecked = (checks) => {
* @component * @component
*/ */
const Configure = () => { const Configure = () => {
const MS_PER_MINUTE = 60000;
const navigate = useNavigate(); const navigate = useNavigate();
const theme = useTheme(); const theme = useTheme();
const dispatch = useDispatch(); const dispatch = useDispatch();
const { authToken } = useSelector((state) => state.auth);
const { monitorId } = useParams();
const [monitor, setMonitor] = useState(); const [monitor, setMonitor] = useState();
const { monitorId } = useParams(); const [errors, setErrors] = useState({});
const { authToken } = useSelector((state) => state.auth);
useEffect(() => { useEffect(() => {
const fetchMonitor = async () => { const fetchMonitor = async () => {
const res = await axiosInstance.get(`/monitors/${monitorId}`, { const res = await axiosInstance.get(`/monitors/${monitorId}`, {
@@ -72,11 +75,20 @@ const Configure = () => {
Authorization: `Bearer ${authToken}`, Authorization: `Bearer ${authToken}`,
}, },
}); });
setMonitor(res.data.data); let data = res.data.data;
setMonitor({
name: data.name,
url: data.url.replace(/^https?:\/\//, ""),
type: data.type,
interval: data.interval / MS_PER_MINUTE,
status: data.status,
});
}; };
fetchMonitor(); fetchMonitor();
}, [monitorId, authToken]); }, [monitorId, authToken]);
const frequencies = [1, 2, 3, 4, 5];
return ( return (
<div <div
className="configure-monitor" className="configure-monitor"
@@ -99,139 +111,176 @@ const Configure = () => {
}, },
}} }}
/> />
<Stack gap={theme.gap.xl}> <form className="configure-monitor-form" noValidate spellCheck="false">
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}> <Stack gap={theme.gap.xl}>
{monitor?.status ? <GreenCheck /> : <RedCheck />} <Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
<Box> {monitor?.status ? <GreenCheck /> : <RedCheck />}
<Typography component="h1" sx={{ lineHeight: 1 }}> <Box>
{monitor?.url.replace(/^https?:\/\//, "") || "..."} <Typography component="h1" sx={{ lineHeight: 1 }}>
</Typography> {monitor?.url.replace(/^https?:\/\//, "") || "..."}
<Typography mt={theme.gap.small}> </Typography>
<Typography <Typography mt={theme.gap.small}>
component="span" <Typography
component="span"
sx={{
color: monitor?.status
? "var(--env-var-color-17)"
: "var(--env-var-color-24)",
}}
>
Your site is {monitor?.status ? "up" : "down"}.
</Typography>{" "}
Checking every {formatDurationRounded(monitor?.interval)}. Last
time checked{" "}
{formatDurationRounded(getLastChecked(monitor?.checks))} ago.
</Typography>
</Box>
<Stack
direction="row"
gap={theme.gap.medium}
sx={{
ml: "auto",
alignSelf: "flex-end",
}}
>
<Button
level="tertiary"
label="Pause"
img={<PauseCircleOutlineIcon />}
sx={{ sx={{
color: monitor?.status backgroundColor: "#f4f4f4",
? "var(--env-var-color-17)" pl: theme.gap.small,
: "var(--env-var-color-24)", pr: theme.gap.medium,
"& svg": {
pr: theme.gap.xs,
},
}} }}
> />
Your site is {monitor?.status ? "up" : "down"}. <Button
</Typography>{" "} level="error"
Checking every {formatDurationRounded(monitor?.interval)}. Last label="Remove"
time checked{" "} sx={{
{formatDurationRounded(getLastChecked(monitor?.checks))} ago. boxShadow: "none",
</Typography> px: theme.gap.ml,
</Box> }}
/>
</Stack>
</Stack>
<Stack <Stack
className="config-box"
direction="row" direction="row"
gap={theme.gap.medium} justifyContent="space-between"
sx={{ gap={theme.gap.xxl}
ml: "auto",
alignSelf: "flex-end",
}}
> >
<Button <Box>
level="tertiary" <Typography component="h2">General settings</Typography>
label="Pause" <Typography component="p" sx={{ mt: theme.gap.small }}>
img={<PauseCircleOutlineIcon />} Here you can select the URL of the host, together with the type
sx={{ of monitor.
backgroundColor: "#f4f4f4", </Typography>
pl: theme.gap.small, </Box>
pr: theme.gap.medium, <Stack gap={theme.gap.xl}>
"& svg": { <Field
pr: theme.gap.xs, type="url"
}, id="monitor-url"
}} label="URL to monitor"
/> placeholder="google.com"
<Button value={monitor?.url}
level="error" />
label="Remove" <Field
sx={{ type="text"
boxShadow: "none", id="monitor-name"
px: theme.gap.ml, label="Friendly name"
}} isOptional={true}
/> placeholder="Google"
value={monitor?.name}
/>
</Stack>
</Stack>
<Stack
className="config-box"
direction="row"
justifyContent="space-between"
gap={theme.gap.xxl}
>
<Box>
<Typography component="h2">Checks to perform</Typography>
<Typography component="p" sx={{ mt: theme.gap.small }}>
You can always add or remove checks after adding your site.
</Typography>
</Box>
<Stack gap={theme.gap.xl}>
<RadioButton
id="monitor-checks-http"
title="HTTP/website monitoring"
desc="Use HTTP(s) to monitor your website or API endpoint."
size="small"
value="http"
checked={monitor?.type === "http"}
/>
<RadioButton
id="monitor-checks-ping"
title="Ping monitoring"
desc="Check whether your server is available or not."
size="small"
value="ping"
checked={monitor?.type === "ping"}
/>
<Box className="error-container">
{errors["type"] ? (
<Typography component="p" className="input-error">
{errors["type"]}
</Typography>
) : (
""
)}
</Box>
</Stack>
</Stack>
<Stack
className="config-box"
direction="row"
justifyContent="space-between"
gap={theme.gap.xxl}
>
<Box>
<Typography component="h2">Advanced settings</Typography>
</Box>
<Stack gap={theme.gap.xl}>
<Select
id="monitor-interval"
value={monitor?.interval || 1}
MenuProps={{
PaperProps: {
style: {
marginTop: "10px",
},
},
}}
IconComponent={KeyboardArrowDownIcon}
>
{frequencies.map((freq) => (
<MenuItem
key={`port-${freq}`}
value={freq}
disableRipple
sx={{
fontSize: "13px",
borderRadius: `${theme.shape.borderRadius}px`,
margin: theme.gap.xs,
}}
>
{freq} {freq === 1 ? "minute" : "minutes"}
</MenuItem>
))}
</Select>
</Stack>
</Stack> </Stack>
</Stack> </Stack>
<Stack <Stack direction="row" justifyContent="flex-end" mt={theme.gap.xl}>
className="config-box" <Button level="primary" label="Save" sx={{ px: theme.gap.ml }} />
direction="row"
justifyContent="space-between"
gap={theme.gap.xxl}
>
<Box>
<Typography component="h2">General settings</Typography>
<Typography component="p" sx={{ mt: theme.gap.small }}>
Here you can select the URL of the host, together with the type of
monitor.
</Typography>
</Box>
<Stack gap={theme.gap.xl}>
<Field
type="url"
id="monitor-url"
label="URL to monitor"
placeholder="google.com"
/>
<Field
type="text"
id="monitor-name"
label="Friendly name"
isOptional={true}
placeholder="Google"
/>
</Stack>
</Stack> </Stack>
<Stack </form>
className="config-box"
direction="row"
justifyContent="space-between"
gap={theme.gap.xxl}
>
<Box>
<Typography component="h2">Checks to perform</Typography>
<Typography component="p" sx={{ mt: theme.gap.small }}>
You can always add or remove checks after adding your site.
</Typography>
</Box>
<Stack gap={theme.gap.xl}>
<RadioButton
id="monitor-checks-http"
title="HTTP/website monitoring"
desc="Use HTTP(s) to monitor your website or API endpoint."
size="small"
value="http"
/>
<RadioButton
id="monitor-checks-ping"
title="Ping monitoring"
desc="Check whether your server is available or not."
size="small"
value="ping"
/>
{/* <Box className="error-container">
{errors["type"] ? (
<Typography component="p" className="input-error">
{errors["type"]}
</Typography>
) : (
""
)}
</Box> */}
</Stack>
</Stack>
<Stack
className="config-box"
direction="row"
justifyContent="space-between"
gap={theme.gap.xxl}
>
<Box>
<Typography component="h2">Advanced settings</Typography>
</Box>
<Stack gap={theme.gap.xl}></Stack>
</Stack>
</Stack>
</div> </div>
); );
}; };