-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Admin] Add new users admin store credits page #5887
Merged
MadelineCollier
merged 1 commit into
solidusio:main
from
MadelineCollier:admin-user-store-credit-page
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be extracted into a UserTabs module, so we do not have to add it to every user index component, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that early on, but had some issues when using a dynamic value for
current
(eg:current: action_name == "edit"
. It would work on initial load but then would sometimes be a bit strange/incorrect in its display during certain flows/partial page reload. Once I have the rest of the store credits stuff out of the way I'd be happy to take another crack at it though!