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/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/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/stores/edit/component.html.erb b/admin/app/components/solidus_admin/stores/edit/component.html.erb new file mode 100644 index 00000000000..95aedb44e41 --- /dev/null +++ b/admin/app/components/solidus_admin/stores/edit/component.html.erb @@ -0,0 +1,27 @@ +<%= page id: :resource_form do %> + <%= page_header do %> + <%= page_header_back(back_url) %> + <%= page_header_title(@store.name) %> + <%= page_header_actions do %> + <%= render component("ui/button").discard(path: back_url) %> + <%= render component("ui/button").save(form: form_id) %> + <% end %> + <% end %> + + <%= render component("stores/form").new(store: @store, url: form_url, id: form_id) %> + + <%= page_footer do %> +
+ <% unless @store.default %> + <%= form_for @store, url: solidus_admin.store_path(@store), method: :delete do %> + <%= render component("ui/button").delete( + "data-controller": "confirm", + "data-confirm-text-value": t("spree.are_you_sure") + ) %> + <% end %> + <% end %> + + <%= render component("ui/button").save(form: form_id) %> +
+ <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/stores/edit/component.rb b/admin/app/components/solidus_admin/stores/edit/component.rb new file mode 100644 index 00000000000..a1608750ab8 --- /dev/null +++ b/admin/app/components/solidus_admin/stores/edit/component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class SolidusAdmin::Stores::Edit::Component < SolidusAdmin::Resources::Edit::Component + include SolidusAdmin::Layout::PageHelpers +end diff --git a/admin/app/components/solidus_admin/stores/form/component.html.erb b/admin/app/components/solidus_admin/stores/form/component.html.erb new file mode 100644 index 00000000000..f22c6c5328b --- /dev/null +++ b/admin/app/components/solidus_admin/stores/form/component.html.erb @@ -0,0 +1,90 @@ +<%= form_for @store, 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) %> + <%= render component("ui/forms/field").text_field(f, :code) %> + <%= render component("ui/forms/field").text_field(f, :url) %> + <%= render component("ui/forms/field").text_field(f, :mail_from_address) %> +
+ <% end %> + <% end %> + <%= render component('ui/panel').new(title: t('.localization')) do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> +
+ <%= render component("ui/forms/field").select(f, :default_currency, Spree::Config.available_currencies.map(&:iso_code)) %> + <%= render component("ui/forms/field").select(f, :cart_tax_country_iso, Spree::Country.order(:name).map { |c| [c.name, c.iso] }, + include_blank: t(".tax_country.no_taxes_without_address") + ) %> + <%= render component("ui/forms/field").select(f, :available_locales, available_locales, multiple: true) %> +
+ <%= render component('ui/panel').new do |inner_panel| %> + <% inner_panel.with_section(class: "flex justify-between") do %> +
+
+ <%= render component("ui/icon").new(name: "github-fill", class: "w-9 h-9 fill-gray-500") %> +
+
+
+
<%= t(".plugins.solidus_i18n.title") %>
+ <%= render component("ui/badge").new(name: t(".plugins.plugin"), color: :blue, size: :s) %> +
+
<%= t(".plugins.solidus_i18n.desc") %>
+
+
+
+ <%= render component("ui/button").new( + tag: :a, + text: t(".plugins.install"), + scheme: :secondary, + href: t(".plugins.solidus_i18n.href"), + target: "_blank" + ) %> +
+ <% end %> + <% end %> + + <%= render component('ui/panel').new do |inner_panel| %> + <% inner_panel.with_section(class: "flex justify-between") do %> +
+
+ <%= render component("ui/icon").new(name: "github-fill", class: "w-9 h-9 fill-gray-500") %> +
+
+
+
<%= t(".plugins.solidus_globalize.title") %>
+ <%= render component("ui/badge").new(name: t(".plugins.plugin"), color: :blue, size: :s) %> +
+
<%= t(".plugins.solidus_globalize.desc") %>
+
+
+
+ <%= render component("ui/button").new( + tag: :a, + text: t(".plugins.install"), + scheme: :secondary, + href: t(".plugins.solidus_globalize.href"), + target: "_blank" + ) %> +
+ <% end %> + <% end %> + <% end %> + <% end %> + <% end %> + + <%= page_with_sidebar_aside do %> + <%= render component('ui/panel').new(title: t('.seo')) do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> +
+ <%= render component("ui/forms/field").text_field(f, :seo_title) %> + <%= render component("ui/forms/field").text_field(f, :meta_keywords) %> + <%= render component("ui/forms/field").text_field(f, :meta_description) %> +
+ <% end %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/stores/form/component.rb b/admin/app/components/solidus_admin/stores/form/component.rb new file mode 100644 index 00000000000..6adddc55355 --- /dev/null +++ b/admin/app/components/solidus_admin/stores/form/component.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class SolidusAdmin::Stores::Form::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(store:, id:, url:) + @store = store + @id = id + @url = url + end + + def available_locales + Spree.i18n_available_locales.map do |locale| + [I18n.t('spree.i18n.this_file_language', locale: locale, default: locale.to_s, fallback: false), locale] + end.sort + end +end diff --git a/admin/app/components/solidus_admin/stores/form/component.yml b/admin/app/components/solidus_admin/stores/form/component.yml new file mode 100644 index 00000000000..9f8ce0ff5b5 --- /dev/null +++ b/admin/app/components/solidus_admin/stores/form/component.yml @@ -0,0 +1,16 @@ +en: + localization: Localization + plugins: + install: Install + plugin: Plugin + solidus_i18n: + href: https://github.com/solidusio/solidus_i18n + desc: Translate Solidus Admin in every language + title: Solidus i18n + solidus_globalize: + href: https://github.com/solidusio-contrib/solidus_globalize + desc: Translate your store content in every language + title: Solidus Globalize + seo: SEO + tax_country: + no_taxes_without_address: No taxes on carts without address diff --git a/admin/app/components/solidus_admin/stores/index/component.rb b/admin/app/components/solidus_admin/stores/index/component.rb index 5df8aa80005..33d599429a4 100644 --- a/admin/app/components/solidus_admin/stores/index/component.rb +++ b/admin/app/components/solidus_admin/stores/index/component.rb @@ -13,15 +13,15 @@ def search_url solidus_admin.stores_path end - def row_url(store) - spree.edit_admin_store_path(store) + def edit_path(store) + solidus_admin.edit_store_path(store) end def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: spree.new_admin_store_path, + href: solidus_admin.new_store_path, icon: "add-line", ) end @@ -33,26 +33,55 @@ def batch_actions action: solidus_admin.stores_path, method: :delete, icon: 'delete-bin-7-line', + require_confirmation: true, }, ] end def columns [ - :name, - :url, - { - header: :slug, - data: ->(store) do - content_tag :div, store.code - end - }, - { - header: :default, - data: ->(store) do - store.default? ? component('ui/badge').yes : component('ui/badge').no - end - }, + name_column, + url_column, + slug_column, + default_column, ] end + + private + + def name_column + { + header: :name, + data: ->(store) do + link_to store.name, edit_path(store), class: 'body-link' + end + } + end + + def url_column + { + header: :url, + data: ->(store) do + link_to store.url, edit_path(store), class: 'body-link' + end + } + end + + def slug_column + { + header: :slug, + data: ->(store) do + link_to store.code, edit_path(store), class: 'body-link' + end + } + end + + def default_column + { + header: :default, + data: ->(store) do + store.default? ? component('ui/badge').yes : component('ui/badge').no + end + } + end end diff --git a/admin/app/components/solidus_admin/stores/new/component.html.erb b/admin/app/components/solidus_admin/stores/new/component.html.erb new file mode 100644 index 00000000000..2de62438a2e --- /dev/null +++ b/admin/app/components/solidus_admin/stores/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("stores/form").new(store: @store, 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/stores/new/component.rb b/admin/app/components/solidus_admin/stores/new/component.rb new file mode 100644 index 00000000000..ec78f2543a1 --- /dev/null +++ b/admin/app/components/solidus_admin/stores/new/component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class SolidusAdmin::Stores::New::Component < SolidusAdmin::Resources::New::Component + include SolidusAdmin::Layout::PageHelpers +end diff --git a/admin/app/components/solidus_admin/stores/new/component.yml b/admin/app/components/solidus_admin/stores/new/component.yml new file mode 100644 index 00000000000..8e1ff8e97e4 --- /dev/null +++ b/admin/app/components/solidus_admin/stores/new/component.yml @@ -0,0 +1,2 @@ +en: + title: "New Store" 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..6992b28a8f4 100644 --- a/admin/app/components/solidus_admin/ui/button/component.rb +++ b/admin/app/components/solidus_admin/ui/button/component.rb @@ -63,6 +63,40 @@ 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.delete(**options) + new( + tag: :button, + text: t(".delete"), + scheme: :danger, + **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..91d0a2c4832 100644 --- a/admin/app/components/solidus_admin/ui/button/component.yml +++ b/admin/app/components/solidus_admin/ui/button/component.yml @@ -1,5 +1,9 @@ en: + back: "Back" cancel: "Cancel" + delete: "Delete" + discard: "Discard" + save: "Save" submit: create: "Add %{resource_name}" update: "Update %{resource_name}" diff --git a/admin/app/components/solidus_admin/ui/forms/select/component.rb b/admin/app/components/solidus_admin/ui/forms/select/component.rb index 349e2429d2a..0f0689b3fb7 100644 --- a/admin/app/components/solidus_admin/ui/forms/select/component.rb +++ b/admin/app/components/solidus_admin/ui/forms/select/component.rb @@ -31,6 +31,7 @@ class SolidusAdmin::UI::Forms::Select::Component < SolidusAdmin::BaseComponent # (see `ActionView::Helpers::FormOptionsHelper#options_for_select`). # When +:src+ parameter is provided, use +:choices+ to provide the list of selected options only. # @param src [nil, String] URL of a JSON resource with options data to be loaded instead of rendering options in place. + # @option attributes [nil, String, Integer, Array] :value which option should be selected # @option attributes [String] :"data-option-value-field" # @option attributes [String] :"data-option-label-field" when +:src+ param is passed, value and label of loaded options # will be mapped to JSON response +"id"+ and +"name"+ by default. Use these parameters to map to different keys. 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/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/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/adjustments_controller.rb b/admin/app/controllers/solidus_admin/adjustments_controller.rb index 350bc3dee5d..f085652211e 100644 --- a/admin/app/controllers/solidus_admin/adjustments_controller.rb +++ b/admin/app/controllers/solidus_admin/adjustments_controller.rb @@ -20,7 +20,7 @@ def index def lock @adjustments = @order.all_adjustments.not_finalized.where(id: params[:id]) @adjustments.each(&:finalize!) - flash[:success] = t('.success') + flash[:notice] = t('.success') redirect_to order_adjustments_path(@order), status: :see_other end @@ -28,7 +28,7 @@ def lock def unlock @adjustments = @order.all_adjustments.finalized.where(id: params[:id]) @adjustments.each(&:unfinalize!) - flash[:success] = t('.success') + flash[:notice] = t('.success') redirect_to order_adjustments_path(@order), status: :see_other end @@ -36,7 +36,7 @@ def unlock def destroy @adjustments = @order.all_adjustments.where(id: params[:id]) @adjustments.destroy_all - flash[:success] = t('.success') + flash[:notice] = t('.success') redirect_to order_adjustments_path(@order), status: :see_other end diff --git a/admin/app/controllers/solidus_admin/base_controller.rb b/admin/app/controllers/solidus_admin/base_controller.rb index bd7442f4eee..8854547389a 100644 --- a/admin/app/controllers/solidus_admin/base_controller.rb +++ b/admin/app/controllers/solidus_admin/base_controller.rb @@ -19,6 +19,7 @@ class BaseController < ApplicationController helper 'solidus_admin/components' helper 'solidus_admin/layout' + helper 'solidus_admin/flash' private diff --git a/admin/app/controllers/solidus_admin/customers_controller.rb b/admin/app/controllers/solidus_admin/customers_controller.rb index af79d4d483a..b86ef95c1e6 100644 --- a/admin/app/controllers/solidus_admin/customers_controller.rb +++ b/admin/app/controllers/solidus_admin/customers_controller.rb @@ -13,7 +13,7 @@ def show def destroy if @order.update(user: nil) - flash[:success] = t('.success') + flash[:notice] = t('.success') else flash[:error] = t('.error') end diff --git a/admin/app/controllers/solidus_admin/products_controller.rb b/admin/app/controllers/solidus_admin/products_controller.rb index e5f22336ed3..4475d11cb47 100644 --- a/admin/app/controllers/solidus_admin/products_controller.rb +++ b/admin/app/controllers/solidus_admin/products_controller.rb @@ -43,7 +43,7 @@ def update @product = Spree::Product.friendly.find(params[:id]) if @product.update(product_params) - flash[:success] = t('spree.successfully_updated', resource: [ + flash[:notice] = t('spree.successfully_updated', resource: [ Spree::Product.model_name.human, @product.name.inspect, ].join(' ')) 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/stores_controller.rb b/admin/app/controllers/solidus_admin/stores_controller.rb index c653163d5c9..5da0a2044f9 100644 --- a/admin/app/controllers/solidus_admin/stores_controller.rb +++ b/admin/app/controllers/solidus_admin/stores_controller.rb @@ -1,35 +1,40 @@ # frozen_string_literal: true module SolidusAdmin - class StoresController < SolidusAdmin::BaseController - include SolidusAdmin::ControllerHelpers::Search - - def index - stores = apply_search_to( - Spree::Store.order(id: :desc), - param: :q - ) - - set_page_and_extract_portion_from(stores) - - respond_to do |format| - format.html { render component('stores/index').new(page: @page) } - end - end - + class StoresController < SolidusAdmin::ResourcesController def destroy - @stores = Spree::Store.where(id: params[:id]) - - Spree::Store.transaction { @stores.destroy_all } + @resource = resource_class.where(id: params[:id]) + + failed = @resource.destroy_all.reject(&:destroyed?) + if failed.present? + desc = failed.map { t(".error.description", name: _1.name, reason: _1.errors.full_messages.join(" ")) }.join("
") + flash[:alert] = { danger: { title: t(".error.title"), description: desc } } + else + flash[:notice] = t('.success') + end - flash[:notice] = t('.success') - redirect_back_or_to stores_path, status: :see_other + redirect_to after_destroy_path, status: :see_other end private - def store_params - params.require(:store).permit(:store_id, permitted_store_attributes) + def resource_class = Spree::Store + + def resources_collection = Spree::Store + + def permitted_resource_params + params.require(:store).permit( + :name, + :url, + :code, + :meta_description, + :meta_keywords, + :seo_title, + :mail_from_address, + :default_currency, + :cart_tax_country_iso, + available_locales: [], + ) end end end diff --git a/admin/app/controllers/solidus_admin/users_controller.rb b/admin/app/controllers/solidus_admin/users_controller.rb index 7e7d181a1bd..04eaa09ac1e 100644 --- a/admin/app/controllers/solidus_admin/users_controller.rb +++ b/admin/app/controllers/solidus_admin/users_controller.rb @@ -37,7 +37,7 @@ def update_addresses set_address_from_params if @address.valid? && @user.update(user_params) - flash[:success] = t(".#{@type}.success") + flash[:notice] = t(".#{@type}.success") respond_to do |format| format.turbo_stream { render turbo_stream: '' } diff --git a/admin/app/helpers/solidus_admin/flash_helper.rb b/admin/app/helpers/solidus_admin/flash_helper.rb new file mode 100644 index 00000000000..de9308ac727 --- /dev/null +++ b/admin/app/helpers/solidus_admin/flash_helper.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Reserve :alert for messages that should go in UI alert component. Everything else will be shown in UI toast. +module SolidusAdmin + module FlashHelper + def toasts + flash.to_hash.with_indifferent_access.except(:alert) + end + + # Construct alert flashes like +flash[:alert] = { : { title: "", description: "" } }+. + # See +SolidusAdmin::UI::Alert::Component::SCHEMES+ for available alert types. + def alerts + flash.to_hash.with_indifferent_access.fetch(:alert, {}).slice(*SolidusAdmin::UI::Alert::Component::SCHEMES.keys) + end + end +end diff --git a/admin/app/views/layouts/solidus_admin/application.html.erb b/admin/app/views/layouts/solidus_admin/application.html.erb index 6755eea3c1d..c833d196a47 100644 --- a/admin/app/views/layouts/solidus_admin/application.html.erb +++ b/admin/app/views/layouts/solidus_admin/application.html.erb @@ -31,8 +31,16 @@
+
+ +
+ diff --git a/admin/config/locales/stores.en.yml b/admin/config/locales/stores.en.yml index 4f901a50d6d..19ff629880e 100644 --- a/admin/config/locales/stores.en.yml +++ b/admin/config/locales/stores.en.yml @@ -1,6 +1,28 @@ en: + activerecord: + attributes: + spree/store: + available_locales: Storefront Languages + bcc_email: BCC Email + cart_tax_country_iso: Tax Country + code: Slug + default: Default + default_currency: Default Currency + mail_from_address: Store Email + meta_description: Meta Description + meta_keywords: Meta Keywords + name: Store Name + seo_title: Page Title + url: URL solidus_admin: stores: title: "Stores" + create: + success: "Store was successfully created." destroy: + error: + title: "Some Stores could not be removed" + description: "%{name}: %{reason}" success: "Stores were successfully removed." + update: + success: "Store was successfully updated." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index ec215522965..64632d94f00 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -79,7 +79,7 @@ admin_resources :shipping_methods, only: [:index, :destroy] admin_resources :shipping_categories, except: [:show] admin_resources :stock_locations, only: [:index, :destroy] - admin_resources :stores, only: [:index, :destroy] + admin_resources :stores, except: [:show] admin_resources :zones, except: [:show] admin_resources :refund_reasons, except: [:show] admin_resources :reimbursement_types, only: [:index] diff --git a/admin/docs/index_pages.md b/admin/docs/index_pages.md index a17379d5529..d18c4b93592 100644 --- a/admin/docs/index_pages.md +++ b/admin/docs/index_pages.md @@ -94,7 +94,7 @@ end def delete @users = Spree.user_class.where(id: params[:id]) @users.destroy_all - flash[:success] = "Admin users deleted" + flash[:notice] = "Admin users deleted" redirect_to solidus_admin.users_path, status: :see_other end ``` 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..fd5667e6894 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,41 @@ 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 ".delete" do + let(:component) { described_class.delete } + + it "renders Delete button" do + render_inline(component) + expect(page).to have_button("Delete") + 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/stores_spec.rb b/admin/spec/features/stores_spec.rb index 921393a584d..07a01204213 100644 --- a/admin/spec/features/stores_spec.rb +++ b/admin/spec/features/stores_spec.rb @@ -5,20 +5,120 @@ describe "Stores", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } - it "lists stores and allows deleting them" do - create(:store, name: "B2C Store") - create(:store, name: "B2B Store") - - visit "/admin/stores" - expect(page).to have_content("B2C Store") - expect(page).to have_content("B2B Store") - expect(page).to be_axe_clean - - select_row("B2C Store") - click_on "Delete" - expect(page).to have_content("Stores were successfully removed.") - expect(page).not_to have_content("B2C Store") - expect(Spree::Store.count).to eq(1) - expect(page).to be_axe_clean + describe "index page" do + before do + create(:store, name: "B2C Store") + create(:store, name: "B2B Store", default: true) + visit "/admin/stores" + expect(page).to have_content("B2C Store") + expect(page).to have_content("B2B Store") + expect(page).to be_axe_clean + end + + it "lists stores and allows deleting them" do + select_row("B2C Store") + + accept_confirm("Are you sure you want to delete 1 store?") do + click_button("Delete") + end + + expect(page).to have_content("Stores were successfully removed.") + expect(page).not_to have_content("B2C Store") + expect(page).to be_axe_clean + end + + it "does not allow to delete default store" do + select_row("B2B Store") + + accept_confirm("Are you sure you want to delete 1 store?") do + click_button("Delete") + end + + expect(page).not_to have_content("Stores were successfully removed.") + expect(page).to have_content("B2B Store") + expect(page).to have_content("Some Stores could not be removed") + expect(page).to have_content("B2B Store: Cannot destroy the default Store") + expect(page).to be_axe_clean + end + end + + describe "creating new store" do + before do + visit "/admin/stores" + click_on "Add new" + expect(page).to be_axe_clean + end + + context "with valid form" do + it "saves store" do + fill_in "Store Name", with: "New Store" + fill_in "Slug", with: "new-store" + fill_in "URL", with: "www.new-store.com" + fill_in "Store Email", with: "mail@new-stores.com" + + within("header") { click_on "Save" } + + expect(page).to have_content("Store was successfully created") + expect(page).to have_content("New Store") + expect(page).to have_content("new-store") + expect(page).to have_content("www.new-store.com") + end + end + + context "with invalid form" do + it "saves store" do + within("header") { click_on "Save" } + + expect(page).to have_content("can't be blank", count: 4) + end + end + end + + describe "editing existing store" do + before do + create(:store, + name: "B2C Store", + default_currency: "GBP", + cart_tax_country_iso: create(:country, iso: "GB").iso, + available_locales: %w[en]) + + create(:country, iso: "US") + visit "/admin/stores" + click_on "B2C Store" + expect(page).to be_axe_clean + end + + it "updates store" do + expect(solidus_select_control("Default Currency")).to have_content("GBP") + expect(solidus_select_control("Tax Country")).to have_content("United Kingdom") + expect(solidus_select_control("Storefront Languages")).to have_content("English (US)") + + fill_in "Store Name", with: "Updated Store" + fill_in "Slug", with: "updated-store" + fill_in "URL", with: "www.updated-store.com" + fill_in "Store Email", with: "updated-mail@new-stores.com" + solidus_select("USD", from: "Default Currency") + solidus_select("United States", from: "Tax Country") + + within("header") { click_on "Save" } + + expect(page).to have_content("Store was successfully updated") + expect(page).to have_content("Updated Store") + expect(page).to have_content("updated-store") + expect(page).to have_content("www.updated-store.com") + + click_on "Updated Store" + expect(solidus_select_control("Default Currency")).to have_content("USD") + expect(solidus_select_control("Tax Country")).to have_content("United States") + end + end + + describe "clicking Discard" do + it "redirects back to index" do + visit "/admin/stores" + click_on "Add new" + click_on "Discard" + expect(page).to have_current_path("/admin/stores") + end end end diff --git a/admin/spec/requests/solidus_admin/stores_spec.rb b/admin/spec/requests/solidus_admin/stores_spec.rb new file mode 100644 index 00000000000..bc19dddffc5 --- /dev/null +++ b/admin/spec/requests/solidus_admin/stores_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::StoresController", type: :request do + before { create(:store, default: true) } # create a default store so that we operate on a non-default one + + include_examples 'CRUD resource requests', 'store' do + let(:resource_class) { Spree::Store } + let(:valid_attributes) { { name: "Store", code: "store", url: "store.com", mail_from_address: "store@example.com" } } + let(:invalid_attributes) { { name: "" } } + end +end diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb index fd5aef8289c..f16e3389342 100644 --- a/core/app/models/spree/store.rb +++ b/core/app/models/spree/store.rb @@ -25,7 +25,7 @@ class Store < Spree::Base self.allowed_ransackable_attributes = %w[name url code] before_save :ensure_default_exists_and_is_unique - before_destroy :validate_not_default + before_destroy :validate_not_default, prepend: true enum :reverse_charge_status, { disabled: 0, @@ -73,6 +73,7 @@ def ensure_default_exists_and_is_unique def validate_not_default if default errors.add(:base, :cannot_destroy_default_store) + throw :abort end end end diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rb index 9bf552581d6..37bdf445638 100644 --- a/core/spec/models/spree/store_spec.rb +++ b/core/spec/models/spree/store_spec.rb @@ -136,4 +136,24 @@ expect { Spree::Store.new(reverse_charge_status: :invalid_status) }.to raise_error(ArgumentError) end end + + describe "#validate_not_default" do + context "when deleting a default store" do + it "prevents deletion" do + store = create(:store, default: true) + expect(store.destroy).to eq false + expect(store.errors.full_messages.join).to match /Cannot destroy/ + expect { store.reload }.not_to raise_error + end + end + + context "when deleting a non-default store" do + it "allows deletion" do + create(:store, default: true) + store = create(:store, default: false) + expect(store.destroy).to be_truthy + expect { store.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + 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| %>