16 changed files with 254 additions and 20 deletions
@ -0,0 +1,25 @@
|
||||
class Form::Sales::Pages::AddressFallback < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address" |
||||
@header = "Q12 - What is the property's address?" |
||||
@depends_on = [ |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil, "address_selection" => 100 }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0, "address_selection" => 100 }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0, "address_selection" => 100 }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil, "address_options_present?" => false }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0, "address_options_present?" => false }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0, "address_options_present?" => false }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::AddressLine1.new(nil, nil, self), |
||||
Form::Sales::Questions::AddressLine2.new(nil, nil, self), |
||||
Form::Sales::Questions::TownOrCity.new(nil, nil, self), |
||||
Form::Sales::Questions::County.new(nil, nil, self), |
||||
Form::Sales::Questions::PostcodeForFullAddress.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
||||
@ -0,0 +1,19 @@
|
||||
class Form::Sales::Pages::AddressMatcher < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address_matcher" |
||||
@header = "Find an address" |
||||
@depends_on = [ |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0 }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0 }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::AddressLine1ForAddressMatcher.new(nil, nil, self), |
||||
Form::Sales::Questions::PostcodeForAddressMatcher.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
||||
@ -0,0 +1,28 @@
|
||||
class Form::Sales::Pages::AddressSelection < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address_selection" |
||||
@header = "We found some addresses that might be this property" |
||||
@depends_on = [{ "address_options_present?" => true }] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::AddressSelection.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(log, _current_user = nil) |
||||
(log.uprn_known.nil? || log.uprn_known.zero?) && log.address_line1_input.present? && log.postcode_full_input.present? && (1..10).cover?(log.address_options&.count) |
||||
end |
||||
|
||||
def skip_text |
||||
"Search for address again" |
||||
end |
||||
|
||||
def skip_href(log = nil) |
||||
return unless log |
||||
|
||||
"/#{log.model_name.param_key.dasherize}s/#{log.id}/address-matcher" |
||||
end |
||||
end |
||||
@ -0,0 +1,26 @@
|
||||
class Form::Sales::Pages::NoAddressFound < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "no_address_found" |
||||
@type = "interruption_screen" |
||||
@title_text = { |
||||
"translation" => "soft_validations.no_address_found.title_text", |
||||
"arguments" => [], |
||||
} |
||||
@informative_text = { |
||||
"translation" => "soft_validations.no_address_found.informative_text", |
||||
"arguments" => [], |
||||
} |
||||
@depends_on = [{ "address_options_present?" => false }] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::NoAddressFound.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[address_line1_input] |
||||
end |
||||
end |
||||
@ -0,0 +1,20 @@
|
||||
class Form::Sales::Questions::AddressLine1ForAddressMatcher < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_line1_input" |
||||
@header = "Address line 1" |
||||
@error_label = "Address line 1" |
||||
@type = "text" |
||||
@plain_label = true |
||||
@check_answer_label = "Find address" |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
@hide_question_number_on_page = true |
||||
end |
||||
|
||||
def answer_label(log, _current_user = nil) |
||||
[ |
||||
log.address_line1_input, |
||||
log.postcode_full_input, |
||||
].select(&:present?).join("\n") |
||||
end |
||||
end |
||||
@ -0,0 +1,34 @@
|
||||
class Form::Sales::Questions::AddressSelection < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_selection" |
||||
@header = "Select the correct address" |
||||
@type = "radio" |
||||
@check_answer_label = "Select the correct address" |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
end |
||||
|
||||
def answer_options(log = nil, _user = nil) |
||||
answer_opts = { "100" => { "value" => "The address is not listed, I want to enter the address manually" } } |
||||
return answer_opts unless ActiveRecord::Base.connected? |
||||
return answer_opts unless log&.address_options |
||||
|
||||
answer_opts = {} |
||||
|
||||
(0...[log.address_options.count, 10].min).each do |i| |
||||
answer_opts[i.to_s] = { "value" => log.address_options[i] } |
||||
end |
||||
|
||||
answer_opts["divider"] = { "value" => true } |
||||
answer_opts["100"] = { "value" => "The address is not listed, I want to enter the address manually" } |
||||
answer_opts |
||||
end |
||||
|
||||
def displayed_answer_options(log, user = nil) |
||||
answer_options(log, user) |
||||
end |
||||
|
||||
def hidden_in_check_answers?(log, _current_user = nil) |
||||
(log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options&.count) |
||||
end |
||||
end |
||||
@ -0,0 +1,9 @@
|
||||
class Form::Sales::Questions::NoAddressFound < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_search_value_check" |
||||
@header = "No address found" |
||||
@type = "interruption_screen" |
||||
@hidden_in_check_answers = true |
||||
end |
||||
end |
||||
@ -0,0 +1,13 @@
|
||||
class Form::Sales::Questions::PostcodeForAddressMatcher < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "postcode_full_input" |
||||
@header = "Postcode" |
||||
@type = "text" |
||||
@width = 5 |
||||
@plain_label = true |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
@hide_question_number_on_page = true |
||||
@hidden_in_check_answers = true |
||||
end |
||||
end |
||||
@ -0,0 +1,5 @@
|
||||
class AddAddressSearchValueCheckToSalesLogs < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :sales_logs, :address_search_value_check, :integer |
||||
end |
||||
end |
||||
Loading…
Reference in new issue