diff --git a/app/components/tag_rule_form_component.rb b/app/components/tag_rule_form_component.rb index bcdb5b8aa1..2ec9b78da1 100644 --- a/app/components/tag_rule_form_component.rb +++ b/app/components/tag_rule_form_component.rb @@ -1,20 +1,52 @@ # frozen_string_literal: true class TagRuleFormComponent < ViewComponent::Base - def initialize(rule:, rule_data:, index:, customer_tags: "", + def initialize(rule:, index:, customer_tags: "", hidden_field_customer_tag_options: {}) @rule = rule - @rule_data = rule_data @index = index @customer_tags = customer_tags @hidden_field_customer_tag_options = hidden_field_customer_tag_options end - attr_reader :rule, :index, :rule_data, :customer_tags, :hidden_field_customer_tag_options + attr_reader :rule, :index, :customer_tags, :hidden_field_customer_tag_options private def element_name(name) "enterprise[tag_rules_attributes][#{index}][#{name}]" end + + def rule_data # rubocop:disable Metrics/MethodLength + case rule.type + when "TagRule::FilterShippingMethods" + { + text_top: t('components.tag_rule_form.tag_rules.shipping_method_tagged_top'), + text_bottom: t('components.tag_rule_form.tag_rules.shipping_method_tagged_bottom'), + taggable: "shipping_method", + visibility_field: "shipping_methods", + } + when "TagRule::FilterPaymentMethods" + { + text_top: t('components.tag_rule_form.tag_rules.payment_method_tagged_top'), + text_bottom: t('components.tag_rule_form.tag_rules.payment_method_tagged_bottom'), + taggable: "payment_method", + visibility_field: "payment_methods", + } + when "TagRule::FilterOrderCycles" + { + text_top: t('components.tag_rule_form.tag_rules.order_cycle_tagged_top'), + text_bottom: t('components.tag_rule_form.tag_rules.order_cycle_tagged_bottom'), + taggable: "exchange", + visibility_field: "order_cycles", + } + when "TagRule::FilterProducts" + { + text_top: t('components.tag_rule_form.tag_rules.inventory_tagged_top'), + text_bottom: t('components.tag_rule_form.tag_rules.inventory_tagged_bottom'), + taggable: "variant", + visibility_field: "variants", + } + end + end end diff --git a/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml b/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml index ca19b097fd..ee453c29af 100644 --- a/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml +++ b/app/components/tag_rule_group_form_component/tag_rule_group_form_component.html.haml @@ -23,7 +23,6 @@ - group[:rules].each do |rule| -rule_index += 1 = render(TagRuleFormComponent.new(rule: rule, - rule_data: helpers.rule_data(rule), index: rule_index, customer_tags: group[:tags], hidden_field_customer_tag_options: { "data-tag-rule-group-form-component--tag-rule-group-form-target": "ruleCustomerTag" })) diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index ee5be10b47..ec33789a06 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -76,38 +76,6 @@ module Admin Enterprise::SELLS.map { |s| [I18n.t(s, scope:), s] } end - def rule_data(rule) # rubocop:disable Metrics/MethodLength - case rule.type - when "TagRule::FilterShippingMethods" - { - text_top: t('js.admin.tag_rules.shipping_method_tagged_top'), - text_bottom: t('js.admin.tag_rules.shipping_method_tagged_bottom'), - taggable: "shipping_method", - visibility_field: "shipping_methods", - } - when "TagRule::FilterPaymentMethods" - { - text_top: t('js.admin.tag_rules.payment_method_tagged_top'), - text_bottom: t('js.admin.tag_rules.payment_method_tagged_bottom'), - taggable: "payment_method", - visibility_field: "payment_methods", - } - when "TagRule::FilterOrderCycles" - { - text_top: t('js.admin.tag_rules.order_cycle_tagged_top'), - text_bottom: t('js.admin.tag_rules.order_cycle_tagged_bottom'), - taggable: "exchange", - visibility_field: "order_cycles", - } - when "TagRule::FilterProducts" - { - text_top: t('js.admin.tag_rules.inventory_tagged_top'), - text_bottom: t('js.admin.tag_rules.inventory_tagged_bottom'), - taggable: "variant", - visibility_field: "variants", - } - end - # Group tag rules per rule.preferred_customer_tags def tag_groups(tag_rules) tag_rules.each_with_object([]) do |tag_rule, tag_groups| diff --git a/app/views/admin/enterprises/form/tag_rules/_default_rules.html.haml b/app/views/admin/enterprises/form/tag_rules/_default_rules.html.haml index a60c3ecce8..5f20fd9435 100644 --- a/app/views/admin/enterprises/form/tag_rules/_default_rules.html.haml +++ b/app/views/admin/enterprises/form/tag_rules/_default_rules.html.haml @@ -17,7 +17,7 @@ - else - default_rules.each_with_index do |default_rule, index| - current_rule_index = index + 1 - = render TagRuleFormComponent.new(rule: default_rule, rule_data: rule_data(default_rule), index: index) + = render TagRuleFormComponent.new(rule: default_rule, index: index) %hr .add_rule.text-center diff --git a/app/views/admin/tag_rules/new.turbo_stream.haml b/app/views/admin/tag_rules/new.turbo_stream.haml index c77eff1c3e..2190634063 100644 --- a/app/views/admin/tag_rules/new.turbo_stream.haml +++ b/app/views/admin/tag_rules/new.turbo_stream.haml @@ -4,7 +4,7 @@ - else = turbo_stream.append @div_id do = render(TagRuleFormComponent.new(rule: @default_rule, - rule_data: rule_data(@default_rule), - index: @index, customer_tags: @customer_tags, + index: @index, + customer_tags: @customer_tags, hidden_field_customer_tag_options: { "data-tag-rule-group-form-component--tag-rule-group-form-target": "ruleCustomerTag" })) = turbo_stream.remove_all ".no_rules" diff --git a/config/locales/en.yml b/config/locales/en.yml index 60ec5b7d05..b462f300cb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3668,15 +3668,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using loading_variants: "Loading Variants" no_variants: "No variant available for this product (hidden via inventory settings)." some_variants_hidden: "(Some variants might be hidden via inventory settings)" - tag_rules: - shipping_method_tagged_top: "Shipping methods tagged" - shipping_method_tagged_bottom: "are:" - payment_method_tagged_top: "Payment methods tagged" - payment_method_tagged_bottom: "are:" - order_cycle_tagged_top: "Order Cycles tagged" - order_cycle_tagged_bottom: "are:" - inventory_tagged_top: "Inventory variants tagged" - inventory_tagged_bottom: "are:" enterprise_fees: inherit_from_product: "Inherit From Product" orders: @@ -5072,6 +5063,16 @@ See the %{link} to find out more about %{sitename}'s features and to start using previous: Previous tag_list_input: default_placeholder: Add a tag + tag_rule_form: + tag_rules: + shipping_method_tagged_top: "Shipping methods tagged" + shipping_method_tagged_bottom: "are:" + payment_method_tagged_top: "Payment methods tagged" + payment_method_tagged_bottom: "are:" + order_cycle_tagged_top: "Order Cycles tagged" + order_cycle_tagged_bottom: "are:" + inventory_tagged_top: "Inventory variants tagged" + inventory_tagged_bottom: "are:" tag_rule_group_form: for_customers_tagged: 'For customers tagged:' add_new_rule: '+ Add A New Rule'