-
-
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.
[wip] Add
orders/show/shipment
component
Co-Authored-By: andrea longhi <[email protected]>
- Loading branch information
1 parent
547d0d2
commit e1f8c30
Showing
11 changed files
with
276 additions
and
7 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
admin/app/components/solidus_admin/orders/show/shipment/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
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
96 changes: 96 additions & 0 deletions
96
admin/app/components/solidus_admin/orders/show/shipment/split/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,96 @@ | ||
<div class="<%= stimulus_id %>" data-controller="<%= stimulus_id %>"> | ||
<%= render component("orders/show").new(order: @order) %> | ||
<%= render component("ui/modal").new(title: t(".title", number: @shipment.number), close_path: close_path) do |modal| %> | ||
<table class="table-auto w-full"> | ||
<thead> | ||
<tr> | ||
<th class="py-2 px-4 h-10 bg-gray-15 w-16"> | ||
<%= | ||
render component("ui/forms/checkbox").new( | ||
form: form_id, | ||
"data-action": "#{stimulus_id}#selectAllRows", | ||
"data-#{stimulus_id}-target": "headerCheckbox", | ||
"aria-label": t('.select_all'), | ||
) | ||
%> | ||
</th> | ||
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none"> | ||
<%= t(".product") %> | ||
</th> | ||
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16"> | ||
<%= t(".quantity") %> | ||
</th> | ||
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16 whitespace-nowrap"> | ||
<%= t(".total") %> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% manifest.each do |item| %> | ||
<tr class="border-gray-100 border-t"> | ||
<td class="py-2 px-4"> | ||
<%= | ||
render component("ui/forms/checkbox").new( | ||
name: "selected_variants[]", | ||
form: form_id, | ||
value: item.variant.id, | ||
"data-#{stimulus_id}-target": "checkbox", | ||
) | ||
%> | ||
</td> | ||
|
||
<td class="px-6 py-4"> | ||
<div class="flex gap-2 grow"> | ||
<% variant = item.variant %> | ||
<%= render component("ui/thumbnail").new( | ||
src: (variant.images.first || variant.product.gallery.images.first)&.url(:small), | ||
alt: variant.name | ||
) %> | ||
<div class="flex-col"> | ||
<div class="leading-5 text-black body-small-bold"><%= variant.name %></div> | ||
<div class="leading-5 text-gray-500 body-small"> | ||
SKU: <%= variant.sku %> | ||
<%= variant.options_text.presence&.prepend("- ") %> | ||
</div> | ||
</div> | ||
</div> | ||
</td> | ||
<td class="px-6 py-4"> | ||
<span class="text-gray-500 body-small whitespace-nowrap"> | ||
<%= render component("ui/forms/input").new( | ||
value: item.line_item.quantity, | ||
form: form_id, | ||
name: "variants[#{item.variant.id}][quantity]", | ||
type: :number, | ||
step: 1, | ||
min: "1", | ||
max: item.line_item.quantity, | ||
"data-#{stimulus_id}-target": "quantity", | ||
"data-action": "focus->#{stimulus_id}#selectRow", | ||
) %> | ||
</span> | ||
</td> | ||
<td class="px-6 py-4"> | ||
<span class="text-gray-500 body-small"><%= item.line_item.display_amount %></span> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<% modal.with_actions do %> | ||
<%= form_tag '', id: form_id, "data-action": "submit->#{stimulus_id}#submit" %> | ||
<%= render component("ui/button").new(tag: :a, scheme: :secondary, href: close_path, type: :submit, text: t('.cancel')) %> | ||
<%= render_split_action_button %> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
|
||
|
||
|
||
<form action="/your_action" method="post"> | ||
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>"> | ||
<input type="text" name="variants[1][quantity]" value="12"> | ||
<input type="text" name="variants[2][quantity]" value="3"> | ||
<input type="submit" value="Submit"> | ||
</form> |
23 changes: 23 additions & 0 deletions
23
admin/app/components/solidus_admin/orders/show/shipment/split/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,23 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = [ | ||
"checkbox", | ||
"headerCheckbox", | ||
"quantity" | ||
] | ||
|
||
selectAllRows(event) { | ||
this.checkboxTargets.forEach((checkbox) => (checkbox.checked = event.target.checked)) | ||
} | ||
|
||
selectRow(event) { | ||
const checkbox = this.checkboxTargets.find(selection => event.target.closest("tr").contains(selection)) | ||
if (checkbox) checkbox.checked = true | ||
} | ||
|
||
submit(event) { | ||
event.preventDefault() | ||
//this.quantityTargets.forEach((quantity) => (quantity.disabled = !this.checkboxTargets.find(selection => quantity.contains(selection).checked ))) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
admin/app/components/solidus_admin/orders/show/shipment/split/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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::Orders::Show::Shipment::Split::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(shipment:) | ||
@order = shipment.order | ||
@shipment = shipment | ||
end | ||
|
||
def manifest | ||
Spree::ShippingManifest.new( | ||
inventory_units: @shipment.inventory_units.where(carton_id: nil), | ||
).items.sort_by { |item| item.line_item.created_at } | ||
end | ||
|
||
def form_id | ||
dom_id(@order, "#{stimulus_id}_shipment_form_#{@shipment.id}") | ||
end | ||
|
||
|
||
def render_split_action_button | ||
render component("ui/button").new( | ||
name: request_forgery_protection_token, | ||
value: form_authenticity_token(form_options: { | ||
action: solidus_admin.split_create_order_shipments_path(@order), | ||
method: :put, | ||
}), | ||
formaction: solidus_admin.split_create_order_shipments_path(@order), | ||
formmethod: :put, | ||
form: form_id, | ||
text: t('.split'), | ||
type: :submit, | ||
) | ||
end | ||
|
||
def close_path | ||
@close_path ||= solidus_admin.order_path(@order) | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
admin/app/components/solidus_admin/orders/show/shipment/split/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,16 @@ | ||
en: | ||
title: "Split shipment %{number}" | ||
submit: "Save" | ||
cancel: "Cancel" | ||
product: Product | ||
quantity: Quantity | ||
total: Total Price | ||
actions: Actions | ||
split: Split | ||
select_all: Select All | ||
inventory_states: | ||
backordered: Backordered | ||
canceled: Canceled | ||
on_hand: On hand | ||
returned: Returned | ||
shipped: Shipped |
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
15 changes: 15 additions & 0 deletions
15
admin/spec/components/previews/solidus_admin/orders/show/shipment/split/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/show/shipment/split" | ||
class SolidusAdmin::Orders::Show::Shipment::Split::ComponentPreview < ViewComponent::Preview | ||
include SolidusAdmin::Preview | ||
|
||
def overview | ||
render_with_template | ||
end | ||
|
||
# @param shipment text | ||
def playground(shipment: "shipment") | ||
render component("orders/show/shipment/split").new(shipment: shipment) | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
...nts/previews/solidus_admin/orders/show/shipment/split/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(shipment: "shipment") %> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
admin/spec/components/solidus_admin/orders/show/shipment/split/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::Show::Shipment::Split::Component, type: :component do | ||
it "renders the overview preview" do | ||
render_preview(:overview) | ||
end | ||
|
||
# it "renders something useful" do | ||
# render_inline(described_class.new(shipment: "shipment")) | ||
# | ||
# expect(page).to have_text "Hello, components!" | ||
# expect(page).to have_css '.value' | ||
# end | ||
end |