Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/src/Hooks/useMonitorForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const getBaseDefaults = (data?: Monitor | null) => ({
name: data?.name || "",
description: data?.description || "",
interval: data?.interval || 60000,
notifications: data?.notifications || [],
// `notifications` holds plain notification IDs (regular channels)
notifications: data?.notificationConfig
? data.notificationConfig.filter((c) => !c.escalation).map((c) => c.notificationId)
: data?.notifications || [],
// `notificationConfig` preserves escalation entries (and any explicit configs)
notificationConfig: data?.notificationConfig || [],
statusWindowSize: data?.statusWindowSize || 5,
statusWindowThreshold: data?.statusWindowThreshold || 60,
geoCheckEnabled: data?.geoCheckEnabled ?? false,
Expand Down
21 changes: 19 additions & 2 deletions client/src/Pages/CreateMonitor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,28 @@ const CreateMonitorPage = () => {
};

const onSubmit = async (data: MonitorFormData) => {
// Build notificationConfig expected by backend by combining regular notifications
// and any escalation entries from the notificationConfig form field.
const regularNotifications = data.notifications ?? [];
const escalationConfigs = (data.notificationConfig ?? []).filter((c) => c.escalation);

const notificationConfig = [
// regular notifications as simple entries
...regularNotifications.map((id: string) => ({ notificationId: id })),
// include escalation-configured entries (these already include escalation)
...escalationConfigs,
];

const submitData = {
...data,
notificationConfig,
};

let result;
if (isEditMode && monitorId) {
result = await patch(`/monitors/${monitorId}`, data);
result = await patch(`/monitors/${monitorId}`, submitData);
} else {
result = await post("/monitors", data);
result = await post("/monitors", submitData);
}

if (result?.success) {
Expand Down
7 changes: 7 additions & 0 deletions client/src/Validation/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const baseSchema = z.object({
description: z.string().optional(),
interval: z.number().min(15000, "Interval must be at least 15 seconds"),
notifications: z.array(z.string()),
notificationConfig: z.array(z.object({
notificationId: z.string(),
escalation: z.object({
delayMinutes: z.number().min(1, "Delay must be at least 1 minute"),
channelId: z.string()
}).optional()
})).optional(),
statusWindowSize: z
.number({ message: "Status window size is required" })
.min(1, "Status window size must be at least 1")
Expand Down