Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MadelineCollier committed Oct 18, 2024
1 parent 41cb5d3 commit 50946f6
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 1 deletion.
124 changes: 124 additions & 0 deletions admin/app/components/solidus_admin/users/store_credits/component.rb
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
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 %>
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
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
10 changes: 9 additions & 1 deletion admin/app/controllers/solidus_admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UsersController < SolidusAdmin::BaseController
include SolidusAdmin::ControllerHelpers::Search
include Spree::Core::ControllerHelpers::StrongParameters

before_action :set_user, only: [:edit, :addresses, :update_addresses, :orders, :items]
before_action :set_user, only: [:edit, :addresses, :update_addresses, :orders, :items, :store_credits]

search_scope(:all, default: true)
search_scope(:customers) { _1.left_outer_joins(:role_users).where(role_users: { id: nil }) }
Expand Down Expand Up @@ -81,6 +81,14 @@ def destroy
redirect_back_or_to users_path, status: :see_other
end

def store_credits
set_page_and_extract_portion_from(Spree::StoreCredit.where(user_id: @user.id).order(id: :desc))

respond_to do |format|
format.html { render component('users/store_credits').new(page: @page) }
end
end

private

def set_user
Expand Down
1 change: 1 addition & 0 deletions admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
put :update_addresses
get :orders
get :items
get :store_credits
end
end

Expand Down

0 comments on commit 50946f6

Please sign in to comment.