Add username filter to admin invitations index
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e8f912360b
commit
c99d8545c1
@ -1,12 +1,28 @@
|
||||
class Admin::InvitationsController < Admin::BaseController
|
||||
before_action :set_current_section
|
||||
|
||||
def index
|
||||
@current_section = :invitations
|
||||
@pagy, @invitations_used = pagy(Invitation.used.order('used_at desc'))
|
||||
@username = params[:username].presence
|
||||
accepted_scope = Invitation.used.order('used_at desc')
|
||||
unused_scope = Invitation.unused
|
||||
|
||||
if @username
|
||||
accepted_scope = accepted_scope.joins(:user).where(users: { cn: @username })
|
||||
unused_scope = unused_scope.joins(:user).where(users: { cn: @username })
|
||||
end
|
||||
|
||||
@pagy, @invitations_used = pagy(accepted_scope)
|
||||
|
||||
@stats = {
|
||||
available: Invitation.unused.count,
|
||||
accepted: @invitations_used.length,
|
||||
users_with_referrals: Invitation.used.distinct.count(:user_id)
|
||||
available: unused_scope.count,
|
||||
accepted: accepted_scope.count,
|
||||
users_with_referrals: accepted_scope.distinct.count(:user_id)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_current_section
|
||||
@current_section = :invitations
|
||||
end
|
||||
end
|
||||
|
11
app/views/admin/_username_search_form.html.erb
Normal file
11
app/views/admin/_username_search_form.html.erb
Normal file
@ -0,0 +1,11 @@
|
||||
<%= form_with url: path, method: :get, local: true, class: "flex gap-1" do %>
|
||||
<%= text_field_tag :username, @username, placeholder: 'Filter by username' %>
|
||||
<%= button_tag type: 'submit', name: nil, title: "Filter", class: 'btn-md btn-icon btn-outline' do %>
|
||||
<%= render partial: "icons/filter", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||
<% end %>
|
||||
<% if @username %>
|
||||
<%= link_to path, title: "Remove filter", class: 'btn-md btn-icon btn-outline' do %>
|
||||
<%= render partial: "icons/x", locals: { custom_class: "text-red-600 h-4 w-4 inline" } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
@ -19,17 +19,8 @@
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<%= form_with url: admin_donations_path, method: :get, local: true, class: "flex gap-1" do %>
|
||||
<%= text_field_tag :username, @username, placeholder: 'Filter by username' %>
|
||||
<%= button_tag type: 'submit', name: nil, title: "Filter", class: 'btn-md btn-icon btn-outline' do %>
|
||||
<%= render partial: "icons/filter", locals: { custom_class: "text-blue-600 h-4 w-4 inline" } %>
|
||||
<% end %>
|
||||
<% if @username %>
|
||||
<%= link_to admin_donations_path, title: "Remove filter", class: 'btn-md btn-icon btn-outline' do %>
|
||||
<%= render partial: "icons/x", locals: { custom_class: "text-red-600 h-4 w-4 inline" } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render partial: "admin/username_search_form",
|
||||
locals: { path: admin_donations_path } %>
|
||||
</section>
|
||||
|
||||
<% if @pending_donations.present? %>
|
||||
|
@ -21,6 +21,12 @@
|
||||
) %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<%= render partial: "admin/username_search_form",
|
||||
locals: { path: admin_invitations_path } %>
|
||||
</section>
|
||||
|
||||
<% if @invitations_used.any? %>
|
||||
<section>
|
||||
<h3>Accepted</h3>
|
||||
|
Loading…
x
Reference in New Issue
Block a user