diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb
new file mode 100644
index 00000000000..a5feeef7251
--- /dev/null
+++ b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb
@@ -0,0 +1,28 @@
+<%= turbo_frame_tag :edit_tax_category_modal do %>
+ <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
+ <%= form_for @tax_category, url: solidus_admin.tax_category_path(@tax_category), html: { id: form_id } do |f| %>
+
+ <%= render component("ui/forms/field").text_field(f, :name) %>
+ <%= render component("ui/forms/field").text_field(f, :tax_code) %>
+ <%= render component("ui/forms/field").text_field(f, :description) %>
+
+
+ <% modal.with_actions do %>
+
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %>
+ <% end %>
+ <% end %>
+ <% end %>
+<% end %>
+
+<%= render component("tax_categories/index").new(page: @page) %>
diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.rb b/admin/app/components/solidus_admin/tax_categories/edit/component.rb
new file mode 100644
index 00000000000..31ddbd13d72
--- /dev/null
+++ b/admin/app/components/solidus_admin/tax_categories/edit/component.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class SolidusAdmin::TaxCategories::Edit::Component < SolidusAdmin::TaxCategories::Index::Component
+ def initialize(page:, tax_category:)
+ @page = page
+ @tax_category = tax_category
+ end
+
+ def form_id
+ dom_id(@tax_category, "#{stimulus_id}_edit_tax_category_form")
+ end
+end
diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.yml b/admin/app/components/solidus_admin/tax_categories/edit/component.yml
new file mode 100644
index 00000000000..6e3f8562048
--- /dev/null
+++ b/admin/app/components/solidus_admin/tax_categories/edit/component.yml
@@ -0,0 +1,8 @@
+# Add your component translations here.
+# Use the translation in the example in your template with `t(".hello")`.
+en:
+ title: "Edit Tax Category"
+ cancel: "Cancel"
+ submit: "Update Tax Category"
+ hints:
+ is_default: "When checked, this tax category will be selected by default when creating new products or variants."
diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.rb b/admin/app/components/solidus_admin/tax_categories/index/component.rb
index c435fb1da7c..c2ce2b16ca2 100644
--- a/admin/app/components/solidus_admin/tax_categories/index/component.rb
+++ b/admin/app/components/solidus_admin/tax_categories/index/component.rb
@@ -2,7 +2,7 @@
class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Component
def row_url(tax_category)
- spree.edit_admin_tax_category_path(tax_category)
+ spree.edit_admin_tax_category_path(tax_category, _turbo_frame: :edit_tax_category_modal)
end
def model_class
@@ -24,7 +24,10 @@ def page_actions
end
def turbo_frames
- %w[new_tax_category_modal]
+ %w[
+ new_tax_category_modal
+ edit_tax_category_modal
+ ]
end
def search_key
diff --git a/admin/app/controllers/solidus_admin/tax_categories_controller.rb b/admin/app/controllers/solidus_admin/tax_categories_controller.rb
index cc9e833a2ba..5bea5239211 100644
--- a/admin/app/controllers/solidus_admin/tax_categories_controller.rb
+++ b/admin/app/controllers/solidus_admin/tax_categories_controller.rb
@@ -4,6 +4,8 @@ module SolidusAdmin
class TaxCategoriesController < SolidusAdmin::BaseController
include SolidusAdmin::ControllerHelpers::Search
+ before_action :find_tax_category, only: %i[edit update]
+
def new
@tax_category = Spree::TaxCategory.new
@@ -14,6 +16,16 @@ def new
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) }
+ end
+ end
+
def create
@tax_category = Spree::TaxCategory.new(tax_category_params)
@@ -43,6 +55,31 @@ def create
end
end
+ def update
+ if @tax_category.update(tax_category_params)
+ respond_to do |format|
+ flash[:notice] = t('.success')
+
+ format.html do
+ redirect_to solidus_admin.tax_categories_path, status: :see_other
+ end
+
+ format.turbo_stream do
+ render turbo_stream: ''
+ 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)
+ render page_component, status: :unprocessable_entity
+ end
+ end
+ end
+ end
+
def index
set_index_page
@@ -67,6 +104,10 @@ def load_tax_category
authorize! action_name, @tax_category
end
+ def find_tax_category
+ @tax_category = Spree::TaxCategory.find(params[:id])
+ end
+
def tax_category_params
params.require(:tax_category).permit(:name, :description, :is_default, :tax_code)
end
diff --git a/admin/config/locales/tax_categories.en.yml b/admin/config/locales/tax_categories.en.yml
index c86f9400f42..b049ad67e00 100644
--- a/admin/config/locales/tax_categories.en.yml
+++ b/admin/config/locales/tax_categories.en.yml
@@ -6,3 +6,5 @@ en:
success: "Tax categories were successfully removed."
create:
success: "Tax category was successfully created."
+ update:
+ success: "Tax category was successfully updated."
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index 37003949356..5b1822dcbfe 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -51,7 +51,7 @@
admin_resources :option_types, only: [:index, :destroy], sortable: true
admin_resources :taxonomies, only: [:index, :destroy], sortable: true
admin_resources :promotion_categories, only: [:index, :destroy]
- admin_resources :tax_categories, only: [:new, :index, :create, :destroy]
+ admin_resources :tax_categories, except: [:show]
admin_resources :tax_rates, only: [:index, :destroy]
admin_resources :payment_methods, only: [:index, :destroy], sortable: true
admin_resources :stock_items, only: [:index, :edit, :update]