-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new users admin store credits page
- Loading branch information
1 parent
25a41bf
commit 9f24cce
Showing
7 changed files
with
237 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
admin/app/components/solidus_admin/users/store_credits/index/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<%= page do %> | ||
<%= page_header do %> | ||
<%= page_header_back(solidus_admin.users_path) %> | ||
<%= page_header_title(t(".title", email: @user.email)) %> | ||
<%= page_header_actions do %> | ||
<%= render component("ui/button").new(tag: :a, text: t(".add_store_credit"), href: spree.new_admin_user_store_credit_url(user_id: @user.id, only_path: true)) %> | ||
<% end %> | ||
<% end %> | ||
<%= page_header do %> | ||
<% tabs.each do |tab| %> | ||
<%= render(component("ui/button").new(tag: :a, scheme: :ghost, text: tab[:text], 'aria-current': tab[:current], href: tab[:href])) %> | ||
<% end %> | ||
<% end %> | ||
<%= page_with_sidebar do %> | ||
<%= page_with_sidebar_main do %> | ||
<% if @store_credits.present? %> | ||
<% @store_credits.group_by(&:currency).each do |currency, credits| %> | ||
<% title = [t('spree.admin.store_credits.current_balance'), Spree::Money.new(credits.sum(&:amount_remaining), currency: currency)].join(" ") %> | ||
<%= render component('ui/panel').new(title: title) do %> | ||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: model_class, | ||
rows: credits, | ||
fade: -> (_order) { false }, | ||
columns: columns, | ||
url: -> { row_url(_1) }, | ||
}, | ||
)%> | ||
<% end %> | ||
<% end %> | ||
<% else %> | ||
<%= render component('ui/panel').new(title: t(".store_credit")) do %> | ||
<%= t(".no_credits_found") %> | ||
<%= render component("ui/button").new(tag: :a, text: t(".create_one"), href: spree.new_admin_user_store_credit_url(user_id: @user.id, only_path: true)) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<%= page_with_sidebar_aside do %> | ||
<%= render component("users/stats").new(user: @user) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
106 changes: 106 additions & 0 deletions
106
admin/app/components/solidus_admin/users/store_credits/index/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Users::StoreCredits::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(user:, store_credits:) | ||
@user = user | ||
@store_credits = store_credits | ||
end | ||
|
||
def model_class | ||
Spree::StoreCredit | ||
end | ||
|
||
def tabs | ||
[ | ||
{ | ||
text: t('.account'), | ||
href: solidus_admin.user_path(@user), | ||
current: false, | ||
}, | ||
{ | ||
text: t('.addresses'), | ||
href: solidus_admin.addresses_user_path(@user), | ||
current: false, | ||
}, | ||
{ | ||
text: t('.order_history'), | ||
href: solidus_admin.orders_user_path(@user), | ||
current: false, | ||
}, | ||
{ | ||
text: t('.items'), | ||
href: spree.items_admin_user_path(@user), | ||
current: false, | ||
}, | ||
{ | ||
text: t('.store_credit'), | ||
href: solidus_admin.store_credits_user_path(@user), | ||
current: true, | ||
}, | ||
] | ||
end | ||
|
||
def rows | ||
@store_credits | ||
end | ||
|
||
def row_url(store_credit) | ||
spree.admin_user_store_credit_path(@user, store_credit) | ||
end | ||
|
||
def columns | ||
[ | ||
{ | ||
header: :credited, | ||
col: { class: "w-[12%]" }, | ||
data: ->(store_credit) do | ||
content_tag :div, store_credit.display_amount.to_html, class: "text-sm" | ||
end | ||
}, | ||
{ | ||
header: :authorized, | ||
col: { class: "w-[13%]" }, | ||
data: ->(store_credit) do | ||
content_tag :div, store_credit.display_amount_authorized.to_html, class: "text-sm" | ||
end | ||
}, | ||
{ | ||
header: :used, | ||
col: { class: "w-[9%]" }, | ||
data: ->(store_credit) do | ||
content_tag :div, store_credit.display_amount_used.to_html, class: "text-sm" | ||
end | ||
}, | ||
{ | ||
header: :type, | ||
col: { class: "w-[13%]" }, | ||
data: ->(store_credit) do | ||
component('ui/badge').new(name: store_credit.credit_type.name, color: :blue) | ||
end | ||
}, | ||
{ | ||
header: :created_by, | ||
col: { class: "w-[22%]" }, | ||
data: ->(store_credit) do | ||
content_tag :div, store_credit.created_by_email, class: "font-semibold text-sm" | ||
end | ||
}, | ||
{ | ||
header: :issued_on, | ||
col: { class: "w-[16%]" }, | ||
data: ->(store_credit) do | ||
I18n.l(store_credit.created_at.to_date) | ||
end | ||
}, | ||
{ | ||
header: :invalidated, | ||
col: { class: "w-[15%]" }, | ||
data: ->(store_credit) do | ||
store_credit.invalidated? ? component('ui/badge').yes : component('ui/badge').no | ||
end | ||
}, | ||
] | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
admin/app/components/solidus_admin/users/store_credits/index/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
en: | ||
title: "Users / %{email} / Store Credit" | ||
account: Account | ||
addresses: Addresses | ||
order_history: Order History | ||
items: Items | ||
store_credit: Store Credit | ||
last_active: Last Active | ||
add_store_credit: Add Store Credit | ||
no_credits_found: No Store Credits found. | ||
create_one: Create One | ||
back: Back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
put :update_addresses | ||
get :orders | ||
get :items | ||
get :store_credits | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,4 +252,57 @@ | |
end | ||
end | ||
end | ||
|
||
context "when viewing a user's store credits" do | ||
context "when a user has no store credits" do | ||
before do | ||
create(:user, email: "[email protected]") | ||
visit "/admin/users" | ||
find_row("[email protected]").click | ||
click_on "Store Credit" | ||
end | ||
|
||
it "shows the store credits page" do | ||
expect(page).to have_content("Users / [email protected] / Store Credit") | ||
expect(page).to have_content("Lifetime Stats") | ||
expect(page).to have_content("Store Credit") | ||
expect(page).to be_axe_clean | ||
end | ||
|
||
it "shows the appropriate content" do | ||
expect(page).to have_content("No Store Credits found.") | ||
end | ||
end | ||
|
||
context "when a user has store credits" do | ||
let!(:store_credit) { create(:store_credit, amount: 199.00, currency: "USD") } | ||
|
||
before do | ||
store_credit.user.update(email: "[email protected]") | ||
|
||
visit "/admin/users" | ||
find_row("[email protected]").click | ||
click_on "Store Credit" | ||
end | ||
|
||
it "shows the store credits page" do | ||
expect(page).to have_content("Users / [email protected] / Store Credit") | ||
expect(page).to have_content("Lifetime Stats") | ||
expect(page).to have_content("Store Credit") | ||
expect(page).to be_axe_clean | ||
end | ||
|
||
it "lists the user's store credit" do | ||
expect(page).to have_content("Current balance: $199.00") | ||
expect(page).to have_content("Credited") | ||
expect(page).to have_content("Authorized") | ||
expect(page).to have_content("Used") | ||
expect(page).to have_content("Type") | ||
expect(page).to have_content("Created by") | ||
expect(page).to have_content("Issued on") | ||
expect(page).to have_content("Invalidated") | ||
expect(page).not_to have_content("No Store Credits found.") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters