Skip to content

Commit

Permalink
Admin refund reasons: Load modal with turbo frame
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Dec 20, 2024
1 parent 3963495 commit 162d93c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("refund_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
def initialize(refund_reason:)
@refund_reason = refund_reason
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def search_key
:name_or_code_cont
end

def row_url(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal)
def edit_path(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason)
end

def turbo_frames
Expand All @@ -28,7 +28,10 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal },
href: solidus_admin.new_refund_reason_path, data: {
turbo_frame: :new_refund_reason_modal,
turbo_prefetch: false
},
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -47,8 +50,22 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(refund_reason) do
link_to refund_reason.name, edit_path(refund_reason),
data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :code,
data: ->(refund_reason) do
link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason),
data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :active,
data: ->(refund_reason) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("refund_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
def initialize(refund_reason:)
@refund_reason = refund_reason
end

Expand Down
16 changes: 4 additions & 12 deletions admin/app/controllers/solidus_admin/refund_reasons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ def index
def new
@refund_reason = Spree::RefundReason.new

set_index_page

respond_to do |format|
format.html { render component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason) }
format.html { render component('refund_reasons/new').new(refund_reason: @refund_reason) }
end
end

Expand All @@ -40,22 +38,18 @@ def create
end
end
else
set_index_page

respond_to do |format|
format.html do
page_component = component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason)
page_component = component('refund_reasons/new').new(refund_reason: @refund_reason)
render page_component, status: :unprocessable_entity
end
end
end
end

def edit
set_index_page

respond_to do |format|
format.html { render component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason) }
format.html { render component('refund_reasons/edit').new(refund_reason: @refund_reason) }
end
end

Expand All @@ -73,11 +67,9 @@ def update
end
end
else
set_index_page

respond_to do |format|
format.html do
page_component = component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason)
page_component = component('refund_reasons/edit').new(refund_reason: @refund_reason)
render page_component, status: :unprocessable_entity
end
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/refund_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
before do
Spree::RefundReason.create(name: "Return process")
visit "/admin/refund_reasons#{query}"
find_row("Return process").click
click_on "Return process"
expect(page).to have_css("dialog", wait: 5)
expect(page).to have_content("Edit Refund Reason")
expect(page).to be_axe_clean
Expand Down

0 comments on commit 162d93c

Please sign in to comment.