@@ -75,8 +88,6 @@
<%= @shipment.shipping_method.name %> - <%= @shipment.display_cost %>
-
- <%= render component("ui/icon").new(name: 'edit-line', class: 'w-5 h-5 cursor-pointer') %>
-
- <%= render component("ui/icon").new(name: 'edit-line', class: 'w-5 h-5 cursor-pointer') %>
diff --git a/admin/app/components/solidus_admin/orders/show/shipment/component.rb b/admin/app/components/solidus_admin/orders/show/shipment/component.rb
index 13ff52bed16..d65fed88cc2 100644
--- a/admin/app/components/solidus_admin/orders/show/shipment/component.rb
+++ b/admin/app/components/solidus_admin/orders/show/shipment/component.rb
@@ -1,8 +1,11 @@
# frozen_string_literal: true
class SolidusAdmin::Orders::Show::Shipment::Component < SolidusAdmin::BaseComponent
+ include SolidusAdmin::Layout::PageHelpers
+
def initialize(shipment:, index:)
@shipment = shipment
+ @order = shipment.order
@index = index
end
diff --git a/admin/app/components/solidus_admin/orders/show/shipment/component.yml b/admin/app/components/solidus_admin/orders/show/shipment/component.yml
index 4f41648a1c3..ad59106d2cc 100644
--- a/admin/app/components/solidus_admin/orders/show/shipment/component.yml
+++ b/admin/app/components/solidus_admin/orders/show/shipment/component.yml
@@ -1,9 +1,11 @@
en:
+ title: "#%{index}: %{number} from %{location}"
product: Product
quantity: Quantity
total: Total Price
actions: Actions
none: No tracking details provided
+ edit_shipment: Edit shipment
inventory_states:
backordered: Backordered
canceled: Canceled
diff --git a/admin/app/components/solidus_admin/orders/show/shipment/edit/component.html.erb b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.html.erb
new file mode 100644
index 00000000000..91edf286d1d
--- /dev/null
+++ b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.html.erb
@@ -0,0 +1,18 @@
+
+ <%= render component("orders/show").new(order: @order) %>
+ <%= render component("ui/modal").new(title: t(".title", number: @shipment.number), close_path: close_path) do |modal| %>
+ <%= form_for @shipment, url: solidus_admin.order_shipments_path(@order, shipment_id: @shipment.id), html: { id: form_id } do |f| %>
+ <%= render component("ui/forms/field").text_field(f, :tracking) %>
+ <%= render component("ui/forms/field").select(
+ f,
+ :selected_shipping_rate_id,
+ @shipment.shipping_rates.map { |sr| [sr.shipping_method.name, sr.id] },
+ ) %>
+ <% end %>
+
+ <% modal.with_actions do %>
+ <%= render component("ui/button").new(tag: :a, scheme: :secondary, href: close_path, type: :submit, text: t('.cancel')) %>
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
+ <% end %>
+ <% end %>
+
diff --git a/admin/app/components/solidus_admin/orders/show/shipment/edit/component.js b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.js
new file mode 100644
index 00000000000..b6e2b996c67
--- /dev/null
+++ b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.js
@@ -0,0 +1,14 @@
+import { Controller } from '@hotwired/stimulus'
+
+export default class extends Controller {
+ static targets = ['output']
+
+ typed(event) {
+ this.text = event.currentTarget.value
+ this.render()
+ }
+
+ render() {
+ this.outputTarget.innerText = this.text
+ }
+}
diff --git a/admin/app/components/solidus_admin/orders/show/shipment/edit/component.rb b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.rb
new file mode 100644
index 00000000000..cdbeb708f15
--- /dev/null
+++ b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class SolidusAdmin::Orders::Show::Shipment::Edit::Component < SolidusAdmin::BaseComponent
+ include SolidusAdmin::Layout::PageHelpers
+
+ def initialize(shipment:)
+ @order = shipment.order
+ @shipment = shipment
+ end
+
+ def form_id
+ dom_id(@order, "#{stimulus_id}_shipment_form_#{@shipment.id}")
+ end
+
+ def close_path
+ @close_path ||= solidus_admin.order_path(@order)
+ end
+end
diff --git a/admin/app/components/solidus_admin/orders/show/shipment/edit/component.yml b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.yml
new file mode 100644
index 00000000000..76492adc03f
--- /dev/null
+++ b/admin/app/components/solidus_admin/orders/show/shipment/edit/component.yml
@@ -0,0 +1,4 @@
+en:
+ title: "Edit shipment %{number}"
+ submit: "Save"
+ cancel: "Cancel"
diff --git a/admin/app/controllers/solidus_admin/shipments_controller.rb b/admin/app/controllers/solidus_admin/shipments_controller.rb
new file mode 100644
index 00000000000..54680638f2b
--- /dev/null
+++ b/admin/app/controllers/solidus_admin/shipments_controller.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+class SolidusAdmin::ShipmentsController < SolidusAdmin::BaseController
+ include Spree::Core::ControllerHelpers::StrongParameters
+
+ before_action :load_order, :load_shipment, only: [:show, :update]
+
+ def show
+ render component('orders/show/shipment/edit').new(shipment: @shipment)
+ end
+
+ def update
+ if @shipment.update_attributes_and_order(shipment_params)
+ redirect_to order_path(@order), status: :see_other, notice: t('.success')
+ else
+ flash.now[:error] = @order.errors[:base].join(", ") if @order.errors[:base].any?
+
+ respond_to do |format|
+ format.html do
+ render component('orders/show/shipment/edit').new(order: @order), status: :unprocessable_entity
+ end
+ end
+ end
+ end
+
+ private
+
+ def load_order
+ @order = Spree::Order.find_by!(number: params[:order_id])
+ end
+
+ def load_shipment
+ @shipment = @order.shipments.find_by(id: params[:shipment_id])
+ end
+
+ def shipment_params
+ if params[:shipment] && !params[:shipment].empty?
+ params.require(:shipment).permit(permitted_shipment_attributes)
+ else
+ {}
+ end
+ end
+
+ def authorization_subject
+ @order || Spree::Order
+ end
+end
diff --git a/admin/config/locales/shipments.en.yml b/admin/config/locales/shipments.en.yml
new file mode 100644
index 00000000000..79db3c734de
--- /dev/null
+++ b/admin/config/locales/shipments.en.yml
@@ -0,0 +1,7 @@
+en:
+ solidus_admin:
+ shipments:
+ title: "Shipments"
+ update:
+ success: "Shipment was updated successfully"
+ error: "Shipment could not be updated"
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index c938ea27de6..3f3a57610fe 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -38,6 +38,7 @@
resource :customer
resource :ship_address, only: [:show, :edit, :update], controller: "addresses", type: "ship"
resource :bill_address, only: [:show, :edit, :update], controller: "addresses", type: "bill"
+ resource :shipments
member do
get :variants_for
diff --git a/admin/lib/solidus_admin/configuration.rb b/admin/lib/solidus_admin/configuration.rb
index 921ba5d5cd9..70fda4629b3 100644
--- a/admin/lib/solidus_admin/configuration.rb
+++ b/admin/lib/solidus_admin/configuration.rb
@@ -44,7 +44,7 @@ class Configuration < Spree::Preferences::Configuration
# Setting this to `true` enables access to alpha stage features that might still be in testing or development.
# Use with caution, as these features may not be fully stable or complete.
# Default: false
- preference :enable_alpha_features, :boolean, default: false
+ preference :enable_alpha_features, :boolean, default: true
alias enable_alpha_features? enable_alpha_features
diff --git a/admin/spec/components/previews/solidus_admin/orders/show/shipment/edit/component_preview.rb b/admin/spec/components/previews/solidus_admin/orders/show/shipment/edit/component_preview.rb
new file mode 100644
index 00000000000..48b14be56f1
--- /dev/null
+++ b/admin/spec/components/previews/solidus_admin/orders/show/shipment/edit/component_preview.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+# @component "orders/show/shipment/edit"
+class SolidusAdmin::Orders::Show::Shipment::Edit::ComponentPreview < ViewComponent::Preview
+ include SolidusAdmin::Preview
+
+ def overview
+ render_with_template
+ end
+
+ # @param shipment text
+ def playground(shipment: "shipment")
+ render component("orders/show/shipment/edit").new(shipment: shipment)
+ end
+end
diff --git a/admin/spec/components/previews/solidus_admin/orders/show/shipment/edit/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/orders/show/shipment/edit/component_preview/overview.html.erb
new file mode 100644
index 00000000000..66873ba36a2
--- /dev/null
+++ b/admin/spec/components/previews/solidus_admin/orders/show/shipment/edit/component_preview/overview.html.erb
@@ -0,0 +1,7 @@
+
+
+ Scenario 1
+
+
+ <%= render current_component.new(shipment: "shipment") %>
+
diff --git a/admin/spec/components/solidus_admin/orders/show/shipment/edit/component_spec.rb b/admin/spec/components/solidus_admin/orders/show/shipment/edit/component_spec.rb
new file mode 100644
index 00000000000..6b280dd7f5d
--- /dev/null
+++ b/admin/spec/components/solidus_admin/orders/show/shipment/edit/component_spec.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe SolidusAdmin::Orders::Show::Shipment::Edit::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