Skip to content

Commit

Permalink
Merge pull request #5434 from nebulab/rainerd/base-order-creation-com…
Browse files Browse the repository at this point in the history
…ponents

[Admin] Construct base components for order creation in admin interface
  • Loading branch information
rainerdema authored Oct 13, 2023
2 parents 0e4424c + b8f3a4d commit 33e539d
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%= render component("ui/button").new(
tag: :a,
text: t('.create_order'),
href: spree.new_admin_order_path,
href: solidus_admin.new_order_path,
icon: "add-line",
) %>
</div>
Expand Down
20 changes: 20 additions & 0 deletions admin/app/components/solidus_admin/orders/new/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="px-4 relative" data-controller="<%= stimulus_id %>">
<header class="py-6 flex items-center gap-4">
<%= render component("ui/button").new(
tag: :a,
title: t(".back"),
icon: "arrow-left-line",
scheme: :secondary,
href: solidus_admin.orders_path
) %>
<h1 class="flex items-center gap-2">
<span class="body-title"><%= t(".create_order") %></span>
</h1>

<div class="ml-auto flex gap-2 items-center">
<%= render component("feedback").new %>
<%= render component("ui/button").new(tag: :button, scheme: :secondary, text: t(".discard"), form: form_id) %>
<%= render component("ui/button").new(tag: :button, text: t(".save"), form: form_id) %>
</div>
</header>
</div>
5 changes: 5 additions & 0 deletions admin/app/components/solidus_admin/orders/new/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {

}
11 changes: 11 additions & 0 deletions admin/app/components/solidus_admin/orders/new/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class SolidusAdmin::Orders::New::Component < SolidusAdmin::BaseComponent
def initialize(order:)
@order = order
end

def form_id
@form_id ||= "#{stimulus_id}--form-#{@order.id}"
end
end
6 changes: 6 additions & 0 deletions admin/app/components/solidus_admin/orders/new/component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
create_order: Create Order
save: Save
discard: Discard
12 changes: 12 additions & 0 deletions admin/app/controllers/solidus_admin/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ def index
format.html { render component('orders/index').new(page: @page) }
end
end

def new
@order = Spree::Order.new(
created_by: current_solidus_admin_user,
frontend_viewable: false,
store_id: current_store.try(:id)
)

respond_to do |format|
format.html { render component('orders/new').new(order: @order) }
end
end
end
end
2 changes: 1 addition & 1 deletion admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
put :activate
end
end
resources :orders, only: :index
resources :orders, only: [:index, :new, :create]
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

# @component "orders/new"
class SolidusAdmin::Orders::New::ComponentPreview < ViewComponent::Preview
include SolidusAdmin::Preview

def overview
render_with_template(locals: { order: Spree::Order.new })
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="mb-8">
<%= render current_component.new(order: order) %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe SolidusAdmin::Orders::New::Component, type: :component do
it "renders the overview preview" do
render_preview(:overview)
end
end

0 comments on commit 33e539d

Please sign in to comment.