2024-08-03 09:40:08 +03:30
|
|
|
|
import { Box, Stack, Typography } from "@mui/material";
|
|
|
|
|
|
import "./index.css";
|
2024-08-20 10:54:28 -07:00
|
|
|
|
import { useState } from "react";
|
2024-08-03 09:40:08 +03:30
|
|
|
|
import Button from "../../../Components/Button";
|
2024-08-19 13:23:17 -04:00
|
|
|
|
import Back from "../../../assets/icons/left-arrow-long.svg?react";
|
2024-08-03 09:40:08 +03:30
|
|
|
|
import Select from "../../../Components/Inputs/Select";
|
|
|
|
|
|
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
|
|
|
|
|
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
|
|
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
|
|
|
|
|
import { MobileTimePicker } from "@mui/x-date-pickers/MobileTimePicker";
|
2024-08-05 14:17:41 +03:30
|
|
|
|
import Field from "../../../Components/Inputs/Field";
|
2024-08-21 09:40:09 +03:30
|
|
|
|
import { maintenanceWindowValidation } from "../../../Validation/validation";
|
|
|
|
|
|
import { logger } from "../../../Utils/Logger";
|
|
|
|
|
|
import { createToast } from "../../../Utils/toastUtils";
|
2024-08-03 09:40:08 +03:30
|
|
|
|
|
|
|
|
|
|
const directory = {
|
|
|
|
|
|
title: "Create a maintenance window",
|
|
|
|
|
|
description: "Your pings won’t be sent in this time frame.",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const repeatOptions = [
|
|
|
|
|
|
{ _id: 1, name: "Don't repeat" },
|
|
|
|
|
|
{ _id: 2, name: "Repeat daily" },
|
|
|
|
|
|
{ _id: 3, name: "Repeat weekly" },
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const configOptionTitle = (title, description) => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Stack width="40%" gap={1}>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
style={{
|
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
|
fontSize: "var(--env-var-font-size-medium)",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{title}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
{description && (
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
style={{
|
|
|
|
|
|
fontSize: "var(--env-var-font-size-small)",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{description}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-08 09:13:46 +03:30
|
|
|
|
const durationOptions = [
|
2024-08-07 22:46:48 +03:30
|
|
|
|
{ _id: "minutes", name: "minutes" },
|
|
|
|
|
|
{ _id: "hours", name: "hours" },
|
|
|
|
|
|
{ _id: "days", name: "days" },
|
2024-08-05 14:17:41 +03:30
|
|
|
|
];
|
|
|
|
|
|
|
2024-08-03 09:40:08 +03:30
|
|
|
|
const CreateNewMaintenanceWindow = () => {
|
|
|
|
|
|
const [values, setValues] = useState({
|
|
|
|
|
|
repeat: 1,
|
2024-08-05 14:17:41 +03:30
|
|
|
|
date: dayjs(),
|
|
|
|
|
|
startTime: dayjs(),
|
2024-08-08 09:13:46 +03:30
|
|
|
|
duration: "60",
|
2024-08-06 18:41:00 +03:30
|
|
|
|
unit: "minutes",
|
2024-08-26 17:16:29 -07:00
|
|
|
|
displayName: "",
|
2024-08-05 14:17:41 +03:30
|
|
|
|
AddMonitors: "",
|
2024-08-03 09:40:08 +03:30
|
|
|
|
});
|
2024-08-21 09:40:09 +03:30
|
|
|
|
const [errors, setErrors] = useState({});
|
2024-08-03 09:40:08 +03:30
|
|
|
|
|
|
|
|
|
|
const handleChange = (event, name) => {
|
|
|
|
|
|
const { value } = event.target;
|
|
|
|
|
|
setValues((prev) => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[name]: value,
|
|
|
|
|
|
}));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-20 20:33:28 +03:30
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
repeat: values.repeat,
|
|
|
|
|
|
date: values.date.format("YYYY-MM-DD"),
|
|
|
|
|
|
startTime: values.startTime.format("HH:mm"),
|
|
|
|
|
|
duration: values.duration,
|
|
|
|
|
|
unit: values.unit,
|
2024-08-26 17:16:29 -07:00
|
|
|
|
displayName: values.displayName,
|
2024-08-20 20:33:28 +03:30
|
|
|
|
addMonitors: values.AddMonitors,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-21 09:40:09 +03:30
|
|
|
|
const { error } = maintenanceWindowValidation.validate(data, {
|
|
|
|
|
|
abortEarly: false,
|
|
|
|
|
|
});
|
|
|
|
|
|
logger.log("error: ", error);
|
2024-08-22 10:01:18 +03:30
|
|
|
|
if (!error || error.details.length === 0) {
|
|
|
|
|
|
setErrors({});
|
|
|
|
|
|
} else {
|
2024-08-21 09:40:09 +03:30
|
|
|
|
const newErrors = {};
|
|
|
|
|
|
error.details.forEach((err) => {
|
|
|
|
|
|
newErrors[err.path[0]] = err.message;
|
|
|
|
|
|
});
|
|
|
|
|
|
setErrors(newErrors);
|
|
|
|
|
|
createToast({
|
|
|
|
|
|
body:
|
|
|
|
|
|
error.details && error.details.length > 0
|
|
|
|
|
|
? error.details[0].message
|
|
|
|
|
|
: "Error validating data",
|
2024-08-20 20:33:28 +03:30
|
|
|
|
});
|
2024-08-21 09:40:09 +03:30
|
|
|
|
logger.error("Validation errors:", error.details);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.log("Submitting data: ", data);
|
2024-08-20 20:33:28 +03:30
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-03 09:40:08 +03:30
|
|
|
|
const configOptions = [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: "Repeat",
|
|
|
|
|
|
component: (
|
|
|
|
|
|
<Select
|
|
|
|
|
|
onChange={(e) => handleChange(e, "repeat")}
|
|
|
|
|
|
id="repeat-mode"
|
|
|
|
|
|
items={repeatOptions}
|
|
|
|
|
|
value={values.repeat}
|
|
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: "Date",
|
|
|
|
|
|
component: (
|
|
|
|
|
|
<LocalizationProvider
|
|
|
|
|
|
className="date-localization-provider"
|
|
|
|
|
|
dateAdapter={AdapterDayjs}
|
|
|
|
|
|
>
|
2024-08-05 14:17:41 +03:30
|
|
|
|
<DatePicker
|
|
|
|
|
|
className="date-picker"
|
|
|
|
|
|
defaultValue={values.date}
|
|
|
|
|
|
onChange={(date) =>
|
|
|
|
|
|
handleChange({ target: { value: date } }, "date")
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
2024-08-03 09:40:08 +03:30
|
|
|
|
</LocalizationProvider>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: "Start time",
|
|
|
|
|
|
component: (
|
|
|
|
|
|
<LocalizationProvider
|
|
|
|
|
|
className="time-localization-provider"
|
|
|
|
|
|
dateAdapter={AdapterDayjs}
|
|
|
|
|
|
>
|
2024-08-05 14:17:41 +03:30
|
|
|
|
<MobileTimePicker
|
|
|
|
|
|
className="time-picker"
|
|
|
|
|
|
defaultValue={values.startTime}
|
|
|
|
|
|
onChange={(time) =>
|
|
|
|
|
|
handleChange({ target: { value: time } }, "startTime")
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
2024-08-03 09:40:08 +03:30
|
|
|
|
</LocalizationProvider>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
2024-08-05 14:17:41 +03:30
|
|
|
|
{
|
|
|
|
|
|
title: "Duration",
|
|
|
|
|
|
component: (
|
|
|
|
|
|
<Stack className="duration-config" gap={2} direction="row">
|
|
|
|
|
|
<Field
|
|
|
|
|
|
id="duration-value"
|
|
|
|
|
|
placeholder="60"
|
2024-08-08 09:13:46 +03:30
|
|
|
|
onChange={(e) => handleChange(e, "duration")}
|
|
|
|
|
|
value={values.duration}
|
2024-08-21 22:50:42 +03:30
|
|
|
|
error={errors.duration}
|
2024-08-22 10:01:18 +03:30
|
|
|
|
type="number"
|
2024-08-05 14:17:41 +03:30
|
|
|
|
/>
|
|
|
|
|
|
<Select
|
2024-08-06 18:41:00 +03:30
|
|
|
|
onChange={(e) => handleChange(e, "unit")}
|
2024-08-05 14:17:41 +03:30
|
|
|
|
id="duration-unit"
|
2024-08-08 09:13:46 +03:30
|
|
|
|
items={durationOptions}
|
2024-08-06 18:41:00 +03:30
|
|
|
|
value={values.unit}
|
2024-08-05 14:17:41 +03:30
|
|
|
|
/>
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-08-26 17:16:29 -07:00
|
|
|
|
title: "Display name",
|
2024-08-05 14:17:41 +03:30
|
|
|
|
component: (
|
|
|
|
|
|
<Field
|
2024-08-26 17:16:29 -07:00
|
|
|
|
id="display-name"
|
2024-08-05 14:17:41 +03:30
|
|
|
|
placeholder="Maintanence at __ : __ for ___ minutes"
|
2024-08-26 17:16:29 -07:00
|
|
|
|
value={values.displayName}
|
|
|
|
|
|
onChange={(e) => handleChange(e, "displayName")}
|
|
|
|
|
|
error={errors.displayName}
|
2024-08-05 14:17:41 +03:30
|
|
|
|
/>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: "Add monitors",
|
|
|
|
|
|
component: (
|
2024-08-06 18:22:54 +03:30
|
|
|
|
<Stack
|
|
|
|
|
|
className="add-monitors-fields"
|
|
|
|
|
|
sx={{ width: "60%", maxWidth: "380px" }}
|
|
|
|
|
|
gap={2}
|
|
|
|
|
|
>
|
2024-08-05 14:17:41 +03:30
|
|
|
|
<Field
|
|
|
|
|
|
id="add-monitors"
|
|
|
|
|
|
placeholder="Start typing to search for current monitors"
|
|
|
|
|
|
value={values.AddMonitors}
|
|
|
|
|
|
onChange={(e) => handleChange(e, "AddMonitors")}
|
2024-08-21 22:50:42 +03:30
|
|
|
|
error={errors.addMonitors}
|
2024-08-05 14:17:41 +03:30
|
|
|
|
/>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
2024-08-05 21:41:28 +03:30
|
|
|
|
width: "fit-content",
|
2024-08-05 14:17:41 +03:30
|
|
|
|
fontSize: "var(--env-var-font-size-small)",
|
|
|
|
|
|
borderBottom: "1px dashed var(--env-var-color-3)",
|
2024-08-05 21:25:21 +03:30
|
|
|
|
paddingBottom: "4px",
|
2024-08-05 14:17:41 +03:30
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Add all monitors to this maintenance window
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
2024-08-03 09:40:08 +03:30
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="create-maintenance-window">
|
|
|
|
|
|
<Stack gap={3}>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
id="btn-back"
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "100px",
|
|
|
|
|
|
height: "30px",
|
|
|
|
|
|
gap: "10px",
|
|
|
|
|
|
backgroundColor: "var(--env-var-color-32)",
|
|
|
|
|
|
color: "var(--env-var-color-5)",
|
|
|
|
|
|
}}
|
|
|
|
|
|
label="Back"
|
|
|
|
|
|
level="tertiary"
|
|
|
|
|
|
img={<Back />}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
fontSize: "var(--env-var-font-size-large)",
|
|
|
|
|
|
fontWeight: "600",
|
|
|
|
|
|
color: "var(--env-var-color-5)",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{directory.title}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
|
|
|
|
<Typography sx={{ fontSize: "var(--env-var-font-size-medium)" }}>
|
|
|
|
|
|
{directory.description}
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<Stack
|
2024-08-05 14:17:41 +03:30
|
|
|
|
className="maintenance-options"
|
2024-08-03 09:40:08 +03:30
|
|
|
|
gap={5}
|
|
|
|
|
|
paddingY={4}
|
|
|
|
|
|
paddingX={8}
|
2024-08-05 14:17:41 +03:30
|
|
|
|
paddingBottom={10}
|
2024-08-03 09:40:08 +03:30
|
|
|
|
sx={{
|
|
|
|
|
|
border: "1px solid var(--env-var-color-16)",
|
|
|
|
|
|
borderRadius: "var(--env-var-radius-1)",
|
2024-08-08 09:13:46 +03:30
|
|
|
|
backgroundColor: "var(--env-var-color-0)",
|
2024-08-03 09:40:08 +03:30
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{configOptions.map((item, index) => (
|
|
|
|
|
|
<Stack key={index} display="-webkit-inline-box">
|
2024-08-05 14:17:41 +03:30
|
|
|
|
{item.title && configOptionTitle(item.title, item.description)}
|
2024-08-03 09:40:08 +03:30
|
|
|
|
{item.component && item.component}
|
|
|
|
|
|
</Stack>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</Stack>
|
2024-08-05 14:17:41 +03:30
|
|
|
|
<Stack justifyContent="end" direction="row" marginTop={3}>
|
2024-08-09 11:09:28 +03:30
|
|
|
|
<Button
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
"&:hover": {
|
|
|
|
|
|
backgroundColor: "transparent",
|
|
|
|
|
|
boxShadow: "none",
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
|
|
|
|
|
level="tertiary"
|
|
|
|
|
|
label="Cancel"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
"&:hover": {
|
|
|
|
|
|
backgroundColor: "#1570EF",
|
|
|
|
|
|
boxShadow: "none",
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
|
|
|
|
|
level="primary"
|
|
|
|
|
|
label="Create"
|
2024-08-20 20:33:28 +03:30
|
|
|
|
onClick={handleSubmit}
|
2024-08-09 11:09:28 +03:30
|
|
|
|
/>
|
2024-08-05 14:17:41 +03:30
|
|
|
|
</Stack>
|
2024-08-03 09:40:08 +03:30
|
|
|
|
</Stack>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default CreateNewMaintenanceWindow;
|