Move budget headings form partial to a component

This way it'll be easier to test it.
This commit is contained in:
Javi Martín
2023-04-26 18:02:54 +02:00
parent c6c09074df
commit ca013cf9f1
6 changed files with 35 additions and 6 deletions

View File

@@ -12,7 +12,7 @@
<% end %>
<div class="small-12 medium-6">
<% if @budget.show_money? %>
<% if budget.show_money? %>
<%= f.text_field :price, maxlength: 8 %>
<% else %>
<%= f.hidden_field :price, value: 0 %>
@@ -41,7 +41,7 @@
</div>
<div class="clear">
<% if respond_to?(:single_heading?) && single_heading? %>
<% if single_heading? %>
<%= f.submit t("admin.budgets_wizard.headings.continue"), class: "button success" %>
<% else %>
<%= f.submit t("admin.budget_headings.form.#{action}"), class: "button hollow" %>

View File

@@ -0,0 +1,21 @@
class Admin::BudgetHeadings::FormComponent < ApplicationComponent
include TranslatableFormHelper
include GlobalizeHelper
attr_reader :heading, :path, :action
def initialize(heading, path:, action:)
@heading = heading
@path = path
@action = action
end
private
def budget
heading.budget
end
def single_heading?
helpers.respond_to?(:single_heading?) && helpers.single_heading?
end
end

View File

@@ -1,3 +1,3 @@
<%= render Admin::BudgetsWizard::CreationStepComponent.new(heading, next_step_path) do %>
<%= render "/admin/budget_headings/form", heading: heading, path: form_path, action: "create" %>
<%= render Admin::BudgetHeadings::FormComponent.new(heading, path: form_path, action: "create") %>
<% end %>

View File

@@ -4,4 +4,4 @@
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("headings") %>
<%= render "/admin/budget_headings/form", heading: heading, path: form_path, action: "submit" %>
<%= render Admin::BudgetHeadings::FormComponent.new(heading, path: form_path, action: "submit") %>

View File

@@ -1,3 +1,7 @@
<%= render "header", action: "edit" %>
<%= render "form", heading: @heading, path: admin_budget_group_heading_path(@budget, @group, @heading), action: "submit" %>
<%= render Admin::BudgetHeadings::FormComponent.new(
@heading,
path: admin_budget_group_heading_path(@budget, @group, @heading),
action: "submit"
) %>

View File

@@ -1,3 +1,7 @@
<%= render "header", action: "create" %>
<%= render "form", heading: @heading, path: admin_budget_group_headings_path(@budget, @group), action: "create" %>
<%= render Admin::BudgetHeadings::FormComponent.new(
@heading,
path: admin_budget_group_headings_path(@budget, @group),
action: "create"
) %>