<% webhook_attempts = webhook_event.webhook_attempts.sort_by { |e| -e.id } %> <% if webhook_event.status == 'error' %> <% last_attempt = webhook_attempts.select { |e| e.attempt < SendWebhookRequest::MANUAL_ATTEMPT }.max_by(&:attempt) %> <% if webhook_event.webhook_attempts.none?(&:success?) && last_attempt.attempt <= 10 %>
  1. <%= svg_icon('clock', class: 'w-4 h-4 shrink-0') %>

    <%= t('next_attempt_in_time_in_words', time_in_words: distance_of_time_in_words(Time.current, last_attempt.created_at + (2**last_attempt.attempt).minutes)) %>

  2. <% end %> <% end %> <% if webhook_attempts.present? %> <% webhook_attempts.each do |webhook_attempt| %>
  3. <%= svg_icon(webhook_attempt.success? ? 'check' : 'x', class: 'w-4 h-4 shrink-0') %>

    <%= l(webhook_attempt.created_at.in_time_zone(current_account.timezone), format: :long, locale: current_account.locale) %>

    <%= Rack::Utils::HTTP_STATUS_CODES[webhook_attempt.response_status_code] %> <% if webhook_attempt.response_status_code.positive? %> (<%= webhook_attempt.response_status_code %>) <% end %>

    <% unless webhook_attempt.success? %>

    <%= webhook_attempt.response_body.presence || Rack::Utils::HTTP_STATUS_CODES[webhook_attempt.response_status_code] %>

    <% end %>
  4. <% end %> <% else %>
  5. <%= svg_icon('clock', class: 'w-4 h-4 shrink-0') %>

    <%= l(webhook_event.created_at.in_time_zone(current_account.timezone), format: :long, locale: current_account.locale) %>

  6. <% end %>
<% unless webhook_event.status == 'pending' %>
<%= button_to button_title(title: t('resend'), disabled_with: t('awaiting'), 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, webhook_event.uuid), form: { id: button_uuid = SecureRandom.uuid }, params: { button_id: button_uuid }, class: 'btn btn-neutral btn-sm text-white', method: :post, onclick: '[this.form.requestSubmit(), this.disabled = true]' %>
<% end %>