Skip to content

Commit

Permalink
Add tax category edit and update actions
Browse files Browse the repository at this point in the history
This completes the feature for editing an existing tax category.
  • Loading branch information
spaghetticode committed Mar 13, 2024
1 parent 055e6f0 commit f38fbd6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions admin/app/controllers/solidus_admin/tax_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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: '<turbo-stream action="refresh" />'
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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions admin/config/locales/tax_categories.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit f38fbd6

Please sign in to comment.