Skip to content

Commit

Permalink
Admin return 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 a6bb473 commit 354c7c2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("return_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::ReturnReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
def initialize(return_reason:)
@return_reason = return_reason
end

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

def row_url(return_reason)
spree.edit_admin_return_reason_path(return_reason, _turbo_frame: :edit_return_reason_modal)
def edit_path(return_reason)
spree.edit_admin_return_reason_path(return_reason)
end

def turbo_frames
Expand All @@ -29,7 +29,7 @@ def page_actions
tag: :a,
text: t('.add'),
href: solidus_admin.new_return_reason_path,
data: { turbo_frame: :new_return_reason_modal },
data: { turbo_frame: :new_return_reason_modal, turbo_prefetch: false },
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -48,7 +48,14 @@ def batch_actions

def columns
[
:name,
{
header: :name,
data: ->(return_reason) do
link_to return_reason.name, edit_path(return_reason),
data: { turbo_frame: :edit_return_reason_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :active,
data: ->(return_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("return_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::ReturnReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
def initialize(return_reason:)
@return_reason = return_reason
end

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

set_index_page

respond_to do |format|
format.html { render component('return_reasons/new').new(page: @page, return_reason: @return_reason) }
format.html { render component('return_reasons/new').new(return_reason: @return_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('return_reasons/new').new(page: @page, return_reason: @return_reason)
page_component = component('return_reasons/new').new(return_reason: @return_reason)
render page_component, status: :unprocessable_entity
end
end
end
end

def edit
set_index_page

respond_to do |format|
format.html { render component('return_reasons/edit').new(page: @page, return_reason: @return_reason) }
format.html { render component('return_reasons/edit').new(return_reason: @return_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('return_reasons/edit').new(page: @page, return_reason: @return_reason)
page_component = component('return_reasons/edit').new(return_reason: @return_reason)
render page_component, status: :unprocessable_entity
end
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/return_reasons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
before do
Spree::ReturnReason.create(name: "Good Reason")
visit "/admin/return_reasons#{query}"
find_row("Good Reason").click
click_on "Good Reason"
expect(page).to have_selector("dialog", wait: 5)
expect(page).to have_content("Edit Return Reason")
expect(page).to be_axe_clean
Expand Down

0 comments on commit 354c7c2

Please sign in to comment.