From 055e6f06a454afcc757676d5bde6306dcd736784 Mon Sep 17 00:00:00 2001 From: andrea longhi Date: Tue, 12 Mar 2024 17:46:02 +0100 Subject: [PATCH] Add tax_categories/edit component The component renders the edit form inside a modal on top of the tax categories list, inside a Turbo frame. --- .../tax_categories/edit/component.html.erb | 28 +++++++++++++++++++ .../tax_categories/edit/component.rb | 12 ++++++++ .../tax_categories/edit/component.yml | 8 ++++++ 3 files changed, 48 insertions(+) create mode 100644 admin/app/components/solidus_admin/tax_categories/edit/component.html.erb create mode 100644 admin/app/components/solidus_admin/tax_categories/edit/component.rb create mode 100644 admin/app/components/solidus_admin/tax_categories/edit/component.yml 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 0000000000..a5feeef725 --- /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(scheme: :secondary, text: t('.cancel')) %> +
+ <%= 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 0000000000..31ddbd13d7 --- /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 0000000000..6e3f856204 --- /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."