Skip to content

Commit

Permalink
added admin page for rendering subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
kortirso committed Mar 9, 2024
1 parent e355de8 commit dd4019a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- notifications about long time review for pull requests
- admin page for rendering notifications
- admin page for rendering webhooks
- admin page for rendering subscribers

### Modified
- refactoring Api::Frontend endpoints
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/admin/subscribers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Admin
class SubscribersController < Admin::BaseController
include Pagy::Backend

PER_PAGE = 25

before_action :find_subscribers, only: %i[index]

def index; end

private

def find_subscribers
@pagy, @subscribers = pagy(Subscriber.order(id: :desc), items: PER_PAGE)
end
end
end
3 changes: 3 additions & 0 deletions app/views/components/page_wrappers/admin_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<div class="flex flex-row lg:flex-col flex-wrap lg:flex-nowrap">
<%= link_to 'Feedbacks', admin_feedbacks_path, class: 'user-navigation-link' %>
</div>
<div class="flex flex-row lg:flex-col flex-wrap lg:flex-nowrap">
<%= link_to 'Subscribers', admin_subscribers_path, class: 'user-navigation-link' %>
</div>
</div>
</div>
<div class="flex-1 w-full p-8 lg:p-12 overflow-y-scroll bg-stone-100">
Expand Down
19 changes: 19 additions & 0 deletions app/views/controllers/admin/subscribers/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<table class="table zebra w-full">
<thead>
<tr>
<th>ID</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<% @subscribers.each do |subscriber| %>
<tr>
<td><%= subscriber.id %></td>
<td><%= subscriber.email %></td>
</tr>
<% end %>
</tbody>
</table>
<% if @pagy.pages > 1 %>
<div class="mt-6"><%== pagy_nav(@pagy) %></div>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
resources :webhooks, only: %i[index]
resources :feedbacks, only: %i[index]
resources :users, only: %i[index]
resources :subscribers, only: %i[index]
end

namespace :api do
Expand Down
34 changes: 34 additions & 0 deletions spec/controllers/admin/subscribers_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

describe Admin::SubscribersController do
describe 'GET#index' do
it_behaves_like 'required auth'
it_behaves_like 'required admin auth'

context 'for logged admins' do
sign_in_admin

context 'without subscribers' do
it 'renders index page' do
do_request

expect(response).to render_template :index
end
end

context 'with subscribers' do
before { create :subscriber }

it 'renders index page' do
do_request

expect(response).to render_template :index
end
end
end

def do_request
get :index
end
end
end

0 comments on commit dd4019a

Please sign in to comment.