Skip to content

Commit

Permalink
Add New Tax Category component
Browse files Browse the repository at this point in the history
The component renders:

1) a list of tax categories in the background;
2) a dialog modal with the form for creating a new resource.

The modal is wrapped into a turbo frame tag, so it can be enclosed
in other pages (i.e. the tax categories index) asynchronously.
  • Loading branch information
spaghetticode committed Mar 7, 2024
1 parent 15899d4 commit bcbd4eb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_tax_category_path,
href: solidus_admin.new_tax_category_path, data: { turbo_frame: :new_tax_category_modal },
icon: "add-line",
class: "align-self-end w-full",
)
end

def turbo_frames
%w[new_tax_category_modal]
end

def search_key
:name_or_description_cont
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%= turbo_frame_tag :new_tax_category_modal do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @tax_category, url: solidus_admin.tax_categories_path(page: params[:page], q: params[:q]), html: { id: form_id } do |f| %>
<div class="flex flex-col gap-6 pb-4">
<%= 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) %>
<label class="flex gap-2 items-center">
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[is_default]",
value: "1",
checked: f.object.is_default
) %>
<span class="font-semibold text-xs ml-2"><%= Spree::TaxCategory.human_attribute_name :is_default %></span>
<%= render component("ui/toggletip").new(text: t(".hints.is_default")) %>
</label>
</div>
<% modal.with_actions do %>
<form method="dialog">
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %>
</form>
<%= 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) %>
12 changes: 12 additions & 0 deletions admin/app/components/solidus_admin/tax_categories/new/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class SolidusAdmin::TaxCategories::New::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}_new_tax_category_form")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Add your component translations here.
# Use the translation in the example in your template with `t(".hello")`.
en:
title: "New Tax Category"
cancel: "Cancel"
submit: "Add Tax Category"
hints:
is_default: "When checked, this tax category will be selected by default when creating new products or variants."

0 comments on commit bcbd4eb

Please sign in to comment.