diff --git a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb index dbf81e61c38..71f3a450143 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb index a7ae5b6b6db..520007d4a0b 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -18,7 +18,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_adjustment_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -26,7 +26,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -52,7 +52,7 @@ def columns data: ->(adjustment_reason) do link_to adjustment_reason.name, edit_path(adjustment_reason), class: 'body-link', - data: { turbo_frame: :resource_modal } + data: { turbo_frame: :resource_form } end }, { @@ -60,7 +60,7 @@ def columns data: ->(adjustment_reason) do link_to adjustment_reason.code, edit_path(adjustment_reason), class: 'body-link', - data: { turbo_frame: :resource_modal } + data: { turbo_frame: :resource_form } end }, { diff --git a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb index dbf81e61c38..71f3a450143 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/layout/page_helpers.rb b/admin/app/components/solidus_admin/layout/page_helpers.rb index 47bffa1f50a..20f580b7edc 100644 --- a/admin/app/components/solidus_admin/layout/page_helpers.rb +++ b/admin/app/components/solidus_admin/layout/page_helpers.rb @@ -13,13 +13,7 @@ def page_header_actions(&block) end def page_header_back(back_path) - render component("ui/button").new( - tag: :a, - title: t(".back"), - icon: "arrow-left-line", - scheme: :secondary, - href: back_path - ) + render component("ui/button").back(path: back_path) end def page_header_title(title, &block) diff --git a/admin/app/components/solidus_admin/orders/show/address/component.html.erb b/admin/app/components/solidus_admin/orders/show/address/component.html.erb index dcbdef65c4a..0941160f0b6 100644 --- a/admin/app/components/solidus_admin/orders/show/address/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/address/component.html.erb @@ -50,11 +50,7 @@ ) %> - <%= render component("ui/button").new( - tag: :button, - text: t(".save"), - form: form_id - ) %> + <%= render component("ui/button").save(form: form_id) %> <% end %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/orders/show/address/component.yml b/admin/app/components/solidus_admin/orders/show/address/component.yml index 4d9d520d688..16b0b61d372 100644 --- a/admin/app/components/solidus_admin/orders/show/address/component.yml +++ b/admin/app/components/solidus_admin/orders/show/address/component.yml @@ -1,5 +1,4 @@ en: - save: Save cancel: Cancel back: Back select_address: Select address diff --git a/admin/app/components/solidus_admin/orders/show/component.html.erb b/admin/app/components/solidus_admin/orders/show/component.html.erb index e2cdc78df48..2641a49f389 100644 --- a/admin/app/components/solidus_admin/orders/show/component.html.erb +++ b/admin/app/components/solidus_admin/orders/show/component.html.erb @@ -3,8 +3,8 @@ <%= page_header_back(solidus_admin.orders_path) %> <%= page_header_title(t('.title', number: @order.number)) %> <%= page_header_actions do %> - <%= 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) %> + <%= render component("ui/button").discard(path: solidus_admin.orders_path) %> + <%= render component("ui/button").save(form: form_id) %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/orders/show/component.yml b/admin/app/components/solidus_admin/orders/show/component.yml index 497a0186ab2..95edb7b7b29 100644 --- a/admin/app/components/solidus_admin/orders/show/component.yml +++ b/admin/app/components/solidus_admin/orders/show/component.yml @@ -1,11 +1,8 @@ en: - save: Save - discard: Discard title: "Order %{number}" customer: Customer no_name: No name available order_email: Order contact email - back: Back to orders same_as_shipping: Same as shipping address edit_email: "Edit order email" diff --git a/admin/app/components/solidus_admin/products/show/component.html.erb b/admin/app/components/solidus_admin/products/show/component.html.erb index f8095763f04..f1fcec1e7e2 100644 --- a/admin/app/components/solidus_admin/products/show/component.html.erb +++ b/admin/app/components/solidus_admin/products/show/component.html.erb @@ -19,7 +19,7 @@ target: :_blank, scheme: :ghost ) %> - <%= render component("ui/button").new(tag: :button, text: t(".save"), form: form_id) %> + <%= render component("ui/button").save(form: form_id) %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/products/show/component.yml b/admin/app/components/solidus_admin/products/show/component.yml index 58a100b8332..6d6d7cc1b9d 100644 --- a/admin/app/components/solidus_admin/products/show/component.yml +++ b/admin/app/components/solidus_admin/products/show/component.yml @@ -1,6 +1,4 @@ en: - save: "Save" - back: "Back" duplicate: "Duplicate" view: "View online" delete: "Delete" diff --git a/admin/app/components/solidus_admin/properties/edit/component.html.erb b/admin/app/components/solidus_admin/properties/edit/component.html.erb index b2a90586684..cf56ae99a60 100644 --- a/admin/app/components/solidus_admin/properties/edit/component.html.erb +++ b/admin/app/components/solidus_admin/properties/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/properties/index/component.rb b/admin/app/components/solidus_admin/properties/index/component.rb index 9782ba2e624..e902f80aa16 100644 --- a/admin/app/components/solidus_admin/properties/index/component.rb +++ b/admin/app/components/solidus_admin/properties/index/component.rb @@ -22,7 +22,7 @@ def edit_path(property) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -30,7 +30,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_property_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -58,7 +58,7 @@ def name_column header: :name, data: ->(property) do link_to property.name, edit_path(property), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -69,7 +69,7 @@ def presentation_column header: :presentation, data: ->(property) do link_to property.presentation, edit_path(property), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/admin/app/components/solidus_admin/properties/new/component.html.erb b/admin/app/components/solidus_admin/properties/new/component.html.erb index b2a90586684..cf56ae99a60 100644 --- a/admin/app/components/solidus_admin/properties/new/component.html.erb +++ b/admin/app/components/solidus_admin/properties/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb index 0d7249ab394..3d4f41ddaec 100644 --- a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.rb b/admin/app/components/solidus_admin/refund_reasons/index/component.rb index 62d4f6b9d06..01c4046fd0a 100644 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -19,7 +19,7 @@ def edit_path(refund_reason) def turbo_frames %w[ - resource_modal + resource_form ] end @@ -28,7 +28,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_refund_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -51,7 +51,7 @@ def columns header: :name, data: ->(refund_reason) do link_to refund_reason.name, edit_path(refund_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -59,7 +59,7 @@ def columns header: :code, data: ->(refund_reason) do link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb index 0d7249ab394..3d4f41ddaec 100644 --- a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb index 0feb9fc3597..a6422ca8b09 100644 --- a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.rb b/admin/app/components/solidus_admin/return_reasons/index/component.rb index 594eac21696..e8fb147dd7a 100644 --- a/admin/app/components/solidus_admin/return_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb @@ -19,7 +19,7 @@ def edit_path(return_reason) def turbo_frames %w[ - resource_modal + resource_form ] end @@ -28,7 +28,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_return_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -51,7 +51,7 @@ def columns header: :name, data: ->(return_reason) do link_to return_reason.name, edit_path(return_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/return_reasons/new/component.html.erb b/admin/app/components/solidus_admin/return_reasons/new/component.html.erb index 0feb9fc3597..a6422ca8b09 100644 --- a/admin/app/components/solidus_admin/return_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/roles/edit/component.html.erb b/admin/app/components/solidus_admin/roles/edit/component.html.erb index ff14e0363df..481132339aa 100644 --- a/admin/app/components/solidus_admin/roles/edit/component.html.erb +++ b/admin/app/components/solidus_admin/roles/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @role, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/roles/index/component.rb b/admin/app/components/solidus_admin/roles/index/component.rb index 97ce166278a..4a8f513301e 100644 --- a/admin/app/components/solidus_admin/roles/index/component.rb +++ b/admin/app/components/solidus_admin/roles/index/component.rb @@ -22,14 +22,14 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_role_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end def turbo_frames %w[ - resource_modal + resource_form ] end @@ -61,7 +61,7 @@ def columns header: :role, data: ->(role) do link_to role.name, edit_path(role), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end, }, @@ -69,7 +69,7 @@ def columns header: :description, data: ->(role) do link_to_if role.description, role.description, edit_path(role), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end } diff --git a/admin/app/components/solidus_admin/roles/new/component.html.erb b/admin/app/components/solidus_admin/roles/new/component.html.erb index 3216408ea58..a921f2e2d27 100644 --- a/admin/app/components/solidus_admin/roles/new/component.html.erb +++ b/admin/app/components/solidus_admin/roles/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @role, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb index b3e1b61981a..69b2ee08f8e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb +++ b/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @shipping_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/shipping_categories/index/component.rb b/admin/app/components/solidus_admin/shipping_categories/index/component.rb index 2302b16417e..2c303296914 100644 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/index/component.rb @@ -10,7 +10,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_shipping_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -18,7 +18,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(shipping_category) do link_to shipping_category.name, edit_url(shipping_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end }, diff --git a/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb index b3e1b61981a..69b2ee08f8e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb +++ b/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @shipping_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/stock_items/edit/component.html.erb b/admin/app/components/solidus_admin/stock_items/edit/component.html.erb index a0faf887296..c6d9725b49f 100644 --- a/admin/app/components/solidus_admin/stock_items/edit/component.html.erb +++ b/admin/app/components/solidus_admin/stock_items/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @stock_item, url: form_url, html: { id: form_id } do |f| %>
(stock_item) do link_to stock_item.variant.name, edit_path(stock_item), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -102,7 +102,7 @@ def sku_column header: :sku, data: ->(stock_item) do link_to stock_item.variant.sku, edit_path(stock_item), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -172,6 +172,6 @@ def count_on_hand_column end def turbo_frames - %w[resource_modal] + %w[resource_form] end end diff --git a/admin/app/components/solidus_admin/stock_locations/edit/component.html.erb b/admin/app/components/solidus_admin/stock_locations/edit/component.html.erb new file mode 100644 index 00000000000..746c2d40e6a --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/edit/component.html.erb @@ -0,0 +1,16 @@ +<%= page id: :resource_form do %> + <%= page_header do %> + <%= page_header_back(back_url) %> + <%= page_header_title(t('.title')) %> + <%= page_header_actions do %> + <%= render component("ui/button").discard(path: back_url) %> + <%= render component("ui/button").save(form: form_id) %> + <% end %> + <% end %> + + <%= render component("stock_locations/form").new(stock_location: @stock_location, url: form_url, id: form_id) %> + + <%= page_footer do %> + <%= render component("ui/button").save(form: form_id) %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/stock_locations/edit/component.rb b/admin/app/components/solidus_admin/stock_locations/edit/component.rb new file mode 100644 index 00000000000..1f6dbe7d4cb --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/edit/component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class SolidusAdmin::StockLocations::Edit::Component < SolidusAdmin::Resources::Edit::Component + include SolidusAdmin::Layout::PageHelpers +end diff --git a/admin/app/components/solidus_admin/stock_locations/edit/component.yml b/admin/app/components/solidus_admin/stock_locations/edit/component.yml new file mode 100644 index 00000000000..c9831f69080 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/edit/component.yml @@ -0,0 +1,2 @@ +en: + title: "Edit Stock Location" diff --git a/admin/app/components/solidus_admin/stock_locations/form/component.html.erb b/admin/app/components/solidus_admin/stock_locations/form/component.html.erb new file mode 100644 index 00000000000..6faa1678c98 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/form/component.html.erb @@ -0,0 +1,65 @@ +<%= form_for @stock_location, url: @url, html: { id: @id } do |f| %> + <%= page_with_sidebar do %> + <%= page_with_sidebar_main do %> + <%= render component('ui/panel').new do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :admin_name) %> +
+ <%= render component("ui/forms/field").text_field(f, :code) %> + <% end %> + <% end %> + + <%= render component('ui/panel').new(title: t('.address')) do %> + <%= render component('ui/forms/address').new(addressable: @stock_location, form_field_name: 'stock_location', fieldset: :location, excludes: %i[phone email]) %> + <% end %> + + <%= render component('ui/panel').new(title: t('.contact_info')) do %> + <%= render component('ui/forms/address').new(addressable: @stock_location, form_field_name: 'stock_location', fieldset: :contact_info) %> + <% end %> + <% end %> + + <%= page_with_sidebar_aside do %> + <%= render component('ui/panel').new(title: t('.availability')) do %> + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :active, checked: f.object.active) do |checkbox| %> + <%= checkbox.with_label(text: t(".active")) %> + <%= checkbox.with_hint(text: t(".hints.active")) %> + <% end %> + <% end %> + + <%= render component('ui/panel').new(title: t('.setup')) do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :default, checked: f.object.default) do |checkbox| %> + <%= checkbox.with_label(text: t(".default")) %> + <% end %> + + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :backorderable_default, checked: f.object.backorderable_default) do |checkbox| %> + <%= checkbox.with_label(text: t(".backorderable_default")) %> + <%= checkbox.with_hint(text: t(".hints.backorderable_default")) %> + <% end %> + + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :propagate_all_variants, checked: f.object.propagate_all_variants) do |checkbox| %> + <%= checkbox.with_label(text: t(".propagate_all_variants")) %> + <%= checkbox.with_hint(text: t(".hints.propagate_all_variants")) %> + <% end %> + + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :restock_inventory, checked: f.object.restock_inventory) do |checkbox| %> + <%= checkbox.with_label(text: t(".restock_inventory")) %> + <%= checkbox.with_hint(text: t(".hints.restock_inventory")) %> + <% end %> + + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :fulfillable, checked: f.object.fulfillable) do |checkbox| %> + <%= checkbox.with_label(text: t(".fulfillable")) %> + <%= checkbox.with_hint(text: t(".hints.fulfillable")) %> + <% end %> + + <%= render component("ui/forms/checkbox").new(object_name: f.object_name, method: :check_stock_on_transfer, checked: f.object.check_stock_on_transfer) do |checkbox| %> + <%= checkbox.with_label(text: t(".check_stock_on_transfer")) %> + <%= checkbox.with_hint(text: t(".hints.check_stock_on_transfer")) %> + <% end %> + <% end %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/stock_locations/form/component.rb b/admin/app/components/solidus_admin/stock_locations/form/component.rb new file mode 100644 index 00000000000..5b5d4394518 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/form/component.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class SolidusAdmin::StockLocations::Form::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(stock_location:, id:, url:) + @stock_location = stock_location + @id = id + @url = url + end +end diff --git a/admin/app/components/solidus_admin/stock_locations/form/component.yml b/admin/app/components/solidus_admin/stock_locations/form/component.yml new file mode 100644 index 00000000000..7734f44e625 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/form/component.yml @@ -0,0 +1,19 @@ +en: + active: "Active" + address: "Address" + availability: "Availability" + backorderable_default: "Backorderable default" + check_stock_on_transfer: "Check stock on transfer" + contact_info: "Contact information" + default: "Set as default for all products" + fulfillable: "Fulfillable" + hints: + active: "This determines whether stock from this location can be used when building packages" + backorderable_default: "When checked, stock items in this location will default to allowing backorders" + check_stock_on_transfer: "When checked, inventory levels will be checked when performing stock transfers" + fulfillable: "When unchecked, this indicates that items in this location don't require actual fulfilment. Stock will not be checked when shipping and emails will not be sent" + propagate_all_variants: "When checked, this will create a stock item for each variant in this stock location" + restock_inventory: "When checked, returned inventory can be added back to this location's stock levels" + propagate_all_variants: "Propagate all variants" + restock_inventory: "Restock inventory" + setup: "Setup" diff --git a/admin/app/components/solidus_admin/stock_locations/index/component.rb b/admin/app/components/solidus_admin/stock_locations/index/component.rb index f6324732666..53f2482bdf6 100644 --- a/admin/app/components/solidus_admin/stock_locations/index/component.rb +++ b/admin/app/components/solidus_admin/stock_locations/index/component.rb @@ -5,20 +5,16 @@ def model_class Spree::StockLocation end - def actions + def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: spree.new_admin_stock_location_path, + href: solidus_admin.new_stock_location_path, icon: "add-line", class: "align-self-end w-full", ) end - def row_url(stock_location) - spree.edit_admin_stock_location_path(stock_location) - end - def search_url solidus_admin.stock_locations_path end @@ -27,6 +23,10 @@ def search_key :name_or_description_cont end + def edit_path(stock_location) + solidus_admin.edit_stock_location_path(stock_location) + end + def batch_actions [ { @@ -48,42 +48,89 @@ def filters def columns [ - :name, - :code, - :admin_name, - { - header: :state, - data: -> { - color = _1.active? ? :green : :graphite_light - text = _1.active? ? t('.active') : t('.inactive') - - component('ui/badge').new(name: text, color:) - }, - }, - { - header: :backorderable, - data: -> { - _1.backorderable_default ? component('ui/badge').yes : component('ui/badge').no - } - }, - { - header: :default, - data: -> { - _1.default ? component('ui/badge').yes : component('ui/badge').no - } - }, - { - header: :stock_movements, - data: -> { - count = _1.stock_movements.count - - link_to( - "#{count} #{Spree::StockMovement.model_name.human(count:).downcase}", - spree.admin_stock_location_stock_movements_path(_1), - class: 'body-link' - ) - } - } + name_column, + code_column, + admin_name_column, + state_column, + backorderable_column, + default_column, + stock_movements_column, ] end + + private + + def name_column + { + header: :name, + data: ->(stock_location) do + link_to stock_location.name, edit_path(stock_location), class: 'body-link' + end + } + end + + def code_column + { + header: :code, + data: ->(stock_location) do + return if stock_location.code.blank? + link_to stock_location.code, edit_path(stock_location), class: 'body-link' + end + } + end + + def admin_name_column + { + header: :admin_name, + data: ->(stock_location) do + return if stock_location.admin_name.blank? + link_to stock_location.admin_name, edit_path(stock_location), class: 'body-link' + end + } + end + + def state_column + { + header: :state, + data: ->(stock_location) do + color = stock_location.active? ? :green : :graphite_light + text = stock_location.active? ? t('.active') : t('.inactive') + + component('ui/badge').new(name: text, color:) + end + } + end + + def backorderable_column + { + header: :backorderable, + data: -> do + _1.backorderable_default ? component('ui/badge').yes : component('ui/badge').no + end + } + end + + def default_column + { + header: :default, + data: -> do + _1.default ? component('ui/badge').yes : component('ui/badge').no + end + } + end + + def stock_movements_column + { + header: :stock_movements, + data: ->(stock_location) do + count = stock_location.stock_movements.count + + link_to( + "#{count} #{Spree::StockMovement.model_name.human(count:).downcase}", + spree.admin_stock_location_stock_movements_path(stock_location), + class: 'body-link' + ) + end + } + end end diff --git a/admin/app/components/solidus_admin/stock_locations/new/component.html.erb b/admin/app/components/solidus_admin/stock_locations/new/component.html.erb new file mode 100644 index 00000000000..746c2d40e6a --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/new/component.html.erb @@ -0,0 +1,16 @@ +<%= page id: :resource_form do %> + <%= page_header do %> + <%= page_header_back(back_url) %> + <%= page_header_title(t('.title')) %> + <%= page_header_actions do %> + <%= render component("ui/button").discard(path: back_url) %> + <%= render component("ui/button").save(form: form_id) %> + <% end %> + <% end %> + + <%= render component("stock_locations/form").new(stock_location: @stock_location, url: form_url, id: form_id) %> + + <%= page_footer do %> + <%= render component("ui/button").save(form: form_id) %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/stock_locations/new/component.rb b/admin/app/components/solidus_admin/stock_locations/new/component.rb new file mode 100644 index 00000000000..91934fb26d6 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/new/component.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class SolidusAdmin::StockLocations::New::Component < SolidusAdmin::Resources::New::Component + include SolidusAdmin::Layout::PageHelpers + + def initialize(*args) + super(*args) + ensure_country + end + + private + + def ensure_country + @stock_location.country.blank? && (@stock_location.country = Spree::Country.default) + end +end diff --git a/admin/app/components/solidus_admin/stock_locations/new/component.yml b/admin/app/components/solidus_admin/stock_locations/new/component.yml new file mode 100644 index 00000000000..b59b7080b55 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/new/component.yml @@ -0,0 +1,2 @@ +en: + title: "New Stock Location" diff --git a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb index 6c5109803a1..0d2318b3006 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb index 632c314147d..c1186925d28 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb @@ -10,7 +10,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_store_credit_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -18,7 +18,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(store_credit_reason) do link_to store_credit_reason.name, edit_path(store_credit_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb index 6c5109803a1..0d2318b3006 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb index e15da96d8c6..a117dfc2038 100644 --- a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb +++ b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.rb b/admin/app/components/solidus_admin/tax_categories/index/component.rb index 2937b3b2942..d7d2f40567c 100644 --- a/admin/app/components/solidus_admin/tax_categories/index/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/index/component.rb @@ -18,7 +18,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_tax_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -26,7 +26,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(tax_category) do link_to tax_category.name, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -59,7 +59,7 @@ def columns header: :tax_code, data: ->(tax_category) do link_to_if tax_category.tax_code, tax_category.tax_code, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -67,7 +67,7 @@ def columns header: :description, data: ->(tax_category) do link_to_if tax_category.description, tax_category.description, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/tax_categories/new/component.html.erb b/admin/app/components/solidus_admin/tax_categories/new/component.html.erb index e15da96d8c6..a117dfc2038 100644 --- a/admin/app/components/solidus_admin/tax_categories/new/component.html.erb +++ b/admin/app/components/solidus_admin/tax_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/ui/button/component.rb b/admin/app/components/solidus_admin/ui/button/component.rb index 4a0d9811381..655bc3082f3 100644 --- a/admin/app/components/solidus_admin/ui/button/component.rb +++ b/admin/app/components/solidus_admin/ui/button/component.rb @@ -63,6 +63,31 @@ class SolidusAdmin::UI::Button::Component < SolidusAdmin::BaseComponent }, } + def self.back(path:, **options) + new( + tag: :a, + title: t(".back"), + icon: "arrow-left-line", + scheme: :secondary, + href: path, + **options + ) + end + + def self.discard(path:, **options) + new( + tag: :a, + text: t(".discard"), + scheme: :secondary, + href: path, + **options + ) + end + + def self.save(**options) + new(text: t(".save"), **options) + end + def initialize( tag: :button, text: nil, diff --git a/admin/app/components/solidus_admin/ui/button/component.yml b/admin/app/components/solidus_admin/ui/button/component.yml index 5fa6738fcaa..37791778141 100644 --- a/admin/app/components/solidus_admin/ui/button/component.yml +++ b/admin/app/components/solidus_admin/ui/button/component.yml @@ -1,5 +1,8 @@ en: + back: "Back" cancel: "Cancel" + discard: "Discard" + save: "Save" submit: create: "Add %{resource_name}" update: "Update %{resource_name}" diff --git a/admin/app/components/solidus_admin/ui/forms/address/fieldsets/contact_info/component.rb b/admin/app/components/solidus_admin/ui/forms/address/fieldsets/contact_info/component.rb new file mode 100644 index 00000000000..f9447404683 --- /dev/null +++ b/admin/app/components/solidus_admin/ui/forms/address/fieldsets/contact_info/component.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class SolidusAdmin::UI::Forms::Address::Fieldsets::ContactInfo::Component < SolidusAdmin::UI::Forms::Address::Fieldsets::Base + def fields_map + { + phone: -> { component("ui/forms/field").text_field(@form_field_name, :phone, object: @addressable) }, + email: -> { component("ui/forms/field").text_field(@form_field_name, :email, object: @addressable) }, + } + end +end diff --git a/admin/app/components/solidus_admin/users/addresses/component.yml b/admin/app/components/solidus_admin/users/addresses/component.yml index d8759277b7d..72408eadad0 100644 --- a/admin/app/components/solidus_admin/users/addresses/component.yml +++ b/admin/app/components/solidus_admin/users/addresses/component.yml @@ -3,6 +3,5 @@ en: create_order_for_user: Create order for this user update: Update cancel: Cancel - back: Back billing_address: Billing Address shipping_address: Shipping Address diff --git a/admin/app/components/solidus_admin/users/edit/component.yml b/admin/app/components/solidus_admin/users/edit/component.yml index 53de7d80121..3fbcb9b304f 100644 --- a/admin/app/components/solidus_admin/users/edit/component.yml +++ b/admin/app/components/solidus_admin/users/edit/component.yml @@ -3,4 +3,3 @@ en: create_order_for_user: Create order for this user update: Update cancel: Cancel - back: Back diff --git a/admin/app/components/solidus_admin/users/items/component.yml b/admin/app/components/solidus_admin/users/items/component.yml index 5beecc69b95..f6416a2922d 100644 --- a/admin/app/components/solidus_admin/users/items/component.yml +++ b/admin/app/components/solidus_admin/users/items/component.yml @@ -4,7 +4,6 @@ en: items_purchased: Items Purchased no_orders_found: No Orders found. create_one: Create One - back: Back number_column_header: "Order #" description_column_header: "Description" total_column_header: "Total" diff --git a/admin/app/components/solidus_admin/users/orders/component.yml b/admin/app/components/solidus_admin/users/orders/component.yml index ce7dfe7113f..2b60315e54a 100644 --- a/admin/app/components/solidus_admin/users/orders/component.yml +++ b/admin/app/components/solidus_admin/users/orders/component.yml @@ -4,4 +4,3 @@ en: create_order_for_user: Create order for this user no_orders_found: No Orders found. create_one: Create One - back: Back diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb index bcdb44d7299..be81828c8e8 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb index 54ce226b3a4..e283df9bd7f 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb index 051eb18c78d..0af593f5d42 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb index 41799abddbd..c619d713c9a 100644 --- a/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb @@ -8,7 +8,7 @@ tag: :a, href: new_store_credit_path, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, text: t(".add_store_credit"), icon: "add-line" @@ -45,7 +45,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: new_store_credit_path, text: t(".create_one"), @@ -59,5 +59,5 @@ <% end %> <% end %> - <%= turbo_frame_tag :resource_modal, target: "_top" %> + <%= turbo_frame_tag :resource_form, target: "_top" %> <% end %> diff --git a/admin/app/components/solidus_admin/users/store_credits/index/component.yml b/admin/app/components/solidus_admin/users/store_credits/index/component.yml index 272bb089ec2..a541c1ec6a3 100644 --- a/admin/app/components/solidus_admin/users/store_credits/index/component.yml +++ b/admin/app/components/solidus_admin/users/store_credits/index/component.yml @@ -4,4 +4,3 @@ en: add_store_credit: Add Store Credit no_credits_found: No Store Credits found. create_one: Create One - back: Back diff --git a/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb index e5cc0ed6623..ca6f64f5af2 100644 --- a/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :post, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb index 8232ff9c879..887ea309db5 100644 --- a/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb @@ -29,7 +29,7 @@ tag: :a, scheme: :danger, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_validity_url, text: t(".invalidate"), @@ -39,7 +39,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_memo_url, text: t(".edit_memo"), @@ -49,7 +49,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_amount_url, text: t(".edit_amount"), @@ -77,5 +77,5 @@ <% end %> <% end %> - <%= turbo_frame_tag :resource_modal, target: "_top" %> + <%= turbo_frame_tag :resource_form, target: "_top" %> <% end %> diff --git a/admin/app/components/solidus_admin/users/store_credits/show/component.yml b/admin/app/components/solidus_admin/users/store_credits/show/component.yml index 4f3bbc4c20f..71d86eed23b 100644 --- a/admin/app/components/solidus_admin/users/store_credits/show/component.yml +++ b/admin/app/components/solidus_admin/users/store_credits/show/component.yml @@ -10,4 +10,3 @@ en: created_by: Created By type: Type memo: Memo - back: Back diff --git a/admin/app/components/solidus_admin/zones/form/component.html.erb b/admin/app/components/solidus_admin/zones/form/component.html.erb index 3fdfecb436b..c96c26a1075 100644 --- a/admin/app/components/solidus_admin/zones/form/component.html.erb +++ b/admin/app/components/solidus_admin/zones/form/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title:) do |modal| %> <%= form_for @zone, url: @form_url, html: { id: @form_id, **stimulus_controller, **stimulus_value(name: :kind, value: @zone.kind) } do |f| %>
diff --git a/admin/app/components/solidus_admin/zones/index/component.rb b/admin/app/components/solidus_admin/zones/index/component.rb index 33390df6bea..747bf3399d1 100644 --- a/admin/app/components/solidus_admin/zones/index/component.rb +++ b/admin/app/components/solidus_admin/zones/index/component.rb @@ -22,7 +22,7 @@ def edit_path(zone) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -30,7 +30,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_zone_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -69,7 +69,7 @@ def name_column header: :name, data: ->(zone) do link_to zone.name, edit_path(zone), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -80,7 +80,7 @@ def description_column header: :description, data: ->(zone) do link_to zone.description, edit_path(zone), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index b4656a2f5d2..19f93fe10c9 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -133,7 +133,7 @@ def render_resource_form_with_errors(page_component) render page_component, status: :unprocessable_entity end format.turbo_stream do - render turbo_stream: turbo_stream.replace(:resource_modal, page_component), + render turbo_stream: turbo_stream.replace(resource_form_frame, page_component), status: :unprocessable_entity end end @@ -165,5 +165,9 @@ def blueprint_view raise NotImplementedError, "You must implement the blueprint_view method in #{self.class}" end + + def resource_form_frame + :resource_form + end end end diff --git a/admin/app/controllers/solidus_admin/stock_locations_controller.rb b/admin/app/controllers/solidus_admin/stock_locations_controller.rb index 445c4ec25b0..1d27d04cab9 100644 --- a/admin/app/controllers/solidus_admin/stock_locations_controller.rb +++ b/admin/app/controllers/solidus_admin/stock_locations_controller.rb @@ -1,35 +1,34 @@ # frozen_string_literal: true module SolidusAdmin - class StockLocationsController < SolidusAdmin::BaseController - include SolidusAdmin::ControllerHelpers::Search + class StockLocationsController < SolidusAdmin::ResourcesController + private - def index - stock_locations = apply_search_to( - Spree::StockLocation.order(id: :desc), - param: :q, + def resource_class = Spree::StockLocation + + def permitted_resource_params + params.require(:stock_location).permit( + :name, + :admin_name, + :code, + :address1, + :address2, + :city, :zipcode, + :country_id, + :state_name, + :state_id, + :phone, + :email, + :active, + :default, + :backorderable_default, + :propagate_all_variants, + :restock_inventory, + :fulfillable, + :check_stock_on_transfer ) - - set_page_and_extract_portion_from(stock_locations) - - respond_to do |format| - format.html { render component('stock_locations/index').new(page: @page) } - end - end - - def destroy - @stock_locations = Spree::StockLocation.where(id: params[:id]) - - Spree::StockLocation.transaction { @stock_locations.destroy_all } - - flash[:notice] = t('.success') - redirect_back_or_to stock_locations_path, status: :see_other end - private - - def stock_location_params - params.require(:stock_location).permit(:stock_location_id, permitted_stock_location_attributes) - end + def resources_collection = Spree::StockLocation.unscoped end end diff --git a/admin/config/locales/stock_locations.en.yml b/admin/config/locales/stock_locations.en.yml index 5c365e48372..7607f089ca9 100644 --- a/admin/config/locales/stock_locations.en.yml +++ b/admin/config/locales/stock_locations.en.yml @@ -2,5 +2,9 @@ en: solidus_admin: stock_locations: title: "Stock Locations" + create: + success: "Stock location was successfully created." destroy: success: "Stock locations were successfully removed." + update: + success: "Stock location was successfully updated." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index ec215522965..57306812340 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -78,7 +78,7 @@ admin_resources :stock_items, only: [:index, :edit, :update] admin_resources :shipping_methods, only: [:index, :destroy] admin_resources :shipping_categories, except: [:show] - admin_resources :stock_locations, only: [:index, :destroy] + admin_resources :stock_locations, except: [:show] admin_resources :stores, only: [:index, :destroy] admin_resources :zones, except: [:show] admin_resources :refund_reasons, except: [:show] diff --git a/admin/lib/solidus_admin/testing_support/feature_helpers.rb b/admin/lib/solidus_admin/testing_support/feature_helpers.rb index 6f28ad553cb..bf47f18d52c 100644 --- a/admin/lib/solidus_admin/testing_support/feature_helpers.rb +++ b/admin/lib/solidus_admin/testing_support/feature_helpers.rb @@ -61,6 +61,10 @@ def clear_search find('button[aria-label="Clear"]').click end end + + def solidus_select_control(field) + find_field(field, visible: :all).ancestor(".control") + end end end end diff --git a/admin/spec/components/solidus_admin/ui/button/component_spec.rb b/admin/spec/components/solidus_admin/ui/button/component_spec.rb index 4eda5fab23a..cfaf018417c 100644 --- a/admin/spec/components/solidus_admin/ui/button/component_spec.rb +++ b/admin/spec/components/solidus_admin/ui/button/component_spec.rb @@ -39,4 +39,32 @@ expect(page).to have_content("Cancel") end end + + describe ".back" do + let(:component) { described_class.back(path: "/index") } + + it "renders Back button" do + render_inline(component) + expect(page).to have_link(href: '/index', title: 'Back') + end + end + + describe ".discard" do + let(:component) { described_class.discard(path: "/index") } + + it "renders Discard button" do + render_inline(component) + expect(page).to have_link(href: '/index') + expect(page).to have_content("Discard") + end + end + + describe ".save" do + let(:component) { described_class.save } + + it "renders Save button" do + render_inline(component) + expect(page).to have_button("Save") + end + end end diff --git a/admin/spec/features/stock_locations/form_spec.rb b/admin/spec/features/stock_locations/form_spec.rb new file mode 100644 index 00000000000..3f778ba2102 --- /dev/null +++ b/admin/spec/features/stock_locations/form_spec.rb @@ -0,0 +1,133 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Stock Location Form", :js, type: :feature do + before do + %w[US CA].each do |iso| + create(:country, iso:).tap { create(:state, country: _1, name: "Fictitious State in #{iso}") } + end + + sign_in create(:admin_user, email: 'admin@example.com') + visit "/admin/stock_locations" + click_on "Add new" + end + + it 'shows page with form for stock location' do + expect(page).to have_current_path(solidus_admin.new_stock_location_path) + expect(page).to have_content("New Stock Location") + expect(page).to have_content("Address") + expect(page).to have_content("Availability") + expect(page).to have_content("Setup") + expect(page).to have_content("Save", count: 2) + expect(page).to have_content("Discard") + expect(page).to be_axe_clean + end + + describe 'navigation buttons' do + it 'allows to go back' do + click_on 'Back' + expect(page).to have_current_path(solidus_admin.stock_locations_path) + end + + it 'allows to discard changes' do + click_on 'Discard' + expect(page).to have_current_path(solidus_admin.stock_locations_path) + end + end + + it "renders checkboxes with default values" do + expect(checkbox("Active")).to be_checked + expect(checkbox("Propagate all variants")).to be_checked + expect(checkbox("Restock inventory")).to be_checked + expect(checkbox("Fulfillable")).to be_checked + expect(checkbox("Check stock on transfer")).to be_checked + + expect(checkbox("Set as default for all products")).not_to be_checked + expect(checkbox("Backorderable default")).not_to be_checked + end + + it "preselects default country" do + expect(solidus_select_control("Country")).to have_content("United States") + end + + describe "submit" do + context "with valid inputs" do + it "saves changes" do + aggregate_failures do + fill_in "Name", with: "Warehouse" + fill_in "Internal Name", with: "warehouse" + fill_in "Code", with: "wrhs" + fill_in "Street Address", with: "Willow St." + fill_in "Street Address (cont'd)", with: "12/21" + fill_in "City", with: "12/21" + fill_in "Zip", with: "12-345" + solidus_select "Canada", from: "Country" + solidus_select "Fictitious State in CA", from: "State" + fill_in "Phone", with: "123123123" + fill_in "Email", with: "example@example.com" + check "Set as default for all products" + check "Backorderable default" + + within("header") { click_on "Save" } + + expect(page).to have_current_path(solidus_admin.stock_locations_path) + expect(page).to have_content("Stock location was successfully created.") + + click_on "Warehouse" + + expect(page).to have_current_path(solidus_admin.edit_stock_location_path(Spree::StockLocation.last)) + expect(find_field("Name").value).to eq "Warehouse" + expect(find_field("Internal Name").value).to eq "warehouse" + expect(find_field("Code").value).to eq "wrhs" + expect(find_field("Street Address").value).to eq "Willow St." + expect(find_field("Street Address (cont'd)").value).to eq "12/21" + expect(find_field("City").value).to eq "12/21" + expect(find_field("Zip").value).to eq "12-345" + expect(solidus_select_control("Country")).to have_content("Canada") + expect(solidus_select_control("State")).to have_content("Fictitious State in CA") + expect(find_field("Phone").value).to eq "123123123" + expect(find_field("Email").value).to eq "example@example.com" + expect(checkbox("Active")).to be_checked + expect(checkbox("Propagate all variants")).to be_checked + expect(checkbox("Restock inventory")).to be_checked + expect(checkbox("Fulfillable")).to be_checked + expect(checkbox("Check stock on transfer")).to be_checked + expect(checkbox("Set as default for all products")).to be_checked + expect(checkbox("Backorderable default")).to be_checked + + fill_in "Name", with: "Warehouse (inactive)" + uncheck "Active" + uncheck "Propagate all variants" + uncheck "Restock inventory" + uncheck "Fulfillable" + uncheck "Check stock on transfer" + uncheck "Set as default for all products" + uncheck "Backorderable default" + + within("header") { click_on "Save" } + + expect(page).to have_current_path(solidus_admin.stock_locations_path) + expect(page).to have_content("Stock location was successfully updated.") + + click_on "Warehouse (inactive)" + + expect(checkbox("Active")).not_to be_checked + expect(checkbox("Propagate all variants")).not_to be_checked + expect(checkbox("Restock inventory")).not_to be_checked + expect(checkbox("Fulfillable")).not_to be_checked + expect(checkbox("Check stock on transfer")).not_to be_checked + expect(checkbox("Set as default for all products")).not_to be_checked + expect(checkbox("Backorderable default")).not_to be_checked + end + end + end + + context "with invalid inputs" do + it "shows validation errors" do + within("header") { click_on "Save" } + expect(page).to have_content("can't be blank") + end + end + end +end diff --git a/admin/spec/features/stock_locations_spec.rb b/admin/spec/features/stock_locations/index_spec.rb similarity index 100% rename from admin/spec/features/stock_locations_spec.rb rename to admin/spec/features/stock_locations/index_spec.rb diff --git a/admin/spec/requests/solidus_admin/stock_locations_spec.rb b/admin/spec/requests/solidus_admin/stock_locations_spec.rb new file mode 100644 index 00000000000..7c3132b7d3d --- /dev/null +++ b/admin/spec/requests/solidus_admin/stock_locations_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "spec_helper" +require 'solidus_admin/testing_support/shared_examples/crud_resource_requests' + +RSpec.describe "SolidusAdmin::StockLocationsController", type: :request do + include_examples 'CRUD resource requests', 'stock_location' do + before { create(:country, iso: 'US') } + + let(:resource_class) { Spree::StockLocation } + let(:valid_attributes) { { name: "Warehouse" } } + let(:invalid_attributes) { { name: "" } } + end +end diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb index 35f8574f999..e8d0fa6ea81 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb @@ -14,7 +14,7 @@ def edit_path(record) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -22,7 +22,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_promotion_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -50,7 +50,7 @@ def name_column header: :name, data: ->(record) do link_to record.name, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -61,7 +61,7 @@ def code_column header: :code, data: ->(record) do link_to record.code, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb index d908005d267..9ff6b534244 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb @@ -14,7 +14,7 @@ def edit_path(record) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -22,7 +22,7 @@ def page_actions tag: :a, text: t(".add"), href: solidus_promotions.new_promotion_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line" ) end @@ -50,7 +50,7 @@ def name_column header: :name, data: ->(record) do link_to record.name, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -61,7 +61,7 @@ def code_column header: :code, data: ->(record) do link_to record.code, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>