From f49525b8b84692a3b62e50cf07ee824f8196e44e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 8 Nov 2023 18:21:58 +0100 Subject: [PATCH 01/12] Allow detaching a customer from an order --- .../orders/show/component.html.erb | 4 ++-- .../solidus_admin/customers_controller.rb | 12 +++++++++- admin/config/locales/customers.en.yml | 7 ++++++ admin/spec/features/order_spec.rb | 22 ++++++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 admin/config/locales/customers.en.yml diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index 9d677251898..9a4c7b2bb2c 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -18,8 +18,8 @@ link_to(t(".edit_email"), solidus_admin.order_customer_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), link_to(t(".edit_shipping"), solidus_admin.new_order_ship_address_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), link_to(t(".edit_billing"), solidus_admin.new_order_bill_address_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), - link_to(t(".remove_customer"), solidus_admin.order_customer_path(@order), 'data-turbo-method': :delete, class: "p-2 hover:bg-gray-25 rounded-sm text-red-500"), - ])) do %> + @order.user && button_to(t(".remove_customer"), solidus_admin.order_customer_path(@order), method: :delete, class: "p-2 hover:bg-gray-25 rounded-sm text-red-500"), + ].compact)) do %>
<%# CUSTOMER %> <% if @order.user %> diff --git a/admin/app/controllers/solidus_admin/customers_controller.rb b/admin/app/controllers/solidus_admin/customers_controller.rb index 9b7fbd5af09..07e34cd95b1 100644 --- a/admin/app/controllers/solidus_admin/customers_controller.rb +++ b/admin/app/controllers/solidus_admin/customers_controller.rb @@ -1,12 +1,22 @@ # frozen_string_literal: true class SolidusAdmin::CustomersController < SolidusAdmin::BaseController - before_action :load_order, only: :show + before_action :load_order, only: [:show, :destroy] def show render component('orders/show/email').new(order: @order) end + def destroy + if @order.update(user: nil) + flash[:success] = t('.success') + else + flash[:error] = t('.error') + end + + redirect_to order_path(@order), status: :see_other + end + private def load_order diff --git a/admin/config/locales/customers.en.yml b/admin/config/locales/customers.en.yml new file mode 100644 index 00000000000..a3ac8df8832 --- /dev/null +++ b/admin/config/locales/customers.en.yml @@ -0,0 +1,7 @@ +en: + solidus_admin: + customers: + title: "Customers" + destroy: + success: "Customer was removed successfully" + error: "Customer could not be removed" diff --git a/admin/spec/features/order_spec.rb b/admin/spec/features/order_spec.rb index c4243fa3e07..3f946b5d502 100644 --- a/admin/spec/features/order_spec.rb +++ b/admin/spec/features/order_spec.rb @@ -5,13 +5,27 @@ describe "Order", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } + it "allows detaching a customer from an order" do + order = create(:order, number: "R123456789", user: create(:user)) + + visit "/admin/orders/R123456789" + + open_customer_menu + click_on "Remove customer" + + expect(page).to have_content("Customer was removed successfully") + open_customer_menu + expect(page).not_to have_content("Remove customer") + expect(order.reload.user).to be_nil + end + it "allows changing the order email" do create(:order, number: "R123456789", total: 19.99) visit "/admin/orders/R123456789/edit" expect(page).to have_content("Order R123456789") - find("summary", text: "Customer").click + open_customer_menu click_on "Edit order email" within("dialog") do fill_in "Customer Email", with: "a@b.c" @@ -58,4 +72,10 @@ expect(page).to be_axe_clean end end + + private + + def open_customer_menu + find("summary", text: "Customer").click + end end From dcfde2a85adb260221232f761990de10ee835187 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 8 Nov 2023 18:22:59 +0100 Subject: [PATCH 02/12] Don't show billing and shipping sections if the addresses are not set --- .../orders/show/component.html.erb | 28 ++++++++----------- .../solidus_admin/orders/show/component.yml | 2 -- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index 9a4c7b2bb2c..bc9bd1cf341 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -39,32 +39,28 @@ <% end %> <%# SHIPPING %> -
- <%= @order.class.human_attribute_name(:ship_address) %> -
- <% if @order.ship_address %> + <% if @order.ship_address %> +
+ <%= @order.class.human_attribute_name(:ship_address) %> +
<%= format_address @order.ship_address %> - <% else %> - <%= t('.no_shipping_address') %> - <% end %> +
-
+ <% end %> <%# BILLING %> -
- <%= @order.class.human_attribute_name(:bill_address) %> -
- <% if @order.bill_address %> + <% if @order.bill_address %> +
+ <%= @order.class.human_attribute_name(:bill_address) %> +
<% if @order.bill_address == @order.ship_address %> <%= t('.same_as_shipping') %> <% else %> <%= format_address @order.bill_address %> <% end %> - <% else %> - <%= t('.no_billing_address') %> - <% end %> +
-
+ <% end %>
diff --git a/admin/app/components/solidus_admin/orders/show/component.yml b/admin/app/components/solidus_admin/orders/show/component.yml index 55755957b02..3f6e0461751 100644 --- a/admin/app/components/solidus_admin/orders/show/component.yml +++ b/admin/app/components/solidus_admin/orders/show/component.yml @@ -7,8 +7,6 @@ en: customer: Customer no_name: No name available order_email: Order contact email - no_billing_address: No billing address - no_shipping_address: No shipping address same_as_shipping: Same as shipping address edit_email: "Edit order email" From ac8d8e701419c92e8159641047ab110e77d71508 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 8 Nov 2023 18:42:22 +0100 Subject: [PATCH 03/12] Split the panel from the search component The search component becomes more adaptable this way and can be placed in more ways within or without a panel. The panel component gained an `actions` slot and updated paddings, removing the need for the previously used negative margins. --- .../orders/cart/component.html.erb | 145 +++++++++--------- .../orders/cart/result/component.html.erb | 2 +- .../orders/show/component.html.erb | 7 +- .../ui/forms/search/component.html.erb | 51 ++++++ .../search}/component.js | 0 .../ui/forms/search/component.rb | 8 + .../search}/component.yml | 0 .../ui/forms/search/result/component.rb | 12 ++ .../solidus_admin/ui/panel/component.html.erb | 14 +- .../solidus_admin/ui/panel/component.rb | 9 ++ .../ui/search_panel/component.html.erb | 58 ------- .../ui/search_panel/component.rb | 9 -- .../ui/search_panel/result/component.rb | 12 -- .../search}/component_preview.rb | 4 +- .../component_preview/overview.html.erb | 2 +- .../search}/component_spec.rb | 2 +- admin/spec/features/order_spec.rb | 2 +- 17 files changed, 173 insertions(+), 164 deletions(-) create mode 100644 admin/app/components/solidus_admin/ui/forms/search/component.html.erb rename admin/app/components/solidus_admin/ui/{search_panel => forms/search}/component.js (100%) create mode 100644 admin/app/components/solidus_admin/ui/forms/search/component.rb rename admin/app/components/solidus_admin/ui/{search_panel => forms/search}/component.yml (100%) create mode 100644 admin/app/components/solidus_admin/ui/forms/search/result/component.rb delete mode 100644 admin/app/components/solidus_admin/ui/search_panel/component.html.erb delete mode 100644 admin/app/components/solidus_admin/ui/search_panel/component.rb delete mode 100644 admin/app/components/solidus_admin/ui/search_panel/result/component.rb rename admin/spec/components/previews/solidus_admin/ui/{search_panel => forms/search}/component_preview.rb (50%) rename admin/spec/components/previews/solidus_admin/ui/{search_panel => forms/search}/component_preview/overview.html.erb (87%) rename admin/spec/components/solidus_admin/ui/{search_panel => forms/search}/component_spec.rb (62%) diff --git a/admin/app/components/solidus_admin/orders/cart/component.html.erb b/admin/app/components/solidus_admin/orders/cart/component.html.erb index d77b2a63a2f..2bd82d5ed42 100644 --- a/admin/app/components/solidus_admin/orders/cart/component.html.erb +++ b/admin/app/components/solidus_admin/orders/cart/component.html.erb @@ -3,77 +3,84 @@ data-controller="<%= stimulus_id %>" data-<%= stimulus_id %>-products-url-value="<%= solidus_admin.variants_for_order_path(@order) %>" data-action=" - <%= component('ui/search_panel').stimulus_id %>:search-><%= stimulus_id %>#search - <%= component('ui/search_panel').stimulus_id %>:submit-><%= stimulus_id %>#selectResult + <%= component('ui/forms/search').stimulus_id %>:search-><%= stimulus_id %>#search + <%= component('ui/forms/search').stimulus_id %>:submit-><%= stimulus_id %>#selectResult " > - <%= render component('ui/search_panel').new( - title: t('.title'), - search_placeholder: t('.search_placeholder'), - id: :order_cart, - ) do |panel| %> - > - - - - - - - - - - <% @order.line_items.each do |line_item| %> - - + + + + + <% end %> + +
ProductQuantityPriceActions
-
- <% variant = line_item.variant %> - <%= render component("ui/thumbnail").new( - src: (variant.images.first || variant.product.gallery.images.first)&.url(:small), - alt: variant.name - ) %> -
-
<%= variant.name %>
-
- SKU: <%= variant.sku %> - <%= variant.options_text.presence&.prepend("- ") %> + <%= render component('ui/panel').new(title: t('.title')) do |panel| %> + <% panel.with_section do %> + <%= render component('ui/forms/search').new( + placeholder: t('.search_placeholder'), + id: :order_cart, + ) %> + <% end %> + + <% panel.with_section(wide: true, high: true) do %> +
+ > + + + + + + + + + + <% @order.line_items.each do |line_item| %> + + - - - - - <% end %> - -
ProductQuantityPriceActions
+
+ <% variant = line_item.variant %> + <%= render component("ui/thumbnail").new( + src: (variant.images.first || variant.product.gallery.images.first)&.url(:small), + alt: variant.name + ) %> +
+
<%= variant.name %>
+
+ SKU: <%= variant.sku %> + <%= variant.options_text.presence&.prepend("- ") %> +
+
- - -
- <%= form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), html: { - "data-controller": "readonly-when-submitting" - }) do |f| %> - <%= render component("ui/forms/input").new( - name: "#{f.object_name}[quantity]", - type: :number, - value: line_item.quantity, - "aria-label": "Quantity", - min: 0, - class: "!w-16 inline-block", - "data-action": "input->#{stimulus_id}#updateLineItem", - ) %> - <% render component("ui/button").new(type: :submit, text: "Update", class: "inline-block") %> - <% end %> - - <%= line_item.single_money.to_html %> - - <%= form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), method: :delete) do |f| %> - <%= render component('ui/button').new( - scheme: :ghost, - size: :s, - title: t("spree.delete"), - icon: 'close-line', - "data-controller": "confirm", - "data-confirm-text-value": t("spree.are_you_sure"), - ) %> - <% end %> -
+
+ <%= form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), html: { + "data-controller": "readonly-when-submitting" + }) do |f| %> + <%= render component("ui/forms/input").new( + name: "#{f.object_name}[quantity]", + type: :number, + value: line_item.quantity, + "aria-label": "Quantity", + min: 0, + class: "!w-16 inline-block", + "data-action": "input->#{stimulus_id}#updateLineItem", + ) %> + <% render component("ui/button").new(type: :submit, text: "Update", class: "inline-block") %> + <% end %> + + <%= line_item.single_money.to_html %> + + <%= form_for(line_item, url: solidus_admin.order_line_item_path(@order, line_item), method: :delete) do |f| %> + <%= render component('ui/button').new( + scheme: :ghost, + size: :s, + title: t("spree.delete"), + icon: 'close-line', + "data-controller": "confirm", + "data-confirm-text-value": t("spree.are_you_sure"), + ) %> + <% end %> +
+
+ <% end %> <% end %>
diff --git a/admin/app/components/solidus_admin/orders/cart/result/component.html.erb b/admin/app/components/solidus_admin/orders/cart/result/component.html.erb index 7ef48986da5..ab39d30af92 100644 --- a/admin/app/components/solidus_admin/orders/cart/result/component.html.erb +++ b/admin/app/components/solidus_admin/orders/cart/result/component.html.erb @@ -1,4 +1,4 @@ -<%= render component('ui/search_panel/result').new do %> +<%= render component('ui/forms/search/result').new do %> <%= form_for(@order.line_items.build(variant: @variant), url: solidus_admin.order_line_items_path(@order), method: :post, html: { "data-controller": "readonly-when-submitting", class: "flex items-center", diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index bc9bd1cf341..f1efeba74c6 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -19,8 +19,8 @@ link_to(t(".edit_shipping"), solidus_admin.new_order_ship_address_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), link_to(t(".edit_billing"), solidus_admin.new_order_bill_address_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), @order.user && button_to(t(".remove_customer"), solidus_admin.order_customer_path(@order), method: :delete, class: "p-2 hover:bg-gray-25 rounded-sm text-red-500"), - ].compact)) do %> -
+ ].compact)) do |panel| %> + <% panel.with_section(class: 'flex flex-col gap-6') do %> <%# CUSTOMER %> <% if @order.user %>
@@ -62,8 +62,7 @@
<% end %> -
- + <% end %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/ui/forms/search/component.html.erb b/admin/app/components/solidus_admin/ui/forms/search/component.html.erb new file mode 100644 index 00000000000..119176457b9 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/forms/search/component.html.erb @@ -0,0 +1,51 @@ +
-loading-text-value="<%= t('.loading') %>" + data-<%= stimulus_id %>-initial-text-value="<%= t('.initial') %>" + data-<%= stimulus_id %>-empty-text-value="<%= t('.empty') %>" +> +
+
+ <%= render component("ui/forms/search_field").new( + id: "#{stimulus_id}--search-field--#{@id}", + "data-action": " + #{stimulus_id}#search + #{stimulus_id}#showResults + ", + "data-#{stimulus_id}-target": "searchField", + **@attributes, + ) %> +
+ +
+ +
-target="results" + > +
+
+
+
diff --git a/admin/app/components/solidus_admin/ui/search_panel/component.js b/admin/app/components/solidus_admin/ui/forms/search/component.js similarity index 100% rename from admin/app/components/solidus_admin/ui/search_panel/component.js rename to admin/app/components/solidus_admin/ui/forms/search/component.js diff --git a/admin/app/components/solidus_admin/ui/forms/search/component.rb b/admin/app/components/solidus_admin/ui/forms/search/component.rb new file mode 100644 index 00000000000..808d80b487c --- /dev/null +++ b/admin/app/components/solidus_admin/ui/forms/search/component.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class SolidusAdmin::UI::Forms::Search::Component < SolidusAdmin::BaseComponent + def initialize(id: nil, **attributes) + @id = id + @attributes = attributes + end +end diff --git a/admin/app/components/solidus_admin/ui/search_panel/component.yml b/admin/app/components/solidus_admin/ui/forms/search/component.yml similarity index 100% rename from admin/app/components/solidus_admin/ui/search_panel/component.yml rename to admin/app/components/solidus_admin/ui/forms/search/component.yml diff --git a/admin/app/components/solidus_admin/ui/forms/search/result/component.rb b/admin/app/components/solidus_admin/ui/forms/search/result/component.rb new file mode 100644 index 00000000000..08add6e78dd --- /dev/null +++ b/admin/app/components/solidus_admin/ui/forms/search/result/component.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class SolidusAdmin::UI::Forms::Search::Result::Component < SolidusAdmin::BaseComponent + def call + tag.div( + content, + class: "rounded p-2 hover:bg-gray-25 aria-selected:bg-gray-25 cursor-pointer", + "data-#{component('ui/forms/search').stimulus_id}-target": "result", + "data-action": "click->#{component('ui/forms/search').stimulus_id}#clickedResult", + ) + end +end diff --git a/admin/app/components/solidus_admin/ui/panel/component.html.erb b/admin/app/components/solidus_admin/ui/panel/component.html.erb index e59221adf6c..1dfc039d579 100644 --- a/admin/app/components/solidus_admin/ui/panel/component.html.erb +++ b/admin/app/components/solidus_admin/ui/panel/component.html.erb @@ -8,28 +8,30 @@ flex-col justify-start items-start - gap-6 inline-flex w-full - py-6 " data-controller="<%= stimulus_id %>" > <% if @title %> -

+

<%= @title %> <%= render component('ui/toggletip').new(text: @title_hint) if @title_hint %>

<% end %> - <% if content&.present? %> -
+ <% sections.each do |section| %> + <%= section %> + <% end %> + + <% if content.present? %> +
<%= content %>
<% end %> <% if action? %> -
+
<%= action %>
<% end %> diff --git a/admin/app/components/solidus_admin/ui/panel/component.rb b/admin/app/components/solidus_admin/ui/panel/component.rb index ea009198589..74073f210c9 100644 --- a/admin/app/components/solidus_admin/ui/panel/component.rb +++ b/admin/app/components/solidus_admin/ui/panel/component.rb @@ -10,6 +10,15 @@ class SolidusAdmin::UI::Panel::Component < SolidusAdmin::BaseComponent ) } + renders_many :sections, ->(wide: false, high: false, **args, &block) do + tag.section(**args, class: " + border-gray-100 border-t w-full + #{'px-6' unless wide} + #{'py-6' unless high} + #{args[:class]} + ", &block) + end + # @param title [String] the title of the panel # @param title_hint [String] the title hint of the panel def initialize(title: nil, title_hint: nil) diff --git a/admin/app/components/solidus_admin/ui/search_panel/component.html.erb b/admin/app/components/solidus_admin/ui/search_panel/component.html.erb deleted file mode 100644 index bb4403ca1ab..00000000000 --- a/admin/app/components/solidus_admin/ui/search_panel/component.html.erb +++ /dev/null @@ -1,58 +0,0 @@ -
-loading-text-value="<%= t('.loading') %>" - data-<%= stimulus_id %>-initial-text-value="<%= t('.initial') %>" - data-<%= stimulus_id %>-empty-text-value="<%= t('.empty') %>" -> - <%= render component('ui/panel').new(**@panel_args) do |panel| %> -
-
-
- <%= render component("ui/forms/search_field").new( - id: "#{stimulus_id}--search-field--#{@id}", - placeholder: @search_placeholder, - "data-action": " - #{stimulus_id}#search - #{stimulus_id}#showResults - ", - "data-#{stimulus_id}-target": "searchField", - ) %> -
- -
- -
-target="results" - > -
-
-
- -
- <%= content %> -
- <% end %> -
diff --git a/admin/app/components/solidus_admin/ui/search_panel/component.rb b/admin/app/components/solidus_admin/ui/search_panel/component.rb deleted file mode 100644 index b8f32ac5382..00000000000 --- a/admin/app/components/solidus_admin/ui/search_panel/component.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::SearchPanel::Component < SolidusAdmin::BaseComponent - def initialize(search_placeholder: nil, id: nil, **panel_args) - @search_placeholder = search_placeholder - @panel_args = panel_args - @id = id - end -end diff --git a/admin/app/components/solidus_admin/ui/search_panel/result/component.rb b/admin/app/components/solidus_admin/ui/search_panel/result/component.rb deleted file mode 100644 index 520bbbce5ed..00000000000 --- a/admin/app/components/solidus_admin/ui/search_panel/result/component.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class SolidusAdmin::UI::SearchPanel::Result::Component < SolidusAdmin::BaseComponent - def call - tag.div( - content, - class: "rounded p-2 hover:bg-gray-25 aria-selected:bg-gray-25 cursor-pointer", - "data-#{component('ui/search_panel').stimulus_id}-target": "result", - "data-action": "click->#{component('ui/search_panel').stimulus_id}#clickedResult", - ) - end -end diff --git a/admin/spec/components/previews/solidus_admin/ui/search_panel/component_preview.rb b/admin/spec/components/previews/solidus_admin/ui/forms/search/component_preview.rb similarity index 50% rename from admin/spec/components/previews/solidus_admin/ui/search_panel/component_preview.rb rename to admin/spec/components/previews/solidus_admin/ui/forms/search/component_preview.rb index cc3ab94a5dc..cf9aa0f02c4 100644 --- a/admin/spec/components/previews/solidus_admin/ui/search_panel/component_preview.rb +++ b/admin/spec/components/previews/solidus_admin/ui/forms/search/component_preview.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -# @component "ui/search_panel" -class SolidusAdmin::UI::SearchPanel::ComponentPreview < ViewComponent::Preview +# @component "ui/forms/search" +class SolidusAdmin::UI::Forms::Search::ComponentPreview < ViewComponent::Preview include SolidusAdmin::Preview def overview diff --git a/admin/spec/components/previews/solidus_admin/ui/search_panel/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/forms/search/component_preview/overview.html.erb similarity index 87% rename from admin/spec/components/previews/solidus_admin/ui/search_panel/component_preview/overview.html.erb rename to admin/spec/components/previews/solidus_admin/ui/forms/search/component_preview/overview.html.erb index 6699a39eaef..15ad99adbbb 100644 --- a/admin/spec/components/previews/solidus_admin/ui/search_panel/component_preview/overview.html.erb +++ b/admin/spec/components/previews/solidus_admin/ui/forms/search/component_preview/overview.html.erb @@ -9,7 +9,7 @@ }) window.addEventListener('<%= current_component.stimulus_id %>:search', (event) => { const {controller, query} = event.detail - const resultTemplate = `<%= render component('ui/search_panel/result').new.with_content("{{content}}") %>` + const resultTemplate = `<%= render component('ui/forms/search/result').new.with_content("{{content}}") %>` setTimeout(() => { controller.resultsValue = [ resultTemplate.replace('{{content}}', `Result 1 for ${query}`), diff --git a/admin/spec/components/solidus_admin/ui/search_panel/component_spec.rb b/admin/spec/components/solidus_admin/ui/forms/search/component_spec.rb similarity index 62% rename from admin/spec/components/solidus_admin/ui/search_panel/component_spec.rb rename to admin/spec/components/solidus_admin/ui/forms/search/component_spec.rb index 15209522472..e87a17f6290 100644 --- a/admin/spec/components/solidus_admin/ui/search_panel/component_spec.rb +++ b/admin/spec/components/solidus_admin/ui/forms/search/component_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe SolidusAdmin::UI::SearchPanel::Component, type: :component do +RSpec.describe SolidusAdmin::UI::Forms::Search::Component, type: :component do it "renders the overview preview" do render_preview(:overview) end diff --git a/admin/spec/features/order_spec.rb b/admin/spec/features/order_spec.rb index 3f946b5d502..1a23d85d2d1 100644 --- a/admin/spec/features/order_spec.rb +++ b/admin/spec/features/order_spec.rb @@ -46,7 +46,7 @@ expect(page).to have_content("Order R123456789") - search_field = find("[data-#{SolidusAdmin::UI::SearchPanel::Component.stimulus_id}-target='searchField']") + search_field = find("[data-#{SolidusAdmin::UI::Forms::Search::Component.stimulus_id}-target='searchField']") search_field.set "another" expect(page).not_to have_content("Just a product") From 3e5cf0561277f86925349bd517ea9f34c9ace4c7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 9 Nov 2023 17:38:13 +0100 Subject: [PATCH 04/12] Use a 22px high icon for the customer sidebar menu The button that we used initially was to high. --- .../app/components/solidus_admin/orders/show/component.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/admin/app/components/solidus_admin/orders/show/component.rb b/admin/app/components/solidus_admin/orders/show/component.rb index 36a672d06a0..88520ef1407 100644 --- a/admin/app/components/solidus_admin/orders/show/component.rb +++ b/admin/app/components/solidus_admin/orders/show/component.rb @@ -35,12 +35,10 @@ def panel_title_with_more_links(title, links) tag.span( safe_join([ title, - component("ui/button").new( - icon: "more-line", - scheme: :ghost, - tag: :span, + component("ui/icon").new( + name: "more-line", alt: t("spree.edit"), - class: "cursor-pointer" + class: "cursor-pointer w-[22px] h-[22px]" ).render_in(self), ]), class: 'flex items-center justify-between text-black', From e65924b74091131ebde165554b235b60dc6c8819 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 9 Nov 2023 17:40:03 +0100 Subject: [PATCH 05/12] Add a missing translation for /admin/orders#update --- admin/config/locales/orders.en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/admin/config/locales/orders.en.yml b/admin/config/locales/orders.en.yml index 798fb7ea183..f27376c9ab5 100644 --- a/admin/config/locales/orders.en.yml +++ b/admin/config/locales/orders.en.yml @@ -4,6 +4,7 @@ en: title: "Orders" update: success: "Order was updated successfully" + error: "Order could not be updated" addresses: title: "Addresses" update: From 4b6951170cfb6a387fa9ce2f844772a3443f746b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 9 Nov 2023 17:53:00 +0100 Subject: [PATCH 06/12] Fix search result spacing --- .../components/solidus_admin/ui/forms/search/component.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/admin/app/components/solidus_admin/ui/forms/search/component.html.erb b/admin/app/components/solidus_admin/ui/forms/search/component.html.erb index 119176457b9..cb1ab64e292 100644 --- a/admin/app/components/solidus_admin/ui/forms/search/component.html.erb +++ b/admin/app/components/solidus_admin/ui/forms/search/component.html.erb @@ -38,6 +38,7 @@ border border-gray-100 p-2 + flex flex-col gap-1 max-h-screen From 48db75359eb17a415b8af8c5022a375c4973be00 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 10 Nov 2023 15:07:25 +0100 Subject: [PATCH 07/12] Fix information about being a guest order --- .../solidus_admin/orders/show/email/component.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/app/components/solidus_admin/orders/show/email/component.html.erb b/admin/app/components/solidus_admin/orders/show/email/component.html.erb index 5ade14b6bc4..9bdff03edc0 100644 --- a/admin/app/components/solidus_admin/orders/show/email/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/email/component.html.erb @@ -5,7 +5,7 @@ <%= render component("ui/forms/field").text_field(f, :email) %> <% end %> From 5bbcc05898c56ed6f43629bebc6370ff437b80db Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 10 Nov 2023 18:19:24 +0100 Subject: [PATCH 08/12] Don't let modal go over the screen height Also make the header and footer sticky. --- .../components/solidus_admin/ui/modal/component.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/modal/component.html.erb b/admin/app/components/solidus_admin/ui/modal/component.html.erb index ec23a4cfb35..c9ce14bbf80 100644 --- a/admin/app/components/solidus_admin/ui/modal/component.html.erb +++ b/admin/app/components/solidus_admin/ui/modal/component.html.erb @@ -8,9 +8,9 @@ >
-
+
-
+

<%= @title %>

@@ -28,7 +28,7 @@
<% if actions? %> -
+
<%= actions %>
<% end %> From 9762fde65c30c55e30679613cf6b2c3cb8c5c66b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 10 Nov 2023 18:29:18 +0100 Subject: [PATCH 09/12] Move the panel menu inside the `ui/panel` component --- .../orders/show/component.html.erb | 12 ++-- .../solidus_admin/orders/show/component.rb | 19 ------- .../solidus_admin/ui/panel/component.html.erb | 56 ++++++++++++++++--- .../solidus_admin/ui/panel/component.rb | 10 +++- .../solidus_admin/ui/panel/component.yml | 2 + .../panel/component_preview/overview.html.erb | 27 +++++++++ admin/spec/features/order_spec.rb | 4 +- 7 files changed, 94 insertions(+), 36 deletions(-) create mode 100644 admin/app/components/solidus_admin/ui/panel/component.yml diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index f1efeba74c6..b7ed900b9c9 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -14,12 +14,12 @@ <% end %> <%= page_with_sidebar_aside do %> - <%= render component('ui/panel').new(title: panel_title_with_more_links(t(".customer"), [ - link_to(t(".edit_email"), solidus_admin.order_customer_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), - link_to(t(".edit_shipping"), solidus_admin.new_order_ship_address_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), - link_to(t(".edit_billing"), solidus_admin.new_order_bill_address_path(@order), class: "p-2 hover:bg-gray-25 rounded-sm text-black"), - @order.user && button_to(t(".remove_customer"), solidus_admin.order_customer_path(@order), method: :delete, class: "p-2 hover:bg-gray-25 rounded-sm text-red-500"), - ].compact)) do |panel| %> + <%= render component('ui/panel').new(title: t(".customer")) do |panel| %> + <% panel.with_menu t(".edit_email"), solidus_admin.order_customer_path(@order) %> + <% panel.with_menu t(".edit_shipping"), solidus_admin.new_order_ship_address_path(@order) %> + <% panel.with_menu t(".edit_billing"), solidus_admin.new_order_bill_address_path(@order) %> + <% panel.with_menu t(".remove_customer"), solidus_admin.order_customer_path(@order), method: :delete, class: "text-red-500" if @order.user %> + <% panel.with_section(class: 'flex flex-col gap-6') do %> <%# CUSTOMER %> <% if @order.user %> diff --git a/admin/app/components/solidus_admin/orders/show/component.rb b/admin/app/components/solidus_admin/orders/show/component.rb index 88520ef1407..ba9cf656f0b 100644 --- a/admin/app/components/solidus_admin/orders/show/component.rb +++ b/admin/app/components/solidus_admin/orders/show/component.rb @@ -29,25 +29,6 @@ def format_address(address) ], " ") end - def panel_title_with_more_links(title, links) - tag.details( - tag.summary( - tag.span( - safe_join([ - title, - component("ui/icon").new( - name: "more-line", - alt: t("spree.edit"), - class: "cursor-pointer w-[22px] h-[22px]" - ).render_in(self), - ]), - class: 'flex items-center justify-between text-black', - ) - ) + tag.div(safe_join(links, " "), class: "body-small absolute border border-gray-100 mt-0.5 right-0 flex min-w-[10rem] flex-col p-2 rounded-sm shadow-lg bg-white z-10"), - class: 'relative', - ) - end - def customer_name(user) ( user.default_user_bill_address || diff --git a/admin/app/components/solidus_admin/ui/panel/component.html.erb b/admin/app/components/solidus_admin/ui/panel/component.html.erb index 1dfc039d579..a89d6d72138 100644 --- a/admin/app/components/solidus_admin/ui/panel/component.html.erb +++ b/admin/app/components/solidus_admin/ui/panel/component.html.erb @@ -10,14 +10,50 @@ items-start inline-flex w-full + relative " data-controller="<%= stimulus_id %>" > + <% if menus? %> +
+ "> + <%= render component("ui/icon").new( + name: "more-line", + class: "cursor-pointer w-[22px] h-[22px] hover:fill-gray-500 [[open]_&]:fill-gray-500" + ) %> + +
+ <% menus.each do |menu| %> + <%= menu %> + <% end %> +
+
+ <% end %> + <% if @title %> -

- <%= @title %> - <%= render component('ui/toggletip').new(text: @title_hint) if @title_hint %> -

+
+

+ <%= @title %> + <%= render component("ui/toggletip").new(text: @title_hint) if @title_hint %> +

+
<% end %> <% sections.each do |section| %> @@ -25,14 +61,16 @@ <% end %> <% if content.present? %> -
+
<%= content %> -
+ <% end %> <% if action? %> -
- <%= action %> -
+
+
+ <%= action %> +
+
<% end %>
diff --git a/admin/app/components/solidus_admin/ui/panel/component.rb b/admin/app/components/solidus_admin/ui/panel/component.rb index 74073f210c9..2925ecebb15 100644 --- a/admin/app/components/solidus_admin/ui/panel/component.rb +++ b/admin/app/components/solidus_admin/ui/panel/component.rb @@ -12,13 +12,21 @@ class SolidusAdmin::UI::Panel::Component < SolidusAdmin::BaseComponent renders_many :sections, ->(wide: false, high: false, **args, &block) do tag.section(**args, class: " - border-gray-100 border-t w-full + border-gray-100 border-t w-full first-of-type:border-t-0 #{'px-6' unless wide} #{'py-6' unless high} #{args[:class]} ", &block) end + renders_many :menus, ->(name, url, **args) do + if args[:method] + button_to(name, url, **args, class: "p-2 hover:bg-gray-25 rounded-sm text-black #{args[:class]}") + else + link_to(name, url, **args, class: "p-2 hover:bg-gray-25 rounded-sm text-black #{args[:class]}") + end + end + # @param title [String] the title of the panel # @param title_hint [String] the title hint of the panel def initialize(title: nil, title_hint: nil) diff --git a/admin/app/components/solidus_admin/ui/panel/component.yml b/admin/app/components/solidus_admin/ui/panel/component.yml new file mode 100644 index 00000000000..fe3f3f93212 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/panel/component.yml @@ -0,0 +1,2 @@ +en: + more: "More" diff --git a/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb index 36976757baf..cada7959486 100644 --- a/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb +++ b/admin/spec/components/previews/solidus_admin/ui/panel/component_preview/overview.html.erb @@ -1,4 +1,21 @@
+
+
+ Full +
+ + <%= render current_component.new(title: "SEO") do |panel| %> + <% panel.with_menu("Foo", "#foo") %> + <% panel.with_menu("Bar", "#bar") %> + <% panel.with_section do %><% end %> + <% panel.with_section do %><% end %> + <% panel.with_section do %><% end %> + <% panel.with_section do %><% end %> + <% panel.with_action(name: "Foo", href: "#foo") %> + <% end %> +
+ +
Content only
@@ -61,3 +78,13 @@ <% panel.with_action(name: "Foo", href: "#foo") %> <% end %>
+ +
+
+ With a menu +
+ + <%= render current_component.new(title: "SEO") do |panel| %> + <% panel.with_menu("Foo", "#foo") %> + <% end %> +
diff --git a/admin/spec/features/order_spec.rb b/admin/spec/features/order_spec.rb index 1a23d85d2d1..ccd5efffeeb 100644 --- a/admin/spec/features/order_spec.rb +++ b/admin/spec/features/order_spec.rb @@ -17,6 +17,7 @@ open_customer_menu expect(page).not_to have_content("Remove customer") expect(order.reload.user).to be_nil + expect(page).to be_axe_clean end it "allows changing the order email" do @@ -33,6 +34,7 @@ end expect(page).to have_content("Order was updated successfully") expect(page).to have_content("Order contact email a@b.c", normalize_ws: true) + expect(page).to be_axe_clean end context "in cart state" do @@ -76,6 +78,6 @@ private def open_customer_menu - find("summary", text: "Customer").click + find("summary[title='More']").click end end From fa98eeeb6edc5181991a75882f5f17032dbd7ba4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 10 Nov 2023 18:30:45 +0100 Subject: [PATCH 10/12] Only show the number of complete order in the customer widget --- .../app/components/solidus_admin/orders/show/component.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index b7ed900b9c9..b60fd503711 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -26,7 +26,7 @@
<%= customer_name(@order.user) || tag.span(t('.no_name'), class: "text-gray-500") %>
-
<%= t(".orders_count", count: @order.user.orders.count) %>
+
<%= t(".orders_count", count: @order.user.orders.complete.count) %>
<% end %> From 1fb1f98b5720c5a10160804fc68f47d34d1d94f4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 10 Nov 2023 18:37:00 +0100 Subject: [PATCH 11/12] Reorganize the orders/show customer sidebar Remove the title so that "Customer" will only refer to Spree::User. --- .../orders/show/component.html.erb | 67 ++++++++++--------- .../solidus_admin/orders/show/component.yml | 3 + 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index b60fd503711..4527f809f58 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -14,53 +14,56 @@ <% end %> <%= page_with_sidebar_aside do %> - <%= render component('ui/panel').new(title: t(".customer")) do |panel| %> + <%= render component('ui/panel').new do |panel| %> <% panel.with_menu t(".edit_email"), solidus_admin.order_customer_path(@order) %> <% panel.with_menu t(".edit_shipping"), solidus_admin.new_order_ship_address_path(@order) %> <% panel.with_menu t(".edit_billing"), solidus_admin.new_order_bill_address_path(@order) %> <% panel.with_menu t(".remove_customer"), solidus_admin.order_customer_path(@order), method: :delete, class: "text-red-500" if @order.user %> <% panel.with_section(class: 'flex flex-col gap-6') do %> - <%# CUSTOMER %> - <% if @order.user %> -
-
<%= customer_name(@order.user) || tag.span(t('.no_name'), class: "text-gray-500") %>
+
+ <%= t(".customer") %> + <% if @order.user %> +
<%= customer_name(@order.user) || tag.span(t('.no_name'), class: "text-gray-500") %>
<%= t(".orders_count", count: @order.user.orders.complete.count) %>
-
- <% end %> + <% end %> +
- <%# EMAIL %> - <% if @order.email %> -
- <%= t('.order_email') %> -
<%= @order.email %>
+
+ <%= t('.order_email') %> +
+ <% if @order.email? %> + <%= @order.email %> + <% else %> + <%= link_to(t(".add_email"), solidus_admin.order_customer_path(@order), class: "body-link") %> + <% end %>
- <% end %> +
- <%# SHIPPING %> - <% if @order.ship_address %> -
- <%= @order.class.human_attribute_name(:ship_address) %> -
+
+ <%= @order.class.human_attribute_name(:ship_address) %> +
+ <% if @order.ship_address %> <%= format_address @order.ship_address %> -
+ <% else %> + <%= link_to t(".add_shipping"), solidus_admin.new_order_ship_address_path(@order), class: 'body-link' %> + <% end %>
- <% end %> +
- <%# BILLING %> - <% if @order.bill_address %> -
- <%= @order.class.human_attribute_name(:bill_address) %> -
- <% if @order.bill_address == @order.ship_address %> - <%= t('.same_as_shipping') %> - <% else %> - <%= format_address @order.bill_address %> - <% end %> -
+
+ <%= @order.class.human_attribute_name(:bill_address) %> +
+ <% if @order.bill_address.blank? %> + <%= link_to t(".add_billing"), solidus_admin.new_order_bill_address_path(@order), class: 'body-link' %> + <% elsif @order.bill_address == @order.ship_address %> + <%= t('.same_as_shipping') %> + <% else %> + <%= format_address @order.bill_address %> + <% end %>
- <% end %> +
<% end %> <% end %> diff --git a/admin/app/components/solidus_admin/orders/show/component.yml b/admin/app/components/solidus_admin/orders/show/component.yml index 3f6e0461751..fd3f57289c5 100644 --- a/admin/app/components/solidus_admin/orders/show/component.yml +++ b/admin/app/components/solidus_admin/orders/show/component.yml @@ -10,8 +10,11 @@ en: same_as_shipping: Same as shipping address edit_email: "Edit order email" + add_email: "Add order email" edit_shipping: "Edit shipping address" + add_shipping: "Add shipping address" edit_billing: "Edit billing address" + add_billing: "Add billing address" remove_customer: "Remove customer" orders_count: From de59f4a2298a47d74ec07ce34c50a79b1a5a14e0 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 10 Nov 2023 18:53:05 +0100 Subject: [PATCH 12/12] Add a customer picker for the order page --- .../orders/show/component.html.erb | 2 ++ .../show/customer_search/component.html.erb | 14 ++++++++++++++ .../orders/show/customer_search/component.js | 14 ++++++++++++++ .../orders/show/customer_search/component.rb | 7 +++++++ .../orders/show/customer_search/component.yml | 2 ++ .../customer_search/result/component.html.erb | 17 +++++++++++++++++ .../show/customer_search/result/component.rb | 11 +++++++++++ .../solidus_admin/orders_controller.rb | 16 ++++++++++++++++ admin/config/routes.rb | 1 + 9 files changed, 84 insertions(+) create mode 100644 admin/app/components/solidus_admin/orders/show/customer_search/component.html.erb create mode 100644 admin/app/components/solidus_admin/orders/show/customer_search/component.js create mode 100644 admin/app/components/solidus_admin/orders/show/customer_search/component.rb create mode 100644 admin/app/components/solidus_admin/orders/show/customer_search/component.yml create mode 100644 admin/app/components/solidus_admin/orders/show/customer_search/result/component.html.erb create mode 100644 admin/app/components/solidus_admin/orders/show/customer_search/result/component.rb diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index 4527f809f58..a92fa6ea60c 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -27,6 +27,8 @@
<%= customer_name(@order.user) || tag.span(t('.no_name'), class: "text-gray-500") %>
<%= t(".orders_count", count: @order.user.orders.complete.count) %>
+ <% else %> + <%= render component('orders/show/customer_search').new(order: @order) %> <% end %>
diff --git a/admin/app/components/solidus_admin/orders/show/customer_search/component.html.erb b/admin/app/components/solidus_admin/orders/show/customer_search/component.html.erb new file mode 100644 index 00000000000..e867f7dd7d2 --- /dev/null +++ b/admin/app/components/solidus_admin/orders/show/customer_search/component.html.erb @@ -0,0 +1,14 @@ +
-customers-url-value="<%= solidus_admin.customers_for_order_path(@order) %>" + data-action=" + <%= component('ui/forms/search').stimulus_id %>:search-><%= stimulus_id %>#search + <%= component('ui/forms/search').stimulus_id %>:submit-><%= stimulus_id %>#submit + " +> + <%= render component("ui/forms/search").new( + placeholder: t(".placeholder"), + id: :order_customer + ) %> +
diff --git a/admin/app/components/solidus_admin/orders/show/customer_search/component.js b/admin/app/components/solidus_admin/orders/show/customer_search/component.js new file mode 100644 index 00000000000..68e6b65b05b --- /dev/null +++ b/admin/app/components/solidus_admin/orders/show/customer_search/component.js @@ -0,0 +1,14 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static values = { customersUrl: String } + + async search({ detail: { query, controller } }) { + controller.resultsValue = + (await (await fetch(`${this.customersUrlValue}?q[name_or_variants_including_master_sku_cont]=${query}`)).text()) + } + + submit(event) { + event.detail.resultTarget.querySelector('form').submit() + } +} diff --git a/admin/app/components/solidus_admin/orders/show/customer_search/component.rb b/admin/app/components/solidus_admin/orders/show/customer_search/component.rb new file mode 100644 index 00000000000..1e3b8c2e385 --- /dev/null +++ b/admin/app/components/solidus_admin/orders/show/customer_search/component.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SolidusAdmin::Orders::Show::CustomerSearch::Component < SolidusAdmin::BaseComponent + def initialize(order:) + @order = order + end +end diff --git a/admin/app/components/solidus_admin/orders/show/customer_search/component.yml b/admin/app/components/solidus_admin/orders/show/customer_search/component.yml new file mode 100644 index 00000000000..7d25505767a --- /dev/null +++ b/admin/app/components/solidus_admin/orders/show/customer_search/component.yml @@ -0,0 +1,2 @@ +en: + placeholder: "Search customer" diff --git a/admin/app/components/solidus_admin/orders/show/customer_search/result/component.html.erb b/admin/app/components/solidus_admin/orders/show/customer_search/result/component.html.erb new file mode 100644 index 00000000000..ebe5c4ef2dd --- /dev/null +++ b/admin/app/components/solidus_admin/orders/show/customer_search/result/component.html.erb @@ -0,0 +1,17 @@ +<%= render component('ui/forms/search/result').new do %> + <% if @customer %> + <%= form_for(@order, url: solidus_admin.order_path(@order), html: { + "data-controller": "readonly-when-submitting", + class: "flex items-center", + }) do |f| %> + <%= hidden_field_tag("#{f.object_name}[user_id]", @customer.id) %> + + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/orders/show/customer_search/result/component.rb b/admin/app/components/solidus_admin/orders/show/customer_search/result/component.rb new file mode 100644 index 00000000000..695255a3ff4 --- /dev/null +++ b/admin/app/components/solidus_admin/orders/show/customer_search/result/component.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class SolidusAdmin::Orders::Show::CustomerSearch::Result::Component < SolidusAdmin::BaseComponent + with_collection_parameter :customer + + def initialize(order:, customer:) + @order = order + @customer = customer + @name = (customer.default_user_bill_address || customer.default_user_ship_address)&.address&.name if customer + end +end diff --git a/admin/app/controllers/solidus_admin/orders_controller.rb b/admin/app/controllers/solidus_admin/orders_controller.rb index 71044becabc..8570029ffd8 100644 --- a/admin/app/controllers/solidus_admin/orders_controller.rb +++ b/admin/app/controllers/solidus_admin/orders_controller.rb @@ -74,6 +74,22 @@ def variants_for end end + def customers_for + load_order + + @users = Spree.user_class + .where.not(id: @order.user_id) + .order(created_at: :desc, id: :desc) + .ransack(params[:q]) + .result(distinct: true) + .includes(:default_user_bill_address, :default_user_ship_address) + .limit(10) + + respond_to do |format| + format.html { render component('orders/show/customer_search/result').with_collection(@users, order: @order), layout: false } + end + end + private def load_order diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 9322532bd18..d0c3a997fa9 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -26,6 +26,7 @@ member do get :variants_for + get :customers_for end end end