-
-
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
Showing
14 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
admin/app/components/solidus_admin/orders/customer/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,14 @@ | ||
<div | ||
class="w-full relative overflow-visible" | ||
data-controller="<%= stimulus_id %>" | ||
data-<%= stimulus_id %>-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 | ||
) %> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
admin/app/components/solidus_admin/orders/customer/component.js
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,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() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
admin/app/components/solidus_admin/orders/customer/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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Orders::Customer::Component < SolidusAdmin::BaseComponent | ||
def initialize(order:) | ||
@order = order | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/orders/customer/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,4 @@ | ||
# Add your component translations here. | ||
# Use the translation in the example in your template with `t(".hello")`. | ||
en: | ||
placeholder: "Search customer" |
19 changes: 19 additions & 0 deletions
19
admin/app/components/solidus_admin/orders/customer/result/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,19 @@ | ||
<%= 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) %> | ||
<button type="submit" class="flex gap-2 grow items-center"> | ||
<%= render component("ui/icon").new( | ||
name: "user-line", | ||
) %> | ||
<div class="flex-col"> | ||
<div class="leading-5 text-black body-small-bold"><%= @name %></div> | ||
<div class="leading-5 text-gray-500 body-small"><%= @customer.email %></div> | ||
</div> | ||
</button> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
11 changes: 11 additions & 0 deletions
11
admin/app/components/solidus_admin/orders/customer/result/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,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Orders::Customer::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)&.name if customer | ||
end | ||
end |
2 changes: 2 additions & 0 deletions
2
admin/app/components/solidus_admin/orders/customer/result/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,2 @@ | ||
en: | ||
add: Create a new customer |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ en: | |
title: "Orders" | ||
update: | ||
success: "Order was updated successfully" | ||
error: "Order could not be updated" |
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
|
||
member do | ||
get :variants_for | ||
get :customers_for | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
admin/spec/components/previews/solidus_admin/orders/customer/component_preview.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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
# @component "orders/customer" | ||
class SolidusAdmin::Orders::Customer::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
def overview | ||
render_with_template | ||
end | ||
|
||
# @param order text | ||
def playground(order: "order") | ||
render component("orders/customer").new(order: order) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
...pec/components/previews/solidus_admin/orders/customer/component_preview/overview.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,7 @@ | ||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
Scenario 1 | ||
</h6> | ||
|
||
<%= render current_component.new(order: "order") %> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
admin/spec/components/solidus_admin/orders/customer/component_spec.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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::Orders::Customer::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
|
||
# it "renders something useful" do | ||
# render_inline(described_class.new(order: "order")) | ||
# | ||
# expect(page).to have_text "Hello, components!" | ||
# expect(page).to have_css '.value' | ||
# end | ||
end |
16 changes: 16 additions & 0 deletions
16
admin/spec/components/solidus_admin/orders/customer/new/component_spec.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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
RSpec.describe SolidusAdmin::Orders::Customer::New::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
|
||
# it "renders something useful" do | ||
# render_inline(described_class.new(order: "order")) | ||
# | ||
# expect(page).to have_text "Hello, components!" | ||
# expect(page).to have_css '.value' | ||
# end | ||
end |