<%= 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 %>
<% if @webhook_events.present? || params[:status].present? %>

<%= t('events_log') %>

<%= link_to t('all'), url_for(params.to_unsafe_h.except(:status)), style: 'margin-bottom: -1px', class: "tab h-10 text-base #{params[:status].blank? ? 'tab-active tab-bordered' : 'pb-[3px]'}" %> <%= link_to t('successed'), url_for(params.to_unsafe_h.merge(status: 'success')), style: 'margin-bottom: -1px', class: "tab h-10 text-base #{params[:status] == 'success' ? 'tab-active tab-bordered' : 'pb-[3px]'}" %> <%= link_to t('failed'), url_for(params.to_unsafe_h.merge(status: 'error')), style: 'margin-bottom: -1px', class: "tab h-10 text-base #{params[:status] == 'error' ? 'tab-active tab-bordered' : 'pb-[3px]'}" %>
<% if @webhook_events.present? %>
<% @webhook_events.each do |event| %>
<% if event.status == 'success' %>
<%= svg_icon('check', class: 'w-4 h-4 shrink-0 stroke-2') %>
<% elsif event.status == 'pending' %>
<%= svg_icon('clock', class: 'w-4 h-4 shrink-0 stroke-2') %>
<% elsif event.status == 'error' %>
<%= svg_icon('x', class: 'w-4 h-4 shrink-0') %>
<% end %>
<%= event.event_type %>
<%= button_to button_title(title: t('resend'), disabled_with: t('sending'), icon: svg_icon('rotate', class: 'w-4 h-4'), icon_disabled: svg_icon('loader', class: 'w-4 h-4 animate-spin')), resend_settings_webhook_event_path(@webhook_url.id, event.uuid), class: 'btn btn-neutral btn-xs h-2 text-white relative z-[1] hidden md:group-hover:inline-block', data: { turbo_frame: :drawer }, method: :post %> <%= l(event.created_at, locale: current_account.locale, format: :short) %>
<% end %>
<% else %>
<%= t('there_are_no_events') %>
<% end %> <% if @pagy.pages > 1 %>
<% if @pagy.prev %> <%= link_to '«', url_for(page: @pagy.prev, anchor: 'log'), class: 'join-item btn min-h-full h-10' %> <% else %> « <% end %> <%= "Page #{@pagy.page}" %> <% if @pagy.next %> <%= link_to '»', url_for(page: @pagy.next, anchor: 'log'), class: 'join-item btn min-h-full h-10' %> <% else %> » <% end %>
<% end %>
<% elsif submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last %>
<%= 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') %>
<%== HighlightCode.call(code, 'JSON', theme: 'base16.dark') %>
<% end %>