Skip to content

Commit

Permalink
wip: pass around query params
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Dec 23, 2024
1 parent 45e4a74 commit 0e5c4dc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.stimulus_id
end

delegate :stimulus_id, to: :class
delegate :turbo_frame_request?, to: :helpers
delegate :turbo_frame_request?, :search_filter_params, to: :helpers

class << self
private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= 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: solidus_admin.return_reason_path(@return_reason), html: { id: form_id } do |f| %>
<%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<label class="flex gap-2 items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ 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?
turbo_frame_request? || @return_reason.errors.any?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= 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: solidus_admin.return_reasons_path, html: { id: form_id } do |f| %>
<%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
<label class="flex gap-2 items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ 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?
turbo_frame_request? || @return_reason.errors.any?
end
Expand Down
12 changes: 9 additions & 3 deletions admin/app/controllers/solidus_admin/return_reasons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ReturnReasonsController < SolidusAdmin::BaseController

before_action :set_return_reason, only: %i[edit update]

helper_method :search_filter_params

def index
set_index_page

Expand All @@ -27,7 +29,7 @@ def create

if @return_reason.save
flash[:notice] = t('.success')
redirect_to solidus_admin.return_reasons_path, status: :see_other
redirect_to solidus_admin.return_reasons_path(**search_filter_params), status: :see_other
else
respond_to do |format|
format.html do
Expand All @@ -48,7 +50,7 @@ def edit
def update
if @return_reason.update(return_reason_params)
flash[:notice] = t('.success')
redirect_to solidus_admin.return_reasons_path, status: :see_other
redirect_to solidus_admin.return_reasons_path(**search_filter_params), status: :see_other
else
respond_to do |format|
format.html do
Expand All @@ -68,11 +70,15 @@ 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

def search_filter_params
request.params.slice(:q, :page)
end

def set_return_reason
@return_reason = Spree::ReturnReason.find(params[:id])
end
Expand Down

0 comments on commit 0e5c4dc

Please sign in to comment.