diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 39338157d..6bae9e7c8 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -20,20 +20,15 @@ class CaseLogsController < ApplicationController end def next_question - subsection = params[:subsection] @case_log = CaseLog.find(params[:case_log_id]) - next_question = if subsection - Form::FIRST_QUESTION_FOR_SUBSECTION[subsection] - else - previous_question = params[:previous_question] - answer = params[previous_question] - @case_log.update!(previous_question => answer) - Form::QUESTIONS[previous_question] - end - render next_question, locals: { case_log_id: @case_log.id } + previous_question = params[:previous_question] + previous_answer = params[previous_question] + @case_log.update!(previous_question => previous_answer) + next_question = Form::QUESTIONS[previous_question] + redirect_to(send("case_log_#{next_question}_path", @case_log)) end - Form::QUESTIONS.keys.each do |question| + Form::QUESTIONS.each_key do |question| define_method(question) do @case_log = CaseLog.find(params[:case_log_id]) render "form/questions/#{question}", locals: { case_log_id: @case_log.id } diff --git a/app/models/form.rb b/app/models/form.rb index e57986aee..6f322cc33 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -1,15 +1,39 @@ class Form < ApplicationRecord self.abstract_class = true - FIRST_QUESTION_FOR_SUBSECTION = { - "Household characteristics" => "form/questions/tenant_code", - "Household situation" => "form/questions/previous_housing_situation" + SECTIONS = { + "About the household" => %w[household_characteristics household_situation household_needs], + "Tenancy and property information" => %w[tenancy_information property_information], + "Rent and charges" => %w[income_and_benefits rent], + "Local Authority" => %w[local_authority], + "Submission" => %w[declaration], + }.freeze + + SUBSECTIONS = { + "household_characteristics" => "tenant_code", + "household_situation" => "previous_housing_situation", + "household_needs" => "tenant_code", + "tenancy_information" => "tenant_code", + "property_information" => "tenant_code", + "income_and_benefits" => "tenant_code", + "rent" => "tenant_code", + "local_authority" => "tenant_code", + "declaration" => "tenant_code", }.freeze QUESTIONS = { - "tenant_code" => "form/questions/tenant_age", - "tenant_age" => "form/questions/tenant_gender", - "tenant_gender" => "form/questions/tenant_ethnic_group", - "tenant_ethnic_group" => "form/questions/tenant_nationality", + "tenant_code" => "tenant_age", + "tenant_age" => "tenant_gender", + "tenant_gender" => "tenant_ethnic_group", + "tenant_ethnic_group" => "tenant_nationality", + "previous_housing_situation" => "previous_housing_situation", }.freeze + + def self.first_question_for_subsection(subsection) + SUBSECTIONS[subsection] + end + + def self.next_question(previous_question) + Form::QUESTIONS[previous_question] + end end diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb index af4267f3a..5c3d161d9 100644 --- a/app/views/case_logs/_tasklist.html.erb +++ b/app/views/case_logs/_tasklist.html.erb @@ -1,25 +1,19 @@ -<%# Placeholder until we have a real form schema %> -<% - sections = { - "About the household" => ["Household characteristics", "Household situation", "Household needs"], - "Tenancy and property information" => ["Tenancy information", "Property information"], - "Rent and charges" => ["Income & benefits", "Rent"], - "Local Authority" => ["Local authority"], - "Submission" => ["Declaration"] - } -%> -