-
-
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.
- Loading branch information
1 parent
41cb5d3
commit 50946f6
Showing
6 changed files
with
319 additions
and
1 deletion.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
admin/app/components/solidus_admin/users/store_credits/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,124 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Users::StoreCredits::Component < SolidusAdmin::UI::Pages::Index::Component | ||
include SolidusAdmin::LastLoginHelper | ||
|
||
def model_class | ||
binding.pry | ||
Spree::StoreCredit | ||
end | ||
|
||
def page_header | ||
page_header_back(solidus_admin.users_path) | ||
end | ||
|
||
# | ||
# def page_header_back | ||
# solidus_admin.users_path | ||
# end | ||
|
||
# def page_header_title | ||
# t(".title", email: @user.email) | ||
# end | ||
|
||
|
||
# | ||
# <%= 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(".create_order_for_user"), href: spree.new_admin_order_path(user_id: @user.id)) %> | ||
# <% end %> | ||
# <% end %> | ||
# | ||
# def search_url | ||
# solidus_admin.store_credits_path | ||
# end | ||
|
||
# def search_key | ||
# :name_or_code_cont | ||
# end | ||
|
||
# def page_actions | ||
# render component("ui/button").new( | ||
# tag: :a, | ||
# text: t('.add'), | ||
# href: solidus_admin.user_path(@user), data: { turbo_frame: :new_store_credit_modal }, | ||
# icon: "add-line", | ||
# class: "align-self-end w-full", | ||
# ) | ||
# end | ||
|
||
def turbo_frames | ||
%w[ | ||
new_store_credit_modal | ||
edit_store_credit_modal | ||
] | ||
end | ||
|
||
def row_url(store_credit) | ||
# solidus_admin.user_path(@user) | ||
"/" | ||
# spree.edit_admin_store_credit_path(store_credit, _turbo_frame: :edit_store_credit_modal) | ||
end | ||
|
||
# def batch_actions | ||
# [ | ||
# { | ||
# label: t('.batch_actions.invalidate'), | ||
# action: spree.invalidate_admin_user_store_credit(user_id: @user, id: 1), | ||
# method: :put, | ||
# icon: 'delete-bin-7-line', | ||
# require_confirmation: true, | ||
# }, | ||
# ] | ||
# end | ||
|
||
def columns | ||
[ | ||
{ | ||
header: :credited, | ||
data: ->(store_credit) do | ||
store_credit.display_amount.to_html | ||
end | ||
}, | ||
{ | ||
header: :used, | ||
data: ->(store_credit) do | ||
store_credit.display_amount_used.to_html | ||
end | ||
}, | ||
{ | ||
header: :authorized, | ||
data: ->(store_credit) do | ||
store_credit.display_amount_authorized.to_html | ||
end | ||
}, | ||
{ | ||
header: :type, | ||
data: ->(store_credit) do | ||
component('ui/badge').new(name: store_credit.credit_type.name, color: :blue) | ||
end | ||
}, | ||
{ | ||
header: :created_by, | ||
data: ->(store_credit) do | ||
store_credit.created_by_email | ||
end | ||
}, | ||
{ | ||
header: :issued_on, | ||
data: ->(store_credit) do | ||
I18n.l(store_credit.created_at.to_date) | ||
end | ||
}, | ||
{ | ||
header: :invalidated, | ||
data: ->(store_credit) do | ||
store_credit.invalidated? ? component('ui/badge').yes : component('ui/badge').no | ||
end | ||
}, | ||
] | ||
end | ||
end |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
<%= 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(".create_order_for_user"), href: spree.new_admin_order_path(user_id: @user.id)) %> | ||
<% 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 %> | ||
<%= render component('ui/panel').new(title: t(".order_history")) do %> | ||
<% if @orders.present? %> | ||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: model_class, | ||
rows: rows, | ||
fade: -> { row_fade(_1) }, | ||
columns: columns, | ||
url: -> { row_url(_1) }, | ||
}, | ||
)%> | ||
<% else %> | ||
<%= t(".no_orders_found") %> | ||
<%= render component("ui/button").new(tag: :a, text: t(".create_one"), href: spree.new_admin_order_path(user_id: @user.id)) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<%= page_with_sidebar_aside do %> | ||
<%= render component("users/stats").new(user: @user) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
131 changes: 131 additions & 0 deletions
131
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,131 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Users::StoreCredits::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(user:, orders:) | ||
@user = user | ||
@orders = orders | ||
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: true, | ||
}, | ||
{ | ||
text: t('.items'), | ||
href: spree.items_admin_user_path(@user), | ||
current: false, | ||
}, | ||
{ | ||
text: t('.store_credit'), | ||
href: spree.admin_user_store_credits_path(@user), | ||
current: false, | ||
}, | ||
] | ||
end | ||
|
||
def model_class | ||
Spree::Order | ||
end | ||
|
||
def row_url(order) | ||
spree.edit_admin_order_path(order) | ||
end | ||
|
||
def rows | ||
@orders | ||
end | ||
|
||
def row_fade(_order) | ||
false | ||
end | ||
|
||
def columns | ||
[ | ||
number_column, | ||
state_column, | ||
date_column, | ||
payment_column, | ||
shipment_column, | ||
total_column, | ||
] | ||
end | ||
|
||
def number_column | ||
{ | ||
header: :order, | ||
data: ->(order) do | ||
if !row_fade(order) | ||
content_tag :div, order.number, class: 'font-semibold' | ||
else | ||
content_tag :div, order.number | ||
end | ||
end | ||
} | ||
end | ||
|
||
def state_column | ||
{ | ||
header: :state, | ||
data: ->(order) do | ||
color = { | ||
'complete' => :green, | ||
'returned' => :red, | ||
'canceled' => :blue, | ||
'cart' => :graphite_light, | ||
}[order.state] || :yellow | ||
component('ui/badge').new(name: order.state.humanize, color: color) | ||
end | ||
} | ||
end | ||
|
||
def date_column | ||
{ | ||
header: :date, | ||
data: ->(order) do | ||
content_tag :div, l(order.created_at, format: :short) | ||
end | ||
} | ||
end | ||
|
||
def total_column | ||
{ | ||
header: :total, | ||
data: ->(order) do | ||
content_tag :div, number_to_currency(order.total) | ||
end | ||
} | ||
end | ||
|
||
def payment_column | ||
{ | ||
header: :payment, | ||
data: ->(order) do | ||
component('ui/badge').new(name: order.payment_state.humanize, color: order.paid? ? :green : :yellow) if order.payment_state? | ||
end | ||
} | ||
end | ||
|
||
def shipment_column | ||
{ | ||
header: :shipment, | ||
data: ->(order) do | ||
component('ui/badge').new(name: order.shipment_state.humanize, color: order.shipped? ? :green : :yellow) if order.shipment_state? | ||
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} / Order History" | ||
account: Account | ||
addresses: Addresses | ||
order_history: Order History | ||
items: Items | ||
store_credit: Store Credit | ||
last_active: Last Active | ||
create_order_for_user: Create order for this user | ||
no_orders_found: No Orders 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 | ||
|
||
|