initial commit
This commit is contained in:
1 parent
7cb985116e
commit
75acf7b38f
955 files changed
+37333
-87054
No files matched your search
@@ -0,0 +1,157 @@
|
||||
import { HeaderCreate } from "@/components/notification-channels/HeaderCreate";
|
||||
import { BasePageWithStates, InfoBox } from "@/components/design-elements";
|
||||
import { ActionsMenu } from "@/components/actions-menu";
|
||||
import { Table } from "@/components/design-elements";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { Dialog } from "@/components/inputs";
|
||||
|
||||
import { useState } from "react";
|
||||
import { usePatch, useGet, useDelete } from "@/hooks/UseApi";
|
||||
import { useNavigate } from "react-router";
|
||||
import type { Header } from "@/components/design-elements/Table";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import type { IMaintenance } from "@/types/maintenance";
|
||||
import type { ActionMenuItem } from "@/components/actions-menu";
|
||||
|
||||
const MaintenancePage = () => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
const [selectedMaintenance, setSelectedMaintenance] =
|
||||
useState<IMaintenance | null>(null);
|
||||
const open = Boolean(selectedMaintenance);
|
||||
|
||||
const { patch, loading: isPausing } = usePatch<{}, any>();
|
||||
const { response, isValidating, refetch } = useGet<ApiResponse<any>>(
|
||||
"/maintenance",
|
||||
{},
|
||||
{}
|
||||
);
|
||||
const { deleteFn, loading: isDeleting } = useDelete<any>();
|
||||
|
||||
const maintenance = response?.data || [];
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!selectedMaintenance) return;
|
||||
const res = await deleteFn(`/maintenance/${selectedMaintenance._id}`);
|
||||
if (res) {
|
||||
setSelectedMaintenance(null);
|
||||
refetch();
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
setSelectedMaintenance(null);
|
||||
};
|
||||
|
||||
const getActions = (maintenance: IMaintenance): ActionMenuItem[] => {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
label: "Configure",
|
||||
action: () => {
|
||||
navigate(`/maintenance/${maintenance._id}/configure`);
|
||||
},
|
||||
closeMenu: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
label: maintenance.isActive ? "Disable" : "Enable",
|
||||
action: async () => {
|
||||
const res = await patch(`/maintenance/${maintenance._id}/active`, {});
|
||||
if (res) {
|
||||
refetch();
|
||||
}
|
||||
},
|
||||
closeMenu: true,
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
label: <Typography color={theme.palette.error.main}>Remove</Typography>,
|
||||
action: async () => {
|
||||
setSelectedMaintenance(maintenance);
|
||||
},
|
||||
closeMenu: true,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const getHeaders = () => {
|
||||
const headers: Header<IMaintenance>[] = [
|
||||
{
|
||||
id: "name",
|
||||
content: "Name",
|
||||
render: (row) => {
|
||||
return <Typography>{row?.name}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "active",
|
||||
content: "Active",
|
||||
render: (row) => {
|
||||
const active = row.isActive ? "Yes" : "No";
|
||||
return <Typography>{active}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "repeat",
|
||||
content: "Repeat",
|
||||
render: (row) => {
|
||||
const active = row.repeat ? row.repeat : "No";
|
||||
return <Typography textTransform={"capitalize"}>{active}</Typography>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
content: t("actions"),
|
||||
render: (row) => {
|
||||
return <ActionsMenu items={getActions(row)} />;
|
||||
},
|
||||
},
|
||||
];
|
||||
return headers;
|
||||
};
|
||||
|
||||
const headers = getHeaders();
|
||||
|
||||
return (
|
||||
<BasePageWithStates
|
||||
page="Maintenance windows"
|
||||
loading={isValidating}
|
||||
error={null}
|
||||
items={maintenance}
|
||||
bullets={t("maintenanceWindow.fallback.checks", { returnObjects: true })}
|
||||
actionLink="/maintenance/create"
|
||||
actionButtonText={t("createMaintenanceWindow")}
|
||||
>
|
||||
<InfoBox
|
||||
title="Scheduled Maintenance Periods"
|
||||
description="Plan maintenance windows to temporarily pause monitoring checks. During maintenance, your monitors won't run checks or send notifications, preventing false alerts during planned downtime."
|
||||
/>
|
||||
<HeaderCreate
|
||||
label={"Create a new maintenance window"}
|
||||
isLoading={isValidating || isPausing || isDeleting}
|
||||
path="/maintenance/create"
|
||||
/>
|
||||
<Table
|
||||
headers={headers}
|
||||
data={maintenance}
|
||||
onRowClick={(row: IMaintenance) => {
|
||||
navigate(`/maintenance/${row._id}/configure`);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Dialog
|
||||
title={t("createNotifications.dialogDeleteTitle")}
|
||||
content={t("createNotifications.dialogDeleteContent")}
|
||||
open={open}
|
||||
onConfirm={handleConfirm}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
</BasePageWithStates>
|
||||
);
|
||||
};
|
||||
|
||||
export default MaintenancePage;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { MaintenanceForm } from "@/pages/maintenance/MaintenanceForm";
|
||||
|
||||
import { useParams } from "react-router";
|
||||
import { useNavigate } from "react-router";
|
||||
import { z } from "zod";
|
||||
import { usePatch, useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import { maintenanceSchema } from "@/validation/zod";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
|
||||
type FormValues = z.infer<typeof maintenanceSchema>;
|
||||
|
||||
const MaintenanceConfigPage = () => {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { patch, loading: isPatching } = usePatch<FormValues, any>();
|
||||
const { response, loading } = useGet<ApiResponse<any>>(`/maintenance/${id}`);
|
||||
const { response: monitorsResponse, loading: monitorsLoading } =
|
||||
useGet<ApiResponse<IMonitor[]>>("/monitors");
|
||||
const maintenance = response?.data;
|
||||
const monitors = monitorsResponse?.data || [];
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
const res = await patch(`/maintenance/${id}`, data);
|
||||
if (res) {
|
||||
navigate(-1);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<MaintenanceForm
|
||||
monitorOptions={monitors}
|
||||
initialData={maintenance}
|
||||
onSubmit={onSubmit}
|
||||
loading={loading || isPatching || monitorsLoading}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default MaintenanceConfigPage;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { MaintenanceForm } from "@/pages/maintenance/MaintenanceForm";
|
||||
|
||||
import { useNavigate } from "react-router";
|
||||
import { z } from "zod";
|
||||
import { usePost, useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/hooks/UseApi";
|
||||
import { maintenanceSchema } from "@/validation/zod";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
import type { IMaintenance } from "@/types/maintenance";
|
||||
|
||||
type FormValues = z.infer<typeof maintenanceSchema>;
|
||||
|
||||
const MaintenanceCreatePage = () => {
|
||||
const navigate = useNavigate();
|
||||
const { post, loading } = usePost<FormValues, IMaintenance>();
|
||||
const { response, loading: monitorsLoading } =
|
||||
useGet<ApiResponse<IMonitor[]>>("/monitors");
|
||||
|
||||
const monitors = response?.data || [];
|
||||
console.log(monitors);
|
||||
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
const res = await post("/maintenance", data);
|
||||
if (res) {
|
||||
navigate(-1);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<MaintenanceForm
|
||||
monitorOptions={monitors}
|
||||
onSubmit={onSubmit}
|
||||
loading={loading || monitorsLoading}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default MaintenanceCreatePage;
|
||||
@@ -0,0 +1,229 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { Button, DateTimePicker } from "@/components/inputs";
|
||||
import { ConfigBox, BasePage, InfoBox } from "@/components/design-elements";
|
||||
import { TextInput, Select, AutoComplete } from "@/components/inputs";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import dayjs from "dayjs";
|
||||
import type { Dayjs } from "dayjs";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { z } from "zod";
|
||||
import { MaintenanceRepeats } from "@/types/maintenance";
|
||||
import { maintenanceSchema } from "@/validation/zod";
|
||||
import { useForm, Controller, type SubmitHandler } from "react-hook-form";
|
||||
import { useEffect } from "react";
|
||||
import { useInitForm } from "@/hooks/forms/UseInitMaintenanceForm";
|
||||
import type { IMonitor } from "@/types/monitor";
|
||||
|
||||
type FormValues = z.infer<typeof maintenanceSchema>;
|
||||
|
||||
export const MaintenanceForm = ({
|
||||
monitorOptions,
|
||||
initialData,
|
||||
onSubmit,
|
||||
loading,
|
||||
}: {
|
||||
monitorOptions: IMonitor[];
|
||||
initialData?: Partial<FormValues>;
|
||||
onSubmit: SubmitHandler<FormValues>;
|
||||
loading: boolean;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
const { defaults } = useInitForm({ initialData: initialData });
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
reset,
|
||||
getValues,
|
||||
formState: { errors },
|
||||
} = useForm<FormValues>({
|
||||
resolver: zodResolver(maintenanceSchema),
|
||||
defaultValues: defaults,
|
||||
mode: "onChange",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
reset(defaults);
|
||||
}, [initialData, reset, defaults]);
|
||||
|
||||
const onError = (errors: any) => {
|
||||
console.log(errors);
|
||||
console.log(getValues());
|
||||
};
|
||||
|
||||
return (
|
||||
<BasePage component={"form"} onSubmit={handleSubmit(onSubmit, onError)}>
|
||||
<InfoBox
|
||||
title="About Maintenance Windows"
|
||||
description="During maintenance windows, all monitoring is suspended for selected monitors. No network checks will be performed, preventing any status updates or notifications from being triggered. Your monitors will appear frozen at their last known status, and status pages will display a maintenance indicator. Once the maintenance window ends, monitoring automatically resumes, and alerts will trigger if issues are detected. Maintenance periods do not count against uptime calculations."
|
||||
/>
|
||||
<ConfigBox
|
||||
title={t("createMaintenanceWindowPage.generalSettingsTitle")}
|
||||
subtitle={t("createMaintenanceWindowPage.generalSettingsDescription")}
|
||||
rightContent={
|
||||
<Stack spacing={theme.spacing(8)}>
|
||||
<Controller
|
||||
name="name"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
fieldLabel={t(
|
||||
"createMaintenanceWindowPage.generalSettingsName"
|
||||
)}
|
||||
required
|
||||
type="text"
|
||||
placeholder={t(
|
||||
"createMaintenanceWindowPage.generalSettingsNamePlaceholder"
|
||||
)}
|
||||
fullWidth
|
||||
error={!!errors.name}
|
||||
helperText={errors.name ? errors.name.message : ""}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="repeat"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<Select
|
||||
value={field.value || ""}
|
||||
fieldLabel={t(
|
||||
"createMaintenanceWindowPage.generalSettingsRepeat"
|
||||
)}
|
||||
required
|
||||
error={!!errors.repeat}
|
||||
onChange={field.onChange}
|
||||
fullWidth
|
||||
>
|
||||
{MaintenanceRepeats.map((option) => {
|
||||
return (
|
||||
<MenuItem key={option} value={option}>
|
||||
<Typography textTransform={"capitalize"}>
|
||||
{option}
|
||||
</Typography>
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
)}
|
||||
/>
|
||||
</Stack>
|
||||
}
|
||||
/>
|
||||
<ConfigBox
|
||||
title={t("createMaintenanceWindowPage.timingSettingsTitle")}
|
||||
subtitle={t("createMaintenanceWindowPage.timingSettingsDescription")}
|
||||
rightContent={
|
||||
<Stack spacing={theme.spacing(8)}>
|
||||
<Controller
|
||||
name="startTime"
|
||||
control={control}
|
||||
render={({ field }) => {
|
||||
const value = field.value ? dayjs(field.value) : null;
|
||||
return (
|
||||
<>
|
||||
<DateTimePicker
|
||||
{...field}
|
||||
fieldLabel="Start time"
|
||||
required
|
||||
value={value}
|
||||
onChange={(val: Dayjs | null) =>
|
||||
field.onChange(val?.toDate())
|
||||
}
|
||||
/>
|
||||
{errors?.startTime?.message && (
|
||||
<Typography color="error" variant="caption">
|
||||
{errors.startTime.message}
|
||||
</Typography>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
name="endTime"
|
||||
control={control}
|
||||
render={({ field }) => {
|
||||
const value = field.value ? dayjs(field.value) : null;
|
||||
return (
|
||||
<>
|
||||
<DateTimePicker
|
||||
{...field}
|
||||
fieldLabel="End time"
|
||||
required
|
||||
value={value}
|
||||
onChange={(val: Dayjs | null) =>
|
||||
field.onChange(val?.toDate())
|
||||
}
|
||||
/>
|
||||
{errors?.endTime?.message && (
|
||||
<Typography color="error" variant="caption">
|
||||
{errors.endTime.message}
|
||||
</Typography>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</Stack>
|
||||
}
|
||||
/>
|
||||
<ConfigBox
|
||||
title={t("createMaintenanceWindowPage.monitorsTitle")}
|
||||
subtitle={t("createMaintenanceWindowPage.monitorsDescription")}
|
||||
rightContent={
|
||||
<Controller
|
||||
name="monitors"
|
||||
control={control}
|
||||
defaultValue={[]}
|
||||
render={({ field }) => {
|
||||
const selectedMonitors = monitorOptions.filter((o: any) =>
|
||||
(field.value || []).includes(o._id)
|
||||
);
|
||||
const count = selectedMonitors.length;
|
||||
|
||||
return (
|
||||
<AutoComplete
|
||||
multiple
|
||||
fieldLabel="Monitors"
|
||||
required
|
||||
options={monitorOptions}
|
||||
getOptionLabel={(option) => option.name}
|
||||
value={selectedMonitors}
|
||||
onChange={(_, newValue) => {
|
||||
field.onChange(newValue.map((o: any) => o._id));
|
||||
}}
|
||||
renderInput={(params) => (
|
||||
<TextInput
|
||||
{...params}
|
||||
placeholder={
|
||||
count > 0 ? `${count} selected` : "Type to search"
|
||||
}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
<Stack direction="row" justifyContent="flex-end">
|
||||
<Button
|
||||
loading={loading}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="accent"
|
||||
>
|
||||
{t("settingsSave")}
|
||||
</Button>
|
||||
</Stack>
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user