Skip to content

Commit 676e583

Browse files
committed
[wip] Add orders/show/shipment component
1 parent 1bdfbb7 commit 676e583

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

admin/app/components/solidus_admin/orders/show/component.html.erb

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
<%= render component("orders/cart").new(order: @order) %>
1414
<%= render component("orders/show/summary").new(order: @order) %>
1515

16-
<%= render component('ui/panel').new(title: t('.shipments')) do %>
17-
<% @order.shipments.each do |shipment| %>
18-
<%= render component("orders/show/shipment").new(shipment: @shipment) %>
16+
<% if @order.shipments.count > 0 %>
17+
<%= render component('ui/panel').new(title: t('.shipments')) do %>
18+
<% @order.shipments.each.with_index(1) do |shipment, index| %>
19+
<%= render component("orders/show/shipment").new(shipment: shipment, index: index) %>
20+
<% end %>
1921
<% end %>
2022
<% end %>
2123
<% end %>

admin/app/components/solidus_admin/orders/show/shipment/component.html.erb

+37-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
<div class="<%= stimulus_id %>" data-controller="<%= stimulus_id %>">
22
<div class="rounded p-2">
3-
<%= render component('ui/panel').new(title: @shipment.number) do |panel| %>
3+
<%= render component('ui/panel').new do |panel| %>
4+
<% panel.with_section(wide: true, high: true) do %>
5+
<section class="border-gray-100 border-t w-full first-of-type:border-t-0 p-6">
6+
<h2>
7+
<span class="text-xl">
8+
#<%= @index %>: <%= @shipment.number %> from <%= @shipment.stock_location.name %> <%= render component('ui/badge').new(name: @shipment.state.titleize) %>
9+
</span>
10+
</h2>
11+
</section>
12+
<% end %>
13+
414
<% panel.with_section(wide: true, high: true) do %>
515
<div class="rounded-b-lg overflow-hidden">
616
<table class="table-auto w-full">
717
<thead>
818
<tr>
9-
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none">Product</th>
10-
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16">Quantity</th>
11-
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16 whitespace-nowrap">Total Price</th>
12-
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16"><span class="sr-only">Actions</span></th>
19+
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none"><%= t(".product") %></th>
20+
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16"><%= t(".quantity") %></th>
21+
<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>
22+
<th class="text-left body-small-bold text-gray-800 bg-gray-15 px-6 py-3 leading-none w-16"><span class="sr-only"><%= t(".actions") %></span></th>
1323
</tr>
1424
</thead>
1525
<tbody>
16-
<%
17-
shipment_manifest = Spree::ShippingManifest.new(
18-
inventory_units: @shipment.last.inventory_units.where(carton_id: nil),
19-
).items.sort_by { |item| item.line_item.created_at }
20-
%>
21-
22-
<% shipment_manifest.each do |item| %>
26+
<% manifest.each do |item| %>
2327
<tr class="border-gray-100 border-t">
2428
<td class="px-6 py-4">
2529
<div class="flex gap-2 grow">
@@ -63,19 +67,28 @@
6367
<% end %>
6468
<tr class="border-gray-100 border-t">
6569
<td colspan="4" class="px-6 py-4">
66-
<%= form_for(@shipment, url: '#') do |f| %>
67-
<%= render component("ui/forms/field").select(
68-
f,
69-
:shipping_method,
70-
Spree::ShippingMethod.order(:name).pluck(:name, :id),
71-
class: "mb-4"
72-
) %>
70+
<ul class="text-sm">
71+
<li class="flex justify-between py-1.5">
72+
<label class="flex flex-col w-full">
73+
<span class="text-gray-700 body-tiny-bold body-text-xs-semibold">
74+
<%= @shipment.class.human_attribute_name(:shipping_method) %>
75+
</span>
76+
<%= @shipment.shipping_method.name %> - <%= @shipment.display_cost %>
77+
</label>
78+
79+
<%= render component("ui/icon").new(name: 'edit-line', class: 'w-5 h-5 cursor-pointer') %>
80+
</li>
81+
<li class="flex justify-between py-1.5">
82+
<label class="flex flex-col w-full py-1.5">
83+
<span class="text-gray-700 body-tiny-bold body-text-xs-semibold">
84+
<%= @shipment.class.human_attribute_name(:tracking) %>
85+
</span>
86+
<%= @shipment.tracking || t(".none") %>
87+
</label>
7388

74-
<%= render component("ui/forms/field").text_field(
75-
f,
76-
:tracking
77-
) %>
78-
<% end %>
89+
<%= render component("ui/icon").new(name: 'edit-line', class: 'w-5 h-5 cursor-pointer') %>
90+
</li>
91+
</ul>
7992
</td>
8093
</tr>
8194
</tbody>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# frozen_string_literal: true
22

33
class SolidusAdmin::Orders::Show::Shipment::Component < SolidusAdmin::BaseComponent
4-
def initialize(shipment:)
4+
def initialize(shipment:, index:)
55
@shipment = shipment
6+
@index = index
7+
end
8+
9+
def manifest
10+
Spree::ShippingManifest.new(
11+
inventory_units: @shipment.inventory_units.where(carton_id: nil),
12+
).items.sort_by { |item| item.line_item.created_at }
613
end
714
end

admin/app/components/solidus_admin/orders/show/shipment/component.yml

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
en:
2+
product: Product
3+
quantity: Quantity
4+
total: Total Price
5+
actions: Actions
6+
none: No tracking details provided
27
inventory_states:
38
backordered: Backordered
49
canceled: Canceled

0 commit comments

Comments
 (0)