diff --git a/app/controllers/admin/donations_controller.rb b/app/controllers/admin/donations_controller.rb index 51ea4e3..bdfff93 100644 --- a/app/controllers/admin/donations_controller.rb +++ b/app/controllers/admin/donations_controller.rb @@ -5,6 +5,7 @@ class Admin::DonationsController < Admin::BaseController # GET /donations def index @pagy, @donations = pagy(Donation.completed.order('paid_at desc')) + @pending_donations = Donation.incomplete.order('paid_at desc') @stats = { overall_sats: @donations.sum("amount_sats"), diff --git a/app/models/donation.rb b/app/models/donation.rb index b319259..f3e585c 100644 --- a/app/models/donation.rb +++ b/app/models/donation.rb @@ -17,6 +17,7 @@ class Donation < ApplicationRecord scope :pending, -> { where(payment_status: "pending") } scope :processing, -> { where(payment_status: "processing") } scope :completed, -> { where(payment_status: "settled") } + scope :incomplete, -> { where.not(payment_status: "settled") } aasm column: :payment_status do state :pending, initial: true diff --git a/app/views/admin/donations/_list.html.erb b/app/views/admin/donations/_list.html.erb new file mode 100644 index 0000000..8a75699 --- /dev/null +++ b/app/views/admin/donations/_list.html.erb @@ -0,0 +1,32 @@ + + + + + + + + + + + + + <% donations.each do |donation| %> + + + + + + + + + <% end %> + +
UserSatsFiat AmountPublic nameDate
<%= link_to donation.user.cn, admin_user_path(donation.user.cn), class: 'ks-text-link' %><% if donation.amount_sats.present? %><%= number_with_delimiter donation.amount_sats %><% end %><% if donation.fiat_amount.present? %><%= number_to_currency donation.fiat_amount.to_f / 100, unit: "" %> <%= donation.fiat_currency %><% end %><%= donation.public_name %><%= donation.paid_at ? donation.paid_at.strftime("%Y-%m-%d (%H:%M UTC)") : donation.created_at.strftime("%Y-%m-%d (%H:%M UTC)") %> + <%= link_to 'Show', admin_donation_path(donation), class: 'btn btn-sm btn-gray' %> + <%= link_to 'Edit', edit_admin_donation_path(donation), class: 'btn btn-sm btn-gray' %> + <%= link_to 'Destroy', admin_donation_path(donation), class: 'btn btn-sm btn-red', + data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' } %> +
+<% if defined?(pagy) %> +<%== pagy_nav pagy %> +<% end %> diff --git a/app/views/admin/donations/index.html.erb b/app/views/admin/donations/index.html.erb index 90a755e..2fa6f91 100644 --- a/app/views/admin/donations/index.html.erb +++ b/app/views/admin/donations/index.html.erb @@ -18,42 +18,24 @@ <% end %> + <% if @pending_donations.any? %> +
+

Pending

+ <%= render partial: "admin/donations/list", locals: { + donations: @pending_donations + } %> +
+ <% end %> +
<% if @donations.any? %> -

Recent Donations

- - - - - - - - - - - - - <% @donations.each do |donation| %> - - - - - - - - - <% end %> - -
UserSatsFiat AmountPublic nameDate
<%= link_to donation.user.cn, admin_user_path(donation.user.cn), class: 'ks-text-link' %><% if donation.amount_sats.present? %><%= number_with_delimiter donation.amount_sats %><% end %><% if donation.fiat_amount.present? %><%= number_to_currency donation.fiat_amount.to_f / 100, unit: "" %> <%= donation.fiat_currency %><% end %><%= donation.public_name %><%= donation.paid_at ? donation.paid_at.strftime("%Y-%m-%d (%H:%M UTC)") : "" %> - <%= link_to 'Show', admin_donation_path(donation), class: 'btn btn-sm btn-gray' %> - <%= link_to 'Edit', edit_admin_donation_path(donation), class: 'btn btn-sm btn-gray' %> - <%= link_to 'Destroy', admin_donation_path(donation), class: 'btn btn-sm btn-red', - data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' } %> -
- <%== pagy_nav @pagy %> +

Recent

+ <%= render partial: "admin/donations/list", locals: { + donations: @donations, pagy: @pagy + } %> <% else %>

- No donations yet. + No donations received yet.

<% end %>
diff --git a/app/views/admin/donations/show.html.erb b/app/views/admin/donations/show.html.erb index 00b32cc..3e3ad65 100644 --- a/app/views/admin/donations/show.html.erb +++ b/app/views/admin/donations/show.html.erb @@ -25,7 +25,15 @@ <%= @donation.public_name %> - Date + Payment status + <%= @donation.payment_status %> + + + Created at + <%= @donation.created_at&.strftime("%Y-%m-%d (%H:%M UTC)") %> + + + Paid at <%= @donation.paid_at&.strftime("%Y-%m-%d (%H:%M UTC)") %>