[Format]: npm format on client folder
This commit is contained in:
1 parent
b45df68ece
commit
cf591a5a0b
1 file changed
+443
-422
@@ -13,7 +13,6 @@ import Dialog from "../../../Components/Dialog";
|
|||||||
import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
||||||
import Radio from "../../../Components/Inputs/Radio";
|
import Radio from "../../../Components/Inputs/Radio";
|
||||||
|
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
@@ -27,463 +26,485 @@ import { createToast } from "../../../Utils/toastUtils";
|
|||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
|
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
|
||||||
import {
|
import {
|
||||||
useCreateMonitor,
|
useCreateMonitor,
|
||||||
useFetchMonitorById,
|
useFetchMonitorById,
|
||||||
useDeleteMonitor,
|
useDeleteMonitor,
|
||||||
useUpdateMonitor,
|
useUpdateMonitor,
|
||||||
usePauseMonitor,
|
usePauseMonitor,
|
||||||
} from "../../../Hooks/monitorHooks";
|
} from "../../../Hooks/monitorHooks";
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const FREQUENCIES = [
|
const FREQUENCIES = [
|
||||||
{ _id: 3, name: "3 minutes" },
|
{ _id: 3, name: "3 minutes" },
|
||||||
{ _id: 5, name: "5 minutes" },
|
{ _id: 5, name: "5 minutes" },
|
||||||
{ _id: 10, name: "10 minutes" },
|
{ _id: 10, name: "10 minutes" },
|
||||||
{ _id: 20, name: "20 minutes" },
|
{ _id: 20, name: "20 minutes" },
|
||||||
{ _id: 60, name: "1 hour" },
|
{ _id: 60, name: "1 hour" },
|
||||||
{ _id: 1440, name: "1 day" },
|
{ _id: 1440, name: "1 day" },
|
||||||
{ _id: 10080, name: "1 week" },
|
{ _id: 10080, name: "1 week" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const PageSpeedSetup = ({ configure }) => {
|
const PageSpeedSetup = ({ configure }) => {
|
||||||
const isConfigure = configure;
|
const isConfigure = configure;
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
const CRUMBS = [
|
const CRUMBS = [
|
||||||
{ name: "pagespeed", path: "/pagespeed" },
|
{ name: "pagespeed", path: "/pagespeed" },
|
||||||
...(isConfigure
|
...(isConfigure
|
||||||
? [
|
? [
|
||||||
{ name: "details", path: `/pagespeed/${monitorId}` },
|
{ name: "details", path: `/pagespeed/${monitorId}` },
|
||||||
{ name: "configure", path: `/pagespeed/setup/${monitorId}` },
|
{ name: "configure", path: `/pagespeed/setup/${monitorId}` },
|
||||||
]
|
]
|
||||||
: [{ name: "create", path: `/pagespeed/create` }]),
|
: [{ name: "create", path: `/pagespeed/create` }]),
|
||||||
];
|
];
|
||||||
|
|
||||||
// States
|
// States
|
||||||
const [monitor, setMonitor] = useState(isConfigure ? {} : {
|
const [monitor, setMonitor] = useState(
|
||||||
url: "",
|
isConfigure
|
||||||
name: "",
|
? {}
|
||||||
type: "pagespeed",
|
: {
|
||||||
notifications: [],
|
url: "",
|
||||||
interval: 180000,
|
name: "",
|
||||||
});
|
type: "pagespeed",
|
||||||
const [https, setHttps] = useState(true);
|
notifications: [],
|
||||||
const [errors, setErrors] = useState({});
|
interval: 180000,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const [https, setHttps] = useState(true);
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
const [isDeleting, setIsDeleting] = useState(false);
|
const [isDeleting, setIsDeleting] = useState(false);
|
||||||
const [isUpdating, setIsUpdating] = useState(false);
|
const [isUpdating, setIsUpdating] = useState(false);
|
||||||
const [isPausing, setIsPausing] = useState(false);
|
const [isPausing, setIsPausing] = useState(false);
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const { user } = useSelector((state) => state.auth);
|
const { user } = useSelector((state) => state.auth);
|
||||||
const {
|
const { statusColor, pagespeedStatusMsg, determineState } = useMonitorUtils();
|
||||||
statusColor,
|
const [notifications, notificationsAreLoading, notificationsError] =
|
||||||
pagespeedStatusMsg,
|
useGetNotificationsByTeamId();
|
||||||
determineState
|
|
||||||
} = useMonitorUtils();
|
|
||||||
const [
|
|
||||||
notifications,
|
|
||||||
notificationsAreLoading,
|
|
||||||
notificationsError
|
|
||||||
] = useGetNotificationsByTeamId();
|
|
||||||
|
|
||||||
// Hooks for API actions
|
// Hooks for API actions
|
||||||
const [createMonitor, isCreating] = useCreateMonitor();
|
const [createMonitor, isCreating] = useCreateMonitor();
|
||||||
const [isLoading] = isConfigure
|
const [isLoading] = isConfigure
|
||||||
? useFetchMonitorById({ monitorId, setMonitor, updateTrigger })
|
? useFetchMonitorById({ monitorId, setMonitor, updateTrigger })
|
||||||
: [false];
|
: [false];
|
||||||
const [deleteMonitor] = useDeleteMonitor();
|
const [deleteMonitor] = useDeleteMonitor();
|
||||||
const [updateMonitor] = useUpdateMonitor();
|
const [updateMonitor] = useUpdateMonitor();
|
||||||
const [pauseMonitor] = usePauseMonitor();
|
const [pauseMonitor] = usePauseMonitor();
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
const onSubmit = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (isConfigure) {
|
||||||
|
await updateMonitor({ monitor, redirect: "/pagespeed" });
|
||||||
|
} else {
|
||||||
|
let form = {
|
||||||
|
url: `http${https ? "s" : ""}://` + monitor.url,
|
||||||
|
name: monitor.name === "" ? monitor.url : monitor.name,
|
||||||
|
type: monitor.type,
|
||||||
|
interval: monitor.interval,
|
||||||
|
};
|
||||||
|
|
||||||
// Handlers
|
const { error } = monitorValidation.validate(form, { abortEarly: false });
|
||||||
const onSubmit = async (event) => {
|
if (error) {
|
||||||
event.preventDefault();
|
const newErrors = {};
|
||||||
if (isConfigure) {
|
error.details.forEach((err) => {
|
||||||
await updateMonitor({ monitor, redirect: "/pagespeed" });
|
newErrors[err.path[0]] = err.message;
|
||||||
} else {
|
});
|
||||||
let form = {
|
setErrors(newErrors);
|
||||||
url: `http${https ? "s" : ""}://` + monitor.url,
|
createToast({ body: "Please check the form for errors." });
|
||||||
name: monitor.name === "" ? monitor.url : monitor.name,
|
return;
|
||||||
type: monitor.type,
|
}
|
||||||
interval: monitor.interval,
|
|
||||||
};
|
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(form, { abortEarly: false });
|
form = {
|
||||||
if (error) {
|
...form,
|
||||||
const newErrors = {};
|
description: form.name,
|
||||||
error.details.forEach((err) => {
|
notifications: monitor.notifications,
|
||||||
newErrors[err.path[0]] = err.message;
|
};
|
||||||
});
|
await createMonitor({ monitor: form, redirect: "/pagespeed" });
|
||||||
setErrors(newErrors);
|
}
|
||||||
createToast({ body: "Please check the form for errors." });
|
};
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
form = {
|
const handleChange = (event) => {
|
||||||
...form,
|
let { value, name } = event.target;
|
||||||
description: form.name,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
};
|
|
||||||
await createMonitor({ monitor: form, redirect: "/pagespeed" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
if (name === "interval") {
|
||||||
let { value, name } = event.target;
|
|
||||||
|
|
||||||
if (name === "interval") {
|
|
||||||
value = value * MS_PER_MINUTE;
|
value = value * MS_PER_MINUTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMonitor({
|
setMonitor({
|
||||||
...monitor,
|
...monitor,
|
||||||
[name]: value
|
[name]: value,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(
|
const { error } = monitorValidation.validate(
|
||||||
{ [name]: value },
|
{ [name]: value },
|
||||||
{ abortEarly: false }
|
{ abortEarly: false }
|
||||||
);
|
);
|
||||||
setErrors((prev) => ({
|
setErrors((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
...(error ? { [name]: error.details[0].message } : { [name]: undefined})
|
...(error ? { [name]: error.details[0].message } : { [name]: undefined }),
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBlur = (event) => {
|
const handleBlur = (event) => {
|
||||||
const { name, value } = event.target;
|
const { name, value } = event.target;
|
||||||
if (name === "url" && monitor.name === "") {
|
if (name === "url" && monitor.name === "") {
|
||||||
setMonitor((prev) => ({ ...prev, name: parseDomainName(value) }));
|
setMonitor((prev) => ({ ...prev, name: parseDomainName(value) }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggerUpdate = () => {
|
const triggerUpdate = () => {
|
||||||
setUpdateTrigger(!updateTrigger);
|
setUpdateTrigger(!updateTrigger);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handlePause = async () => {
|
const handlePause = async () => {
|
||||||
await pauseMonitor({ monitorId, triggerUpdate });
|
await pauseMonitor({ monitorId, triggerUpdate });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
await deleteMonitor({ monitor, redirect: "/pagespeed" });
|
await deleteMonitor({ monitor, redirect: "/pagespeed" });
|
||||||
};
|
};
|
||||||
|
|
||||||
// // Loading skeleton
|
return (
|
||||||
// if (isConfigure && (isLoading || !monitor._id)) {
|
<Box
|
||||||
// return <SkeletonLayout />;
|
className={isConfigure ? "configure-pagespeed" : "create-monitor"}
|
||||||
// }
|
sx={{
|
||||||
|
"& h1": { color: theme.palette.primary.contrastText },
|
||||||
return (
|
}}
|
||||||
<Box
|
>
|
||||||
className={isConfigure ? "configure-pagespeed" : "create-monitor"}
|
{Object.keys(monitor).length === 0 ? (
|
||||||
// gap={theme.spacing(10)}
|
<SkeletonLayout />
|
||||||
sx={{
|
) : (
|
||||||
"& h1": { color: theme.palette.primary.contrastText },
|
<>
|
||||||
}}
|
<Breadcrumbs list={CRUMBS} />
|
||||||
>
|
<Stack
|
||||||
{Object.keys(monitor).length === 0 ? (
|
component="form"
|
||||||
<SkeletonLayout />
|
className={isConfigure ? "" : "create-monitor-form"}
|
||||||
) : (
|
onSubmit={onSubmit}
|
||||||
<>
|
noValidate
|
||||||
<Breadcrumbs
|
spellCheck="false"
|
||||||
list={ CRUMBS }
|
gap={theme.spacing(12)}
|
||||||
/>
|
mt={theme.spacing(6)}
|
||||||
<Stack
|
>
|
||||||
component="form"
|
<Stack
|
||||||
className={isConfigure ? "" : "create-monitor-form"}
|
direction="row"
|
||||||
onSubmit={onSubmit}
|
gap={theme.spacing(2)}
|
||||||
noValidate
|
>
|
||||||
spellCheck="false"
|
<Box>
|
||||||
gap={theme.spacing(12)}
|
<Typography
|
||||||
mt={theme.spacing(6)}
|
component="h1"
|
||||||
>
|
variant="h1"
|
||||||
<Stack direction="row" gap={theme.spacing(2)}>
|
>
|
||||||
<Box>
|
<Typography
|
||||||
<Typography component="h1" variant="h1">
|
component="span"
|
||||||
<Typography
|
fontSize="inherit"
|
||||||
component="span"
|
color={
|
||||||
fontSize="inherit"
|
isConfigure
|
||||||
color={isConfigure ? theme.palette.primary.contrastTextSecondary : undefined}
|
? theme.palette.primary.contrastTextSecondary
|
||||||
>
|
: undefined
|
||||||
{isConfigure ? monitor.name : t("createYour") + " "}
|
}
|
||||||
</Typography>
|
>
|
||||||
{ !isConfigure
|
{isConfigure ? monitor.name : t("createYour") + " "}
|
||||||
? (
|
</Typography>
|
||||||
<Typography
|
{!isConfigure ? (
|
||||||
component="span"
|
<Typography
|
||||||
fontSize="inherit"
|
component="span"
|
||||||
fontWeight="inherit"
|
fontSize="inherit"
|
||||||
color={theme.palette.primary.contrastTextSecondary}
|
fontWeight="inherit"
|
||||||
>
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
{t("pageSpeedMonitor")}
|
>
|
||||||
</Typography>
|
{t("pageSpeedMonitor")}
|
||||||
)
|
</Typography>
|
||||||
: <></>
|
) : (
|
||||||
}
|
<></>
|
||||||
</Typography>
|
)}
|
||||||
{isConfigure && (
|
</Typography>
|
||||||
<Stack direction="row" alignItems="center" height="fit-content" gap={theme.spacing(2)}>
|
{isConfigure && (
|
||||||
<Tooltip
|
<Stack
|
||||||
title={pagespeedStatusMsg[determineState(monitor)]}
|
direction="row"
|
||||||
disableInteractive
|
alignItems="center"
|
||||||
slotProps={{
|
height="fit-content"
|
||||||
popper: {
|
gap={theme.spacing(2)}
|
||||||
modifiers: [
|
>
|
||||||
{
|
<Tooltip
|
||||||
name: "offset",
|
title={pagespeedStatusMsg[determineState(monitor)]}
|
||||||
options: { offset: [0, -8] },
|
disableInteractive
|
||||||
},
|
slotProps={{
|
||||||
],
|
popper: {
|
||||||
},
|
modifiers: [
|
||||||
}}
|
{
|
||||||
>
|
name: "offset",
|
||||||
<Box>
|
options: { offset: [0, -8] },
|
||||||
<PulseDot color={statusColor[determineState(monitor)]} />
|
},
|
||||||
</Box>
|
],
|
||||||
</Tooltip>
|
},
|
||||||
<Typography component="h2" variant="monitorUrl">
|
}}
|
||||||
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
>
|
||||||
</Typography>
|
<Box>
|
||||||
<Typography
|
<PulseDot color={statusColor[determineState(monitor)]} />
|
||||||
position="relative"
|
</Box>
|
||||||
variant="body2"
|
</Tooltip>
|
||||||
ml={theme.spacing(6)}
|
<Typography
|
||||||
mt={theme.spacing(1)}
|
component="h2"
|
||||||
sx={{
|
variant="monitorUrl"
|
||||||
"&:before": {
|
>
|
||||||
position: "absolute",
|
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
||||||
content: `""`,
|
</Typography>
|
||||||
width: 4,
|
<Typography
|
||||||
height: 4,
|
position="relative"
|
||||||
borderRadius: "50%",
|
variant="body2"
|
||||||
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
ml={theme.spacing(6)}
|
||||||
opacity: 0.8,
|
mt={theme.spacing(1)}
|
||||||
left: -10,
|
sx={{
|
||||||
top: "50%",
|
"&:before": {
|
||||||
transform: "translateY(-50%)",
|
position: "absolute",
|
||||||
},
|
content: `""`,
|
||||||
}}
|
width: 4,
|
||||||
>
|
height: 4,
|
||||||
{t("editing")}
|
borderRadius: "50%",
|
||||||
</Typography>
|
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
||||||
</Stack>
|
opacity: 0.8,
|
||||||
)}
|
left: -10,
|
||||||
</Box>
|
top: "50%",
|
||||||
{isConfigure && (
|
transform: "translateY(-50%)",
|
||||||
<Box alignSelf="flex-end" ml="auto">
|
},
|
||||||
<Button
|
}}
|
||||||
onClick={handlePause}
|
>
|
||||||
loading={isLoading}
|
{t("editing")}
|
||||||
variant="contained"
|
</Typography>
|
||||||
color="secondary"
|
</Stack>
|
||||||
sx={{
|
)}
|
||||||
pl: theme.spacing(4),
|
</Box>
|
||||||
pr: theme.spacing(6),
|
{isConfigure && (
|
||||||
"& svg": {
|
<Box
|
||||||
mr: theme.spacing(2),
|
alignSelf="flex-end"
|
||||||
"& path": {
|
ml="auto"
|
||||||
stroke: theme.palette.primary.contrastTextTertiary,
|
>
|
||||||
strokeWidth: 0.1,
|
<Button
|
||||||
},
|
onClick={handlePause}
|
||||||
},
|
loading={isLoading}
|
||||||
}}
|
variant="contained"
|
||||||
>
|
color="secondary"
|
||||||
{monitor?.isActive ? (
|
sx={{
|
||||||
<>
|
pl: theme.spacing(4),
|
||||||
<PauseCircleOutlineIcon />
|
pr: theme.spacing(6),
|
||||||
{t("pause")}
|
"& svg": {
|
||||||
</>
|
mr: theme.spacing(2),
|
||||||
) : (
|
"& path": {
|
||||||
<>
|
stroke: theme.palette.primary.contrastTextTertiary,
|
||||||
<PlayCircleOutlineRoundedIcon />
|
strokeWidth: 0.1,
|
||||||
{t("resume")}
|
},
|
||||||
</>
|
},
|
||||||
)}
|
}}
|
||||||
</Button>
|
>
|
||||||
<Button
|
{monitor?.isActive ? (
|
||||||
loading={isLoading}
|
<>
|
||||||
variant="contained"
|
<PauseCircleOutlineIcon />
|
||||||
color="error"
|
{t("pause")}
|
||||||
onClick={() => setIsOpen(true)}
|
</>
|
||||||
sx={{ ml: theme.spacing(6) }}
|
) : (
|
||||||
>
|
<>
|
||||||
{t("remove")}
|
<PlayCircleOutlineRoundedIcon />
|
||||||
</Button>
|
{t("resume")}
|
||||||
</Box>
|
</>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Button>
|
||||||
<ConfigBox>
|
<Button
|
||||||
<Box>
|
loading={isLoading}
|
||||||
<Typography component="h2" variant="h2">
|
variant="contained"
|
||||||
{t("settingsGeneralSettings")}
|
color="error"
|
||||||
</Typography>
|
onClick={() => setIsOpen(true)}
|
||||||
<Typography component="p">
|
sx={{ ml: theme.spacing(6) }}
|
||||||
{t("pageSpeedConfigureSettingsDescription")}
|
>
|
||||||
</Typography>
|
{t("remove")}
|
||||||
</Box>
|
</Button>
|
||||||
<Stack
|
</Box>
|
||||||
gap={isConfigure ? theme.spacing(20) : theme.spacing(15)}
|
)}
|
||||||
|
</Stack>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
>
|
||||||
|
{t("settingsGeneralSettings")}
|
||||||
|
</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
{t("pageSpeedConfigureSettingsDescription")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
gap={isConfigure ? theme.spacing(20) : theme.spacing(15)}
|
||||||
sx={{
|
sx={{
|
||||||
".MuiInputBase-root:has(> .Mui-disabled)": {
|
".MuiInputBase-root:has(> .Mui-disabled)": {
|
||||||
backgroundColor: theme.palette.tertiary.main,
|
backgroundColor: theme.palette.tertiary.main,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
type={"url"}
|
type={"url"}
|
||||||
name="url"
|
name="url"
|
||||||
id="monitor-url"
|
id="monitor-url"
|
||||||
label={isConfigure ? t("url") : "URL to monitor"}
|
label={isConfigure ? t("url") : "URL to monitor"}
|
||||||
startAdornment={!isConfigure ? <HttpAdornment https={https} /> : undefined}
|
startAdornment={
|
||||||
placeholder="random.website.com"
|
!isConfigure ? <HttpAdornment https={https} /> : undefined
|
||||||
value={monitor.url || ""}
|
}
|
||||||
onChange={handleChange}
|
placeholder="random.website.com"
|
||||||
onBlur={!isConfigure ? handleBlur : undefined}
|
value={monitor.url || ""}
|
||||||
error={!!errors["url"]}
|
onChange={handleChange}
|
||||||
helperText={errors["url"]}
|
onBlur={!isConfigure ? handleBlur : undefined}
|
||||||
disabled={isConfigure}
|
error={!!errors["url"]}
|
||||||
/>
|
helperText={errors["url"]}
|
||||||
<TextInput
|
disabled={isConfigure}
|
||||||
type="text"
|
/>
|
||||||
id="monitor-name"
|
<TextInput
|
||||||
name="name"
|
type="text"
|
||||||
label={t("monitorDisplayName")}
|
id="monitor-name"
|
||||||
isOptional={true}
|
name="name"
|
||||||
placeholder="Google"
|
label={t("monitorDisplayName")}
|
||||||
value={monitor.name || ""}
|
isOptional={true}
|
||||||
onChange={handleChange}
|
placeholder="Google"
|
||||||
error={!!errors["name"]}
|
value={monitor.name || ""}
|
||||||
helperText={errors["name"]}
|
onChange={handleChange}
|
||||||
/>
|
error={!!errors["name"]}
|
||||||
</Stack>
|
helperText={errors["name"]}
|
||||||
</ConfigBox>
|
/>
|
||||||
{!isConfigure && (
|
</Stack>
|
||||||
<ConfigBox>
|
</ConfigBox>
|
||||||
<Box>
|
{!isConfigure && (
|
||||||
<Typography component="h2" variant="h2">
|
<ConfigBox>
|
||||||
{t("distributedUptimeCreateChecks")}
|
<Box>
|
||||||
</Typography>
|
<Typography
|
||||||
<Typography component="p">
|
component="h2"
|
||||||
{t("distributedUptimeCreateChecksDescription")}
|
variant="h2"
|
||||||
</Typography>
|
>
|
||||||
</Box>
|
{t("distributedUptimeCreateChecks")}
|
||||||
<Stack gap={theme.spacing(12)}>
|
</Typography>
|
||||||
<Stack gap={theme.spacing(6)}>
|
<Typography component="p">
|
||||||
<Radio
|
{t("distributedUptimeCreateChecksDescription")}
|
||||||
id="monitor-checks-http"
|
</Typography>
|
||||||
title="PageSpeed"
|
</Box>
|
||||||
desc="Use the Lighthouse PageSpeed API to monitor your website"
|
<Stack gap={theme.spacing(12)}>
|
||||||
size="small"
|
<Stack gap={theme.spacing(6)}>
|
||||||
value="http"
|
<Radio
|
||||||
checked={monitor.type === "pagespeed"}
|
id="monitor-checks-http"
|
||||||
/>
|
title="PageSpeed"
|
||||||
<ButtonGroup sx={{ ml: "32px" }}>
|
desc="Use the Lighthouse PageSpeed API to monitor your website"
|
||||||
<Button
|
size="small"
|
||||||
variant="group"
|
value="http"
|
||||||
filled={https.toString()}
|
checked={monitor.type === "pagespeed"}
|
||||||
onClick={() => setHttps(true)}
|
/>
|
||||||
>
|
<ButtonGroup sx={{ ml: "32px" }}>
|
||||||
{t("https")}
|
<Button
|
||||||
</Button>
|
variant="group"
|
||||||
<Button
|
filled={https.toString()}
|
||||||
variant="group" // Why does this work?
|
onClick={() => setHttps(true)}
|
||||||
filled={(!https).toString()} // There's nothing in the docs about this either
|
>
|
||||||
onClick={() => setHttps(false)}
|
{t("https")}
|
||||||
>
|
</Button>
|
||||||
{t("http")}
|
<Button
|
||||||
</Button>
|
variant="group" // Why does this work?
|
||||||
</ButtonGroup>
|
filled={(!https).toString()} // There's nothing in the docs about this either
|
||||||
</Stack>
|
onClick={() => setHttps(false)}
|
||||||
{errors["type"] ? (
|
>
|
||||||
<Box className="error-container">
|
{t("http")}
|
||||||
<Typography
|
</Button>
|
||||||
component="p"
|
</ButtonGroup>
|
||||||
className="input-error"
|
</Stack>
|
||||||
color={theme.palette.error.contrastText}
|
{errors["type"] ? (
|
||||||
>
|
<Box className="error-container">
|
||||||
{errors["type"]}
|
<Typography
|
||||||
</Typography>
|
component="p"
|
||||||
</Box>
|
className="input-error"
|
||||||
) : ""}
|
color={theme.palette.error.contrastText}
|
||||||
</Stack>
|
>
|
||||||
</ConfigBox>
|
{errors["type"]}
|
||||||
)}
|
</Typography>
|
||||||
<ConfigBox>
|
</Box>
|
||||||
<Box>
|
) : (
|
||||||
<Typography component="h2" variant="h2">
|
""
|
||||||
{t("notificationConfig.title")}
|
)}
|
||||||
</Typography>
|
</Stack>
|
||||||
<Typography component="p">{t("notificationConfig.description")}</Typography>
|
</ConfigBox>
|
||||||
</Box>
|
)}
|
||||||
<NotificationsConfig
|
<ConfigBox>
|
||||||
notifications={notifications}
|
<Box>
|
||||||
setMonitor={setMonitor}
|
<Typography
|
||||||
setNotifications={isConfigure ? monitor.notifications : undefined}
|
component="h2"
|
||||||
/>
|
variant="h2"
|
||||||
</ConfigBox>
|
>
|
||||||
<ConfigBox>
|
{t("notificationConfig.title")}
|
||||||
<Box>
|
</Typography>
|
||||||
<Typography
|
<Typography component="p">
|
||||||
component="h2"
|
{t("notificationConfig.description")}
|
||||||
variant="h2"
|
</Typography>
|
||||||
>
|
</Box>
|
||||||
{t("distributedUptimeCreateAdvancedSettings")}
|
<NotificationsConfig
|
||||||
</Typography>
|
notifications={notifications}
|
||||||
</Box>
|
setMonitor={setMonitor}
|
||||||
<Stack gap={theme.spacing(isConfigure ? 20 : 12)}>
|
setNotifications={isConfigure ? monitor.notifications : undefined}
|
||||||
<Select
|
/>
|
||||||
id="monitor-interval"
|
</ConfigBox>
|
||||||
name="interval"
|
<ConfigBox>
|
||||||
label={t("checkFrequency")}
|
<Box>
|
||||||
value={monitor?.interval / MS_PER_MINUTE || 3}
|
<Typography
|
||||||
onChange={handleChange}
|
component="h2"
|
||||||
items={FREQUENCIES}
|
variant="h2"
|
||||||
/>
|
>
|
||||||
</Stack>
|
{t("distributedUptimeCreateAdvancedSettings")}
|
||||||
</ConfigBox>
|
</Typography>
|
||||||
<Stack
|
</Box>
|
||||||
direction="row"
|
<Stack gap={theme.spacing(isConfigure ? 20 : 12)}>
|
||||||
justifyContent="flex-end"
|
<Select
|
||||||
mt={isConfigure ? "auto" : undefined}
|
id="monitor-interval"
|
||||||
>
|
name="interval"
|
||||||
<Button
|
label={t("checkFrequency")}
|
||||||
type="submit"
|
value={monitor?.interval / MS_PER_MINUTE || 3}
|
||||||
variant="contained"
|
onChange={handleChange}
|
||||||
color="accent"
|
items={FREQUENCIES}
|
||||||
disabled={!Object.values(errors).every((value) => value === undefined)}
|
/>
|
||||||
loading={isLoading || isDeleting || isUpdating || isPausing || isCreating}
|
</Stack>
|
||||||
sx={isConfigure ? { px: theme.spacing(12) } : undefined}
|
</ConfigBox>
|
||||||
>
|
<Stack
|
||||||
{isConfigure ? t("settingsSave") : t("createMonitor")}
|
direction="row"
|
||||||
</Button>
|
justifyContent="flex-end"
|
||||||
</Stack>
|
mt={isConfigure ? "auto" : undefined}
|
||||||
</Stack>
|
>
|
||||||
</>
|
<Button
|
||||||
)}
|
type="submit"
|
||||||
{isConfigure && (
|
variant="contained"
|
||||||
<Dialog
|
color="accent"
|
||||||
open={isOpen}
|
disabled={!Object.values(errors).every((value) => value === undefined)}
|
||||||
theme={theme}
|
loading={isLoading || isDeleting || isUpdating || isPausing || isCreating}
|
||||||
title={t("deleteDialogTitle")}
|
sx={isConfigure ? { px: theme.spacing(12) } : undefined}
|
||||||
description={t("deleteDialogDescription")}
|
>
|
||||||
onCancel={() => setIsOpen(false)}
|
{isConfigure ? t("settingsSave") : t("createMonitor")}
|
||||||
confirmationButtonLabel={t("delete")}
|
</Button>
|
||||||
onConfirm={handleRemove}
|
</Stack>
|
||||||
isLoading={isLoading || isDeleting || isUpdating || isPausing}
|
</Stack>
|
||||||
/>
|
</>
|
||||||
)}
|
)}
|
||||||
</Box>
|
{isConfigure && (
|
||||||
);
|
<Dialog
|
||||||
|
open={isOpen}
|
||||||
|
theme={theme}
|
||||||
|
title={t("deleteDialogTitle")}
|
||||||
|
description={t("deleteDialogDescription")}
|
||||||
|
onCancel={() => setIsOpen(false)}
|
||||||
|
confirmationButtonLabel={t("delete")}
|
||||||
|
onConfirm={handleRemove}
|
||||||
|
isLoading={isLoading || isDeleting || isUpdating || isPausing}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PageSpeedSetup;
|
export default PageSpeedSetup;
|
||||||
|
|
||||||
Reference in new issue
Block a user