diff --git a/admin/app/components/solidus_admin/base_component.rb b/admin/app/components/solidus_admin/base_component.rb
index e3adf62c02f..6b9fea1a584 100644
--- a/admin/app/components/solidus_admin/base_component.rb
+++ b/admin/app/components/solidus_admin/base_component.rb
@@ -37,6 +37,7 @@ def self.stimulus_id
end
delegate :stimulus_id, to: :class
+ delegate :turbo_frame_request?, :search_filter_params, to: :helpers
class << self
private
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 5e14b95e423..f9d013ff490 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,6 +1,6 @@
-<%= turbo_frame_tag :edit_return_reason_modal do %>
- <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
- <%= form_for @return_reason, url: solidus_admin.return_reason_path(@return_reason), html: { id: form_id } do |f| %>
+<%= turbo_frame_tag :edit_return_reason_modal, target: "_top" do %>
+ <%= render component("ui/modal").new(title: t(".title"), closable: closable?) do |modal| %>
+ <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<% modal.with_actions do %>
-
+ <% if closable? %>
+
+ <% else %>
+ <%= render component("ui/button").new(
+ tag: :a,
+ href: back_url,
+ scheme: :secondary,
+ text: t('.cancel')
+ ) %>
+ <% end %>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
diff --git a/admin/app/components/solidus_admin/return_reasons/edit/component.rb b/admin/app/components/solidus_admin/return_reasons/edit/component.rb
index a73bca5670a..9884161fc59 100644
--- a/admin/app/components/solidus_admin/return_reasons/edit/component.rb
+++ b/admin/app/components/solidus_admin/return_reasons/edit/component.rb
@@ -8,4 +8,18 @@ def initialize(return_reason:)
def form_id
dom_id(@return_reason, "#{stimulus_id}_edit_return_reason_form")
end
+
+ def form_url
+ solidus_admin.return_reason_path(@return_reason, **search_filter_params)
+ end
+
+ def closable?
+ return false if request.referer.include? "/edit"
+
+ turbo_frame_request? || @return_reason.errors.any?
+ end
+
+ def back_url
+ request.referer || solidus_admin.return_reasons_path
+ end
end
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 8a6ee9f80ef..2de0504de2b 100644
--- a/admin/app/components/solidus_admin/return_reasons/index/component.rb
+++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb
@@ -14,7 +14,7 @@ def search_key
end
def edit_path(return_reason)
- spree.edit_admin_return_reason_path(return_reason)
+ spree.edit_admin_return_reason_path(return_reason, **search_filter_params)
end
def turbo_frames
@@ -28,7 +28,7 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
- href: solidus_admin.new_return_reason_path,
+ href: solidus_admin.new_return_reason_path(**search_filter_params),
data: { turbo_frame: :new_return_reason_modal, turbo_prefetch: false },
icon: "add-line",
class: "align-self-end w-full",
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 237315fb3e8..d39c623b934 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,6 +1,6 @@
-<%= turbo_frame_tag :new_return_reason_modal do %>
- <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
- <%= form_for @return_reason, url: solidus_admin.return_reasons_path, html: { id: form_id } do |f| %>
+<%= turbo_frame_tag :new_return_reason_modal, target: "_top" do %>
+ <%= render component("ui/modal").new(title: t(".title"), closable: closable?) do |modal| %>
+ <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<% modal.with_actions do %>
-
+ <% if closable? %>
+
+ <% else %>
+ <%= render component("ui/button").new(
+ tag: :a,
+ href: back_url,
+ scheme: :secondary,
+ text: t('.cancel')
+ ) %>
+ <% end %>
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
<% end %>
<% end %>
diff --git a/admin/app/components/solidus_admin/return_reasons/new/component.rb b/admin/app/components/solidus_admin/return_reasons/new/component.rb
index 35ae39d7dbe..25e4bd2b553 100644
--- a/admin/app/components/solidus_admin/return_reasons/new/component.rb
+++ b/admin/app/components/solidus_admin/return_reasons/new/component.rb
@@ -8,4 +8,18 @@ def initialize(return_reason:)
def form_id
dom_id(@return_reason, "#{stimulus_id}_new_return_reason_form")
end
+
+ def form_url
+ solidus_admin.return_reasons_path(**search_filter_params)
+ end
+
+ def closable?
+ return false if request.referer.include? "/new"
+
+ turbo_frame_request? || @return_reason.errors.any?
+ end
+
+ def back_url
+ request.referer || solidus_admin.return_reasons_path
+ end
end
diff --git a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb
index 69916f08dd4..682a0123b61 100644
--- a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb
+++ b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb
@@ -39,6 +39,6 @@
<% end %>
<% turbo_frames.each do |frame| %>
- <%= turbo_frame_tag frame %>
+ <%= turbo_frame_tag frame, target: "_top" %>
<% end %>
<% end %>
diff --git a/admin/app/controllers/solidus_admin/base_controller.rb b/admin/app/controllers/solidus_admin/base_controller.rb
index 98905a1f603..e8d63898272 100644
--- a/admin/app/controllers/solidus_admin/base_controller.rb
+++ b/admin/app/controllers/solidus_admin/base_controller.rb
@@ -20,8 +20,14 @@ class BaseController < ApplicationController
helper 'solidus_admin/components'
helper 'solidus_admin/layout'
+ helper_method :search_filter_params
+
private
+ def search_filter_params
+ request.params.slice(:q, :page)
+ end
+
def set_layout
if turbo_frame_request?
false
diff --git a/admin/app/controllers/solidus_admin/return_reasons_controller.rb b/admin/app/controllers/solidus_admin/return_reasons_controller.rb
index 7effdd9f213..fefda2faec3 100644
--- a/admin/app/controllers/solidus_admin/return_reasons_controller.rb
+++ b/admin/app/controllers/solidus_admin/return_reasons_controller.rb
@@ -26,52 +26,38 @@ def create
@return_reason = Spree::ReturnReason.new(return_reason_params)
if @return_reason.save
- respond_to do |format|
- flash[:notice] = t('.success')
-
- format.html do
- redirect_to solidus_admin.return_reasons_path, status: :see_other
- end
-
- format.turbo_stream do
- render turbo_stream: ''
- end
- end
+ flash[:notice] = t('.success')
+ redirect_to solidus_admin.return_reasons_path(**search_filter_params), status: :see_other
else
respond_to do |format|
format.html do
page_component = component('return_reasons/new').new(return_reason: @return_reason)
render page_component, status: :unprocessable_entity
end
+ format.turbo_stream do
+ render status: :unprocessable_entity
+ end
end
end
end
def edit
- respond_to do |format|
- format.html { render component('return_reasons/edit').new(return_reason: @return_reason) }
- end
+ render component('return_reasons/edit').new(return_reason: @return_reason)
end
def update
if @return_reason.update(return_reason_params)
- respond_to do |format|
- flash[:notice] = t('.success')
-
- format.html do
- redirect_to solidus_admin.return_reasons_path, status: :see_other
- end
-
- format.turbo_stream do
- render turbo_stream: ''
- end
- end
+ flash[:notice] = t('.success')
+ redirect_to solidus_admin.return_reasons_path(**search_filter_params), status: :see_other
else
respond_to do |format|
format.html do
page_component = component('return_reasons/edit').new(return_reason: @return_reason)
render page_component, status: :unprocessable_entity
end
+ format.turbo_stream do
+ render status: :unprocessable_entity
+ end
end
end
end
@@ -82,7 +68,7 @@ def destroy
Spree::ReturnReason.transaction { @return_reason.destroy }
flash[:notice] = t('.success')
- redirect_back_or_to return_reasons_path, status: :see_other
+ redirect_back_or_to return_reasons_path(**search_filter_params), status: :see_other
end
private
diff --git a/admin/app/views/solidus_admin/return_reasons/create.turbo_stream.erb b/admin/app/views/solidus_admin/return_reasons/create.turbo_stream.erb
new file mode 100644
index 00000000000..3acfcfcce03
--- /dev/null
+++ b/admin/app/views/solidus_admin/return_reasons/create.turbo_stream.erb
@@ -0,0 +1,3 @@
+<%= turbo_stream.replace :new_return_reason_modal do %>
+ <%= render component('return_reasons/new').new(return_reason: @return_reason) %>
+<% end %>
diff --git a/admin/app/views/solidus_admin/return_reasons/update.turbo_stream.erb b/admin/app/views/solidus_admin/return_reasons/update.turbo_stream.erb
new file mode 100644
index 00000000000..55760e8d270
--- /dev/null
+++ b/admin/app/views/solidus_admin/return_reasons/update.turbo_stream.erb
@@ -0,0 +1,3 @@
+<%= turbo_stream.replace :edit_return_reason_modal do %>
+ <%= render component('return_reasons/edit').new(return_reason: @return_reason) %>
+<% end %>