diff --git a/app/components/routes_section_component/view.html.erb b/app/components/routes_section_component/view.html.erb new file mode 100644 index 000000000..db788650c --- /dev/null +++ b/app/components/routes_section_component/view.html.erb @@ -0,0 +1,3 @@ +

<%= t("pages.routes_section.heading") %>

+

<%= t("pages.routes_section.#{message_key}", routes_path: routes_path(form_id: @page.form_id, anchor: @page.page_position_id)) %>

+
diff --git a/app/components/routes_section_component/view.rb b/app/components/routes_section_component/view.rb new file mode 100644 index 000000000..1542e2daa --- /dev/null +++ b/app/components/routes_section_component/view.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module RoutesSectionComponent + class View < ApplicationComponent + include Rails.application.routes.url_helpers + + def initialize(page:, draft_question:) + super() + @page = page + @draft_question = draft_question + end + + def render? + message_key.present? + end + + def message_key + @message_key ||= if @page.routing_conditions.any? + "has_routes_html" + elsif selection_question_with_one_option_only? + "conditional_routes_html" + elsif @page.has_next_page? + "skip_questions_html" + end + end + + private + + def selection_question_with_one_option_only? + @draft_question.answer_type == "selection" && + @draft_question.answer_settings[:only_one_option] == "true" && + @draft_question.answer_settings[:selection_options].length <= 10 + end + end +end diff --git a/app/views/pages/_form.html.erb b/app/views/pages/_form.html.erb index bb4b64612..0e5383f22 100644 --- a/app/views/pages/_form.html.erb +++ b/app/views/pages/_form.html.erb @@ -52,6 +52,8 @@

<%= t("pages.answer_settings") %>

<%= render PageSettingsSummaryComponent::View.new(draft_question:, errors: question_input.errors) %> + <%= render RoutesSectionComponent::View.new(page: page_object, draft_question:) unless is_new_page %> +