<%= render 'shared/settings_nav' %>

Webhook

<% if params[:action] == 'index' %> <%= render 'shared/test_mode_toggle' %> <% end %> <% if @webhook_url.persisted? && params[:action] == 'index' %> <%= link_to new_settings_webhook_path, class: 'md:ml-3 btn bg-white btn-outline btn-md gap-2 w-full md:w-fit', data: { turbo_frame: 'modal' } do %> <%= svg_icon('plus', class: 'w-6 h-6') %> <%= t('new_webhook') %> <% end %> <% end %>
<%= label_tag :url, 'Webhook URL', class: 'text-sm font-semibold' %> <% if @webhook_url.persisted? %>
<%= link_to webhook_secret_path(@webhook_url), class: 'btn btn-outline btn-sm bg-white', data: { turbo_frame: 'modal' } do %> <%= svg_icon('lock', class: 'w-4 h-4') %> <%= @webhook_url.secret.present? ? t('edit_secret') : t('add_secret') %> <% end %>
<%= button_to settings_webhook_path(@webhook_url), class: 'btn btn-warning btn-sm', method: :delete, data: { turbo_confirm: t('are_you_sure_') } do %> <%= t('delete') %> <% end %>
<% end %>
<%= form_for @webhook_url, url: @webhook_url.persisted? ? settings_webhook_path(@webhook_url) : settings_webhooks_path, html: { autocomplete: 'off' } do |f| %>
<%= f.url_field :url, class: 'input font-mono input-bordered 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 md:w-32' %>
<% unless @webhook_url.persisted? %>
<% WebhookUrl::EVENTS.group_by { |e| e.include?('form') }.each do |_, events| %>
<%= f.collection_check_boxes(:events, events, :to_s, :to_s, include_hidden: false) do |b| %>
<% end %>
<% end %>
<% end %> <% end %> <% if @webhook_url.persisted? %> <%= form_for @webhook_url, url: webhook_preference_path(@webhook_url), method: :put, html: { autocomplete: 'off', class: 'mt-2' } do |f| %>
<% WebhookUrl::EVENTS.group_by { |e| e.include?('form') }.each do |_, events| %>
<% events.each do |event| %> <%= f.fields_for :events do |ff| %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>
<% submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last %> <% if submitter %>
<%= t('submission_example_payload') %> <% if @webhook_url.url.present? && @webhook_url.events.include?('form.completed') %> <%= button_to button_title(title: 'Test Webhook', disabled_with: t('sending'), icon_disabled: svg_icon('loader', class: 'w-4 h-4 animate-spin')), settings_webhook_resend_path(@webhook_url), class: 'btn btn-neutral btn-outline btn-sm', method: :post %> <% end %>
<%= render 'shared/clipboard_copy', icon: 'copy', text: code = JSON.pretty_generate({ event_type: 'form.completed', timestamp: Time.current.iso8601, data: Submitters::SerializeForWebhook.call(submitter) }).gsub(/^/, ' ').sub(/^\s+/, ''), class: 'btn btn-ghost text-white', icon_class: 'w-6 h-6 text-white', copy_title: t('copy'), copied_title: t('copied') %>
<%= code %>
<% end %>