-
-
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
- Loading branch information
1 parent
aacc797
commit 547d0d2
Showing
14 changed files
with
171 additions
and
10 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
admin/app/components/solidus_admin/orders/show/shipment/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
2 changes: 2 additions & 0 deletions
2
admin/app/components/solidus_admin/orders/show/shipment/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
18 changes: 18 additions & 0 deletions
18
admin/app/components/solidus_admin/orders/show/shipment/edit/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,18 @@ | ||
<div class="<%= 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| %> | ||
<%= 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 %> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
admin/app/components/solidus_admin/orders/show/shipment/edit/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 targets = ['output'] | ||
|
||
typed(event) { | ||
this.text = event.currentTarget.value | ||
this.render() | ||
} | ||
|
||
render() { | ||
this.outputTarget.innerText = this.text | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
admin/app/components/solidus_admin/orders/show/shipment/edit/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,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 |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/orders/show/shipment/edit/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 @@ | ||
en: | ||
title: "Edit shipment %{number}" | ||
submit: "Save" | ||
cancel: "Cancel" |
47 changes: 47 additions & 0 deletions
47
admin/app/controllers/solidus_admin/shipments_controller.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,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 |
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 @@ | ||
en: | ||
solidus_admin: | ||
shipments: | ||
title: "Shipments" | ||
update: | ||
success: "Shipment was updated successfully" | ||
error: "Shipment 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
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/edit/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/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 |
7 changes: 7 additions & 0 deletions
7
...ents/previews/solidus_admin/orders/show/shipment/edit/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/edit/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::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 |