From db48f449f5fd1a56e4d0146fb816e0ba324f1b6f Mon Sep 17 00:00:00 2001 From: 0xsysr3ll <0xsysr3ll@pm.me> Date: Sun, 14 Dec 2025 22:47:53 +0100 Subject: [PATCH] feat(webhook): add simple validation Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> --- .../NotificationsWebhook/index.tsx | 28 +++++++++++++++++-- src/i18n/locale/en.json | 3 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/components/Settings/Notifications/NotificationsWebhook/index.tsx b/src/components/Settings/Notifications/NotificationsWebhook/index.tsx index 775f5b2b..a1fbaff2 100644 --- a/src/components/Settings/Notifications/NotificationsWebhook/index.tsx +++ b/src/components/Settings/Notifications/NotificationsWebhook/index.tsx @@ -92,8 +92,7 @@ const messages = defineMessages( customHeadersRemove: 'Remove', customHeadersKey: 'Header Name', customHeadersValue: 'Header Value', - customHeadersKeyRequired: 'Header name is required', - customHeadersValueRequired: 'Header value is required', + customHeadersIncomplete: 'All headers must have both name and value', validationJsonPayloadRequired: 'You must provide a valid JSON payload', webhooksettingssaved: 'Webhook notification settings saved successfully!', webhooksettingsfailed: 'Webhook notification settings failed to save.', @@ -139,7 +138,25 @@ const NotificationsWebhook = () => { supportVariables: Yup.boolean(), - customHeaders: Yup.array(), + customHeaders: Yup.array() + .of( + Yup.object().shape({ + key: Yup.string(), + value: Yup.string(), + }) + ) + .test( + 'complete-headers', + intl.formatMessage(messages.customHeadersIncomplete), + function (headers) { + if (!headers || headers.length === 0) return true; + return headers.every( + (header) => + (!header.key || !header.key.trim()) === + (!header.value || !header.value.trim()) + ); + } + ), jsonPayload: Yup.string() .when('enabled', { @@ -440,6 +457,11 @@ const NotificationsWebhook = () => { {intl.formatMessage(messages.customHeadersAdd)} + {errors.customHeaders && + touched.customHeaders && + typeof errors.customHeaders === 'string' && ( +
{errors.customHeaders}
+ )}
diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json index 026ecb00..b67623c9 100644 --- a/src/i18n/locale/en.json +++ b/src/i18n/locale/en.json @@ -683,12 +683,11 @@ "components.Settings.Notifications.NotificationsWebhook.authheader": "Authorization Header", "components.Settings.Notifications.NotificationsWebhook.customHeaders": "Custom Headers", "components.Settings.Notifications.NotificationsWebhook.customHeadersAdd": "Add Header", + "components.Settings.Notifications.NotificationsWebhook.customHeadersIncomplete": "All headers must have both name and value", "components.Settings.Notifications.NotificationsWebhook.customHeadersKey": "Header Name", - "components.Settings.Notifications.NotificationsWebhook.customHeadersKeyRequired": "Header name is required", "components.Settings.Notifications.NotificationsWebhook.customHeadersRemove": "Remove", "components.Settings.Notifications.NotificationsWebhook.customHeadersTip": "Add custom HTTP headers to include with webhook requests", "components.Settings.Notifications.NotificationsWebhook.customHeadersValue": "Header Value", - "components.Settings.Notifications.NotificationsWebhook.customHeadersValueRequired": "Header value is required", "components.Settings.Notifications.NotificationsWebhook.customJson": "JSON Payload", "components.Settings.Notifications.NotificationsWebhook.resetPayload": "Reset to Default", "components.Settings.Notifications.NotificationsWebhook.resetPayloadSuccess": "JSON payload reset successfully!",