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
+76 -13

No files matched your search

+16 -2
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 {
@@ -41,3 +43,15 @@
.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);
}
+60 -11
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,6 +111,7 @@ const Configure = () => {
}, },
}} }}
/> />
<form className="configure-monitor-form" noValidate spellCheck="false">
<Stack gap={theme.gap.xl}> <Stack gap={theme.gap.xl}>
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}> <Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
{monitor?.status ? <GreenCheck /> : <RedCheck />} {monitor?.status ? <GreenCheck /> : <RedCheck />}
@@ -162,8 +175,8 @@ const Configure = () => {
<Box> <Box>
<Typography component="h2">General settings</Typography> <Typography component="h2">General settings</Typography>
<Typography component="p" sx={{ mt: theme.gap.small }}> <Typography component="p" sx={{ mt: theme.gap.small }}>
Here you can select the URL of the host, together with the type of Here you can select the URL of the host, together with the type
monitor. of monitor.
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.gap.xl}> <Stack gap={theme.gap.xl}>
@@ -172,6 +185,7 @@ const Configure = () => {
id="monitor-url" id="monitor-url"
label="URL to monitor" label="URL to monitor"
placeholder="google.com" placeholder="google.com"
value={monitor?.url}
/> />
<Field <Field
type="text" type="text"
@@ -179,6 +193,7 @@ const Configure = () => {
label="Friendly name" label="Friendly name"
isOptional={true} isOptional={true}
placeholder="Google" placeholder="Google"
value={monitor?.name}
/> />
</Stack> </Stack>
</Stack> </Stack>
@@ -201,6 +216,7 @@ const Configure = () => {
desc="Use HTTP(s) to monitor your website or API endpoint." desc="Use HTTP(s) to monitor your website or API endpoint."
size="small" size="small"
value="http" value="http"
checked={monitor?.type === "http"}
/> />
<RadioButton <RadioButton
id="monitor-checks-ping" id="monitor-checks-ping"
@@ -208,8 +224,9 @@ const Configure = () => {
desc="Check whether your server is available or not." desc="Check whether your server is available or not."
size="small" size="small"
value="ping" value="ping"
checked={monitor?.type === "ping"}
/> />
{/* <Box className="error-container"> <Box className="error-container">
{errors["type"] ? ( {errors["type"] ? (
<Typography component="p" className="input-error"> <Typography component="p" className="input-error">
{errors["type"]} {errors["type"]}
@@ -217,7 +234,7 @@ const Configure = () => {
) : ( ) : (
"" ""
)} )}
</Box> */} </Box>
</Stack> </Stack>
</Stack> </Stack>
<Stack <Stack
@@ -229,9 +246,41 @@ const Configure = () => {
<Box> <Box>
<Typography component="h2">Advanced settings</Typography> <Typography component="h2">Advanced settings</Typography>
</Box> </Box>
<Stack gap={theme.gap.xl}></Stack> <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 direction="row" justifyContent="flex-end" mt={theme.gap.xl}>
<Button level="primary" label="Save" sx={{ px: theme.gap.ml }} />
</Stack>
</form>
</div> </div>
); );
}; };