From b8f3a4d107954271d169d8c27e2a1e8e927612ff Mon Sep 17 00:00:00 2001 From: Rainer Dema Date: Fri, 13 Oct 2023 16:59:58 +0200 Subject: [PATCH] Create and link `orders/new` component with a base header This commit introduces a new `orders/new` component that includes a header, providing users with 'Save' and 'Discard' button options. Although the UI elements have been integrated, the functionalities for these buttons will be implemented in subsequent iterations. --- .../orders/index/component.html.erb | 2 +- .../orders/new/component.html.erb | 20 +++++++++++++++++++ .../solidus_admin/orders/new/component.js | 5 +++++ .../solidus_admin/orders/new/component.rb | 11 ++++++++++ .../solidus_admin/orders/new/component.yml | 6 ++++++ .../solidus_admin/orders_controller.rb | 6 +++++- .../orders/new/component_preview.rb | 10 ++++++++++ .../new/component_preview/overview.html.erb | 3 +++ .../orders/new/component_spec.rb | 9 +++++++++ 9 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 admin/app/components/solidus_admin/orders/new/component.html.erb create mode 100644 admin/app/components/solidus_admin/orders/new/component.js create mode 100644 admin/app/components/solidus_admin/orders/new/component.rb create mode 100644 admin/app/components/solidus_admin/orders/new/component.yml create mode 100644 admin/spec/components/previews/solidus_admin/orders/new/component_preview.rb create mode 100644 admin/spec/components/previews/solidus_admin/orders/new/component_preview/overview.html.erb create mode 100644 admin/spec/components/solidus_admin/orders/new/component_spec.rb diff --git a/admin/app/components/solidus_admin/orders/index/component.html.erb b/admin/app/components/solidus_admin/orders/index/component.html.erb index e423137d3e3..4b90757ceb7 100644 --- a/admin/app/components/solidus_admin/orders/index/component.html.erb +++ b/admin/app/components/solidus_admin/orders/index/component.html.erb @@ -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", ) %> diff --git a/admin/app/components/solidus_admin/orders/new/component.html.erb b/admin/app/components/solidus_admin/orders/new/component.html.erb new file mode 100644 index 00000000000..32d156165f1 --- /dev/null +++ b/admin/app/components/solidus_admin/orders/new/component.html.erb @@ -0,0 +1,20 @@ +
+
+ <%= render component("ui/button").new( + tag: :a, + title: t(".back"), + icon: "arrow-left-line", + scheme: :secondary, + href: solidus_admin.orders_path + ) %> +

+ <%= t(".create_order") %> +

+ +
+ <%= 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) %> +
+
+
diff --git a/admin/app/components/solidus_admin/orders/new/component.js b/admin/app/components/solidus_admin/orders/new/component.js new file mode 100644 index 00000000000..6839d36996e --- /dev/null +++ b/admin/app/components/solidus_admin/orders/new/component.js @@ -0,0 +1,5 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + +} diff --git a/admin/app/components/solidus_admin/orders/new/component.rb b/admin/app/components/solidus_admin/orders/new/component.rb new file mode 100644 index 00000000000..0008f6fce94 --- /dev/null +++ b/admin/app/components/solidus_admin/orders/new/component.rb @@ -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 diff --git a/admin/app/components/solidus_admin/orders/new/component.yml b/admin/app/components/solidus_admin/orders/new/component.yml new file mode 100644 index 00000000000..d78429ce878 --- /dev/null +++ b/admin/app/components/solidus_admin/orders/new/component.yml @@ -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 diff --git a/admin/app/controllers/solidus_admin/orders_controller.rb b/admin/app/controllers/solidus_admin/orders_controller.rb index bcbc76b96b8..ac92068ed8a 100644 --- a/admin/app/controllers/solidus_admin/orders_controller.rb +++ b/admin/app/controllers/solidus_admin/orders_controller.rb @@ -19,11 +19,15 @@ def index end def new - Spree::Order.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 diff --git a/admin/spec/components/previews/solidus_admin/orders/new/component_preview.rb b/admin/spec/components/previews/solidus_admin/orders/new/component_preview.rb new file mode 100644 index 00000000000..f402a1f9838 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/orders/new/component_preview.rb @@ -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 diff --git a/admin/spec/components/previews/solidus_admin/orders/new/component_preview/overview.html.erb b/admin/spec/components/previews/solidus_admin/orders/new/component_preview/overview.html.erb new file mode 100644 index 00000000000..e0fcfa4d526 --- /dev/null +++ b/admin/spec/components/previews/solidus_admin/orders/new/component_preview/overview.html.erb @@ -0,0 +1,3 @@ +
+ <%= render current_component.new(order: order) %> +
diff --git a/admin/spec/components/solidus_admin/orders/new/component_spec.rb b/admin/spec/components/solidus_admin/orders/new/component_spec.rb new file mode 100644 index 00000000000..6f61edbc87e --- /dev/null +++ b/admin/spec/components/solidus_admin/orders/new/component_spec.rb @@ -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