diff --git a/app/components/budgets/investments/form_component.html.erb b/app/components/budgets/investments/form_component.html.erb
index ce157d9db..a7e6e2d21 100644
--- a/app/components/budgets/investments/form_component.html.erb
+++ b/app/components/budgets/investments/form_component.html.erb
@@ -44,11 +44,12 @@
<%= render Documents::NestedComponent.new(f) %>
<% end %>
- <%= render "map_locations/form_fields",
- form: f,
- map_location: map_location,
- label: t("budgets.investments.form.map_location"),
- help: t("budgets.investments.form.map_location_instructions") %>
+ <%= render MapLocations::FormFieldsComponent.new(
+ f,
+ map_location: map_location,
+ label: t("budgets.investments.form.map_location"),
+ help: t("budgets.investments.form.map_location_instructions")
+ ) %>
<%= f.text_field :location %>
diff --git a/app/components/map_locations/form_fields_component.html.erb b/app/components/map_locations/form_fields_component.html.erb
new file mode 100644
index 000000000..9d8d02e10
--- /dev/null
+++ b/app/components/map_locations/form_fields_component.html.erb
@@ -0,0 +1,12 @@
+
diff --git a/app/components/map_locations/form_fields_component.rb b/app/components/map_locations/form_fields_component.rb
new file mode 100644
index 000000000..d4235b3e5
--- /dev/null
+++ b/app/components/map_locations/form_fields_component.rb
@@ -0,0 +1,15 @@
+class MapLocations::FormFieldsComponent < ApplicationComponent
+ attr_reader :form, :map_location, :label, :help
+ use_helpers :render_map
+
+ def initialize(form, map_location:, label:, help:)
+ @form = form
+ @map_location = map_location
+ @label = label
+ @help = help
+ end
+
+ def render?
+ feature?(:map)
+ end
+end
diff --git a/app/components/proposals/form_component.html.erb b/app/components/proposals/form_component.html.erb
index 9aec4e6eb..6e7fed36c 100644
--- a/app/components/proposals/form_component.html.erb
+++ b/app/components/proposals/form_component.html.erb
@@ -52,11 +52,12 @@
<% end %>
- <%= render "map_locations/form_fields",
- form: f,
- map_location: map_location,
- label: t("proposals.form.map_location"),
- help: t("proposals.form.map_location_instructions") %>
+ <%= render MapLocations::FormFieldsComponent.new(
+ f,
+ map_location: proposal.map_location || MapLocation.new,
+ label: t("proposals.form.map_location"),
+ help: t("proposals.form.map_location_instructions")
+ ) %>
<%= f.label :tag_list, t("proposals.form.tags_label") %>
diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb
deleted file mode 100644
index 0b0c519c8..000000000
--- a/app/views/map_locations/_form_fields.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-<% if feature?(:map) %>
-
-<% end %>
diff --git a/spec/components/map_locations/form_fields_component_spec.rb b/spec/components/map_locations/form_fields_component_spec.rb
new file mode 100644
index 000000000..d81508877
--- /dev/null
+++ b/spec/components/map_locations/form_fields_component_spec.rb
@@ -0,0 +1,28 @@
+require "rails_helper"
+
+describe MapLocations::FormFieldsComponent do
+ let(:proposal) { Proposal.new }
+ let(:map_location) { MapLocation.new }
+ let(:form) { ConsulFormBuilder.new(:proposal, proposal, ApplicationController.new.view_context, {}) }
+ let(:label) { "Map location" }
+ let(:help) { "Add a marker" }
+ let(:component) do
+ MapLocations::FormFieldsComponent.new(form, map_location: map_location, label: label, help: help)
+ end
+
+ it "is rendered when the map feature is enabled" do
+ Setting["feature.map"] = true
+
+ render_inline component
+
+ expect(page).to be_rendered
+ end
+
+ it "is not rendered when the map feature is not enabled" do
+ Setting["feature.map"] = false
+
+ render_inline component
+
+ expect(page).not_to be_rendered
+ end
+end