feat(webhook): add simple validation
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
This commit is contained in:
@@ -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 = () => {
|
||||
<span>{intl.formatMessage(messages.customHeadersAdd)}</span>
|
||||
</Button>
|
||||
</div>
|
||||
{errors.customHeaders &&
|
||||
touched.customHeaders &&
|
||||
typeof errors.customHeaders === 'string' && (
|
||||
<div className="error">{errors.customHeaders}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
|
||||
@@ -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!",
|
||||
|
||||
Reference in New Issue
Block a user