Skip to content

Commit 33e539d

Browse files
authored
Merge pull request #5434 from nebulab/rainerd/base-order-creation-components
[Admin] Construct base components for order creation in admin interface
2 parents 0e4424c + b8f3a4d commit 33e539d

File tree

10 files changed

+78
-2
lines changed

10 files changed

+78
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<%= render component("ui/button").new(
1010
tag: :a,
1111
text: t('.create_order'),
12-
href: spree.new_admin_order_path,
12+
href: solidus_admin.new_order_path,
1313
icon: "add-line",
1414
) %>
1515
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div class="px-4 relative" data-controller="<%= stimulus_id %>">
2+
<header class="py-6 flex items-center gap-4">
3+
<%= render component("ui/button").new(
4+
tag: :a,
5+
title: t(".back"),
6+
icon: "arrow-left-line",
7+
scheme: :secondary,
8+
href: solidus_admin.orders_path
9+
) %>
10+
<h1 class="flex items-center gap-2">
11+
<span class="body-title"><%= t(".create_order") %></span>
12+
</h1>
13+
14+
<div class="ml-auto flex gap-2 items-center">
15+
<%= render component("feedback").new %>
16+
<%= render component("ui/button").new(tag: :button, scheme: :secondary, text: t(".discard"), form: form_id) %>
17+
<%= render component("ui/button").new(tag: :button, text: t(".save"), form: form_id) %>
18+
</div>
19+
</header>
20+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Controller } from '@hotwired/stimulus'
2+
3+
export default class extends Controller {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
class SolidusAdmin::Orders::New::Component < SolidusAdmin::BaseComponent
4+
def initialize(order:)
5+
@order = order
6+
end
7+
8+
def form_id
9+
@form_id ||= "#{stimulus_id}--form-#{@order.id}"
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Add your component translations here.
2+
# Use the translation in the example in your template with `t(".hello")`.
3+
en:
4+
create_order: Create Order
5+
save: Save
6+
discard: Discard

admin/app/controllers/solidus_admin/orders_controller.rb

+12
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,17 @@ def index
1717
format.html { render component('orders/index').new(page: @page) }
1818
end
1919
end
20+
21+
def new
22+
@order = Spree::Order.new(
23+
created_by: current_solidus_admin_user,
24+
frontend_viewable: false,
25+
store_id: current_store.try(:id)
26+
)
27+
28+
respond_to do |format|
29+
format.html { render component('orders/new').new(order: @order) }
30+
end
31+
end
2032
end
2133
end

admin/config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
put :activate
1414
end
1515
end
16-
resources :orders, only: :index
16+
resources :orders, only: [:index, :new, :create]
1717
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
# @component "orders/new"
4+
class SolidusAdmin::Orders::New::ComponentPreview < ViewComponent::Preview
5+
include SolidusAdmin::Preview
6+
7+
def overview
8+
render_with_template(locals: { order: Spree::Order.new })
9+
end
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="mb-8">
2+
<%= render current_component.new(order: order) %>
3+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
RSpec.describe SolidusAdmin::Orders::New::Component, type: :component do
6+
it "renders the overview preview" do
7+
render_preview(:overview)
8+
end
9+
end

0 commit comments

Comments
 (0)