Skip to content

Commit 162d93c

Browse files
committed
Admin refund reasons: Load modal with turbo frame
1 parent 3963495 commit 162d93c

File tree

7 files changed

+29
-25
lines changed

7 files changed

+29
-25
lines changed

admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@
2424
<% end %>
2525
<% end %>
2626
<% end %>
27-
<%= render component("refund_reasons/index").new(page: @page) %>

admin/app/components/solidus_admin/refund_reasons/edit/component.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::BaseComponent
4-
def initialize(page:, refund_reason:)
5-
@page = page
4+
def initialize(refund_reason:)
65
@refund_reason = refund_reason
76
end
87

admin/app/components/solidus_admin/refund_reasons/index/component.rb

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def search_key
1313
:name_or_code_cont
1414
end
1515

16-
def row_url(refund_reason)
17-
spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal)
16+
def edit_path(refund_reason)
17+
spree.edit_admin_refund_reason_path(refund_reason)
1818
end
1919

2020
def turbo_frames
@@ -28,7 +28,10 @@ def page_actions
2828
render component("ui/button").new(
2929
tag: :a,
3030
text: t('.add'),
31-
href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal },
31+
href: solidus_admin.new_refund_reason_path, data: {
32+
turbo_frame: :new_refund_reason_modal,
33+
turbo_prefetch: false
34+
},
3235
icon: "add-line",
3336
class: "align-self-end w-full",
3437
)
@@ -47,8 +50,22 @@ def batch_actions
4750

4851
def columns
4952
[
50-
:name,
51-
:code,
53+
{
54+
header: :name,
55+
data: ->(refund_reason) do
56+
link_to refund_reason.name, edit_path(refund_reason),
57+
data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false },
58+
class: 'body-link'
59+
end
60+
},
61+
{
62+
header: :code,
63+
data: ->(refund_reason) do
64+
link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason),
65+
data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false },
66+
class: 'body-link'
67+
end
68+
},
5269
{
5370
header: :active,
5471
data: ->(refund_reason) do

admin/app/components/solidus_admin/refund_reasons/new/component.html.erb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@
2323
<% end %>
2424
<% end %>
2525
<% end %>
26-
27-
<%= render component("refund_reasons/index").new(page: @page) %>

admin/app/components/solidus_admin/refund_reasons/new/component.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::BaseComponent
4-
def initialize(page:, refund_reason:)
5-
@page = page
4+
def initialize(refund_reason:)
65
@refund_reason = refund_reason
76
end
87

admin/app/controllers/solidus_admin/refund_reasons_controller.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ def index
1717
def new
1818
@refund_reason = Spree::RefundReason.new
1919

20-
set_index_page
21-
2220
respond_to do |format|
23-
format.html { render component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason) }
21+
format.html { render component('refund_reasons/new').new(refund_reason: @refund_reason) }
2422
end
2523
end
2624

@@ -40,22 +38,18 @@ def create
4038
end
4139
end
4240
else
43-
set_index_page
44-
4541
respond_to do |format|
4642
format.html do
47-
page_component = component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason)
43+
page_component = component('refund_reasons/new').new(refund_reason: @refund_reason)
4844
render page_component, status: :unprocessable_entity
4945
end
5046
end
5147
end
5248
end
5349

5450
def edit
55-
set_index_page
56-
5751
respond_to do |format|
58-
format.html { render component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason) }
52+
format.html { render component('refund_reasons/edit').new(refund_reason: @refund_reason) }
5953
end
6054
end
6155

@@ -73,11 +67,9 @@ def update
7367
end
7468
end
7569
else
76-
set_index_page
77-
7870
respond_to do |format|
7971
format.html do
80-
page_component = component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason)
72+
page_component = component('refund_reasons/edit').new(refund_reason: @refund_reason)
8173
render page_component, status: :unprocessable_entity
8274
end
8375
end

admin/spec/features/refund_reasons_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
before do
6666
Spree::RefundReason.create(name: "Return process")
6767
visit "/admin/refund_reasons#{query}"
68-
find_row("Return process").click
68+
click_on "Return process"
6969
expect(page).to have_css("dialog", wait: 5)
7070
expect(page).to have_content("Edit Refund Reason")
7171
expect(page).to be_axe_clean

0 commit comments

Comments
 (0)