diff --git a/app/controllers/webhook_settings_controller.rb b/app/controllers/webhook_settings_controller.rb index f9245f49..77fa22bf 100644 --- a/app/controllers/webhook_settings_controller.rb +++ b/app/controllers/webhook_settings_controller.rb @@ -32,9 +32,13 @@ class WebhookSettingsController < ApplicationController def new; end def create - @webhook_url.save! + if @webhook_url.url.present? + @webhook_url.save! - redirect_to settings_webhooks_path, notice: I18n.t('webhook_url_has_been_saved') + redirect_to settings_webhooks_path, notice: I18n.t('webhook_url_has_been_saved') + else + redirect_back fallback_location: settings_webhooks_path + end end def update diff --git a/app/views/testing_api_settings/index.html.erb b/app/views/testing_api_settings/index.html.erb index 956aa970..a385139d 100644 --- a/app/views/testing_api_settings/index.html.erb +++ b/app/views/testing_api_settings/index.html.erb @@ -8,11 +8,21 @@ <%= render 'shared/clipboard_copy', icon: 'copy', text: current_user.access_token.token, class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: t('copy'), copied_title: t('copied') %> - <%= form_for @webhook_url, url: settings_webhooks_path, method: :post, html: { autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %> - <%= f.label :url, 'Webhook URL', class: 'text-sm font-semibold' %> -
- <%= f.url_field :url, class: 'base-input w-full', placeholder: 'https://example.com/hook' %> - <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button w-full' %> -
+ <% if @webhook_url.new_record? %> + <%= form_for @webhook_url, url: settings_webhooks_path, method: :post, html: { autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %> + <%= f.label :url, 'Webhook URL', class: 'text-sm font-semibold' %> +
+ <%= f.url_field :url, class: 'base-input w-full', placeholder: 'https://example.com/hook' %> + <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button w-full' %> +
+ <% end %> + <% else %> + <%= form_for @webhook_url, url: settings_webhook_path(@webhook_url), method: :put, html: { autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %> + <%= f.label :url, 'Webhook URL', class: 'text-sm font-semibold' %> +
+ <%= f.url_field :url, class: 'base-input w-full', placeholder: 'https://example.com/hook', required: true %> + <%= f.button button_title(title: t('save'), disabled_with: t('saving')), class: 'base-button w-full' %> +
+ <% end %> <% end %> <% end %>