diff --git a/client/src/Hooks/useMonitorForm.ts b/client/src/Hooks/useMonitorForm.ts index 963409fc8a..5e2dcaa25b 100644 --- a/client/src/Hooks/useMonitorForm.ts +++ b/client/src/Hooks/useMonitorForm.ts @@ -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, diff --git a/client/src/Pages/CreateMonitor/index.tsx b/client/src/Pages/CreateMonitor/index.tsx index 15b76eab36..8bf9be0158 100644 --- a/client/src/Pages/CreateMonitor/index.tsx +++ b/client/src/Pages/CreateMonitor/index.tsx @@ -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) { diff --git a/client/src/Validation/monitor.ts b/client/src/Validation/monitor.ts index 9acffe6fed..71adbcdd2e 100644 --- a/client/src/Validation/monitor.ts +++ b/client/src/Validation/monitor.ts @@ -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")