Skip to content

Commit

Permalink
Admin tax categories: 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 40a31e7 commit ca8ae78
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@
<% end %>
<% end %>
<% end %>

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

class SolidusAdmin::TaxCategories::Edit::Component < SolidusAdmin::TaxCategories::Index::Component
def initialize(page:, tax_category:)
@page = page
def initialize(tax_category:)
@tax_category = tax_category
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Component
def row_url(tax_category)
spree.edit_admin_tax_category_path(tax_category, _turbo_frame: :edit_tax_category_modal)
def edit_path(tax_category)
spree.edit_admin_tax_category_path(tax_category)
end

def model_class
Expand All @@ -17,7 +17,10 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_tax_category_path, data: { turbo_frame: :new_tax_category_modal },
href: solidus_admin.new_tax_category_path, data: {
turbo_frame: :new_tax_category_modal,
turbo_prefetch: false,
},
icon: "add-line",
class: "align-self-end w-full",
)
Expand Down Expand Up @@ -47,9 +50,30 @@ def batch_actions

def columns
[
:name,
:tax_code,
:description,
{
header: :name,
data: ->(tax_category) do
link_to tax_category.name, edit_path(tax_category),
data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :tax_code,
data: ->(tax_category) do
link_to_if tax_category.tax_code, tax_category.tax_code, edit_path(tax_category),
data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :description,
data: ->(tax_category) do
link_to_if tax_category.description, tax_category.description, edit_path(tax_category),
data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :is_default,
data: ->(tax_category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@
<% end %>
<% end %>
<% end %>

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

class SolidusAdmin::TaxCategories::New::Component < SolidusAdmin::TaxCategories::Index::Component
def initialize(page:, tax_category:)
@page = page
def initialize(tax_category:)
@tax_category = tax_category
end

Expand Down
16 changes: 4 additions & 12 deletions admin/app/controllers/solidus_admin/tax_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ class TaxCategoriesController < SolidusAdmin::BaseController
def new
@tax_category = Spree::TaxCategory.new

set_index_page

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

def edit
@tax_category = Spree::TaxCategory.find(params[:id])

set_index_page

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

Expand All @@ -44,11 +40,9 @@ def create
end
end
else
set_index_page

respond_to do |format|
format.html do
page_component = component('tax_categories/new').new(page: @page, tax_category: @tax_category)
page_component = component('tax_categories/new').new(tax_category: @tax_category)
render page_component, status: :unprocessable_entity
end
end
Expand All @@ -69,11 +63,9 @@ def update
end
end
else
set_index_page

respond_to do |format|
format.html do
page_component = component('tax_categories/edit').new(page: @page, tax_category: @tax_category)
page_component = component('tax_categories/edit').new(tax_category: @tax_category)
render page_component, status: :unprocessable_entity
end
end
Expand Down

0 comments on commit ca8ae78

Please sign in to comment.