From f6bdc40c243a8fbe0f3fcbfa29ed64f7d323827c Mon Sep 17 00:00:00 2001 From: "Cayo P. R. Oliveira" Date: Fri, 14 Feb 2025 11:43:15 -0300 Subject: [PATCH] feat: add name to webhook (#4) * feat(migration): add name column to webhook table * feat(webhooks): add name parameter to webhook params * feat(webhooks): add example webhook name constant and input field to form * fix(webhooks): add webhook name label and placeholder to multiple locales in the form * feat(webhooks): display webhook name in the UI and include it in the API response * Revert 'fix(webhooks): add webhook name label and placeholder to multiple locales in the form' This reverts commit e547778a1c038c934e22ceb25935f541cb09e2cd. * test(webhooks): add tests for creating and updating webhooks with name attribute * chore(webhooks): add name property to webhook definitions in Swagger documentation * chore(webhooks): remove unnecessary input touch event for webhook name field * chore(webhooks): apply review changes requested * chore(webhooks): revert auto lint changes in commit 18ec4cafeb72fd385b70f65f1873d7cfb65216a6 --- .../api/v1/accounts/webhooks_controller.rb | 2 +- .../dashboard/i18n/locale/en/integrations.json | 4 ++++ .../integrations/Webhooks/WebhookForm.vue | 14 ++++++++++++++ .../settings/integrations/Webhooks/WebhookRow.vue | 14 ++++++++++++-- app/models/webhook.rb | 1 + .../v1/accounts/webhooks/_webhook.json.jbuilder | 1 + db/migrate/20250213190934_add_name_to_webhooks.rb | 5 +++++ db/schema.rb | 1 + .../api/v1/accounts/webhook_controller_spec.rb | 15 +++++++++++++-- spec/factories/webhooks.rb | 1 + .../request/webhooks/create_update_payload.yml | 3 +++ swagger/definitions/resource/webhook.yml | 3 +++ swagger/swagger.json | 8 ++++++++ 13 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20250213190934_add_name_to_webhooks.rb diff --git a/app/controllers/api/v1/accounts/webhooks_controller.rb b/app/controllers/api/v1/accounts/webhooks_controller.rb index 7ea257ed2..9f8e94821 100644 --- a/app/controllers/api/v1/accounts/webhooks_controller.rb +++ b/app/controllers/api/v1/accounts/webhooks_controller.rb @@ -23,7 +23,7 @@ class Api::V1::Accounts::WebhooksController < Api::V1::Accounts::BaseController private def webhook_params - params.require(:webhook).permit(:inbox_id, :url, subscriptions: []) + params.require(:webhook).permit(:inbox_id, :name, :url, subscriptions: []) end def fetch_webhook diff --git a/app/javascript/dashboard/i18n/locale/en/integrations.json b/app/javascript/dashboard/i18n/locale/en/integrations.json index 5105513d5..95cd0c9f5 100644 --- a/app/javascript/dashboard/i18n/locale/en/integrations.json +++ b/app/javascript/dashboard/i18n/locale/en/integrations.json @@ -44,6 +44,10 @@ "CONTACT_UPDATED": "Contact updated" } }, + "NAME": { + "LABEL": "Webhook Name", + "PLACEHOLDER": "Enter the name of the webhook" + }, "END_POINT": { "LABEL": "Webhook URL", "PLACEHOLDER": "Example: {webhookExampleURL}", diff --git a/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookForm.vue b/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookForm.vue index f3c724bb2..6368bff19 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookForm.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookForm.vue @@ -53,6 +53,7 @@ export default { data() { return { url: this.value.url || '', + name: this.value.name || '', subscriptions: this.value.subscriptions || [], supportedWebhookEvents: SUPPORTED_WEBHOOK_EVENTS, }; @@ -66,11 +67,15 @@ export default { } ); }, + webhookNameInputPlaceholder() { + return this.$t('INTEGRATION_SETTINGS.WEBHOOK.FORM.NAME.PLACEHOLDER'); + }, }, methods: { onSubmit() { this.$emit('submit', { url: this.url, + name: this.name, subscriptions: this.subscriptions, }); }, @@ -95,6 +100,15 @@ export default { {{ $t('INTEGRATION_SETTINGS.WEBHOOK.FORM.END_POINT.ERROR') }} + diff --git a/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookRow.vue b/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookRow.vue index 1ff6244ba..1a39694b3 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookRow.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/integrations/Webhooks/WebhookRow.vue @@ -37,8 +37,18 @@ const subscribedEvents = computed(() => {