Skip to content

Commit 58a5a96

Browse files
authored
Merge pull request #1967 from alphagov/copy-of-answers
Add initial "Copy of answers" screen
2 parents 0bb161c + 51e1980 commit 58a5a96

23 files changed

+546
-10
lines changed

.review_apps/ecs_task_definition.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ locals {
2424
{ name = "SETTINGS__FORMS_ADMIN__BASE_URL", value = "https://${local.admin_app_hostname}" },
2525
{ name = "SETTINGS__FORMS_API__BASE_URL", value = "http://localhost:3000" },
2626
{ name = "SETTINGS__FORMS_ENV", value = "review" },
27+
{ name = "SETTINGS__FEATURES__FILLER_ANSWER_EMAIL_ENABLED", value = "true" }
2728

2829
##
2930
# Settings for AWS SES email sending, and S3 CSV submission and file upload

app/controllers/forms/check_your_answers_controller.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ def setup_check_your_answers
7272
end
7373

7474
def back_link
75-
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
76-
77-
if previous_step.present?
78-
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
75+
if FeatureService.enabled?("filler_answer_email_enabled")
76+
copy_of_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
77+
else
78+
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
79+
80+
if previous_step.present?
81+
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
82+
end
7983
end
8084
end
8185
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Forms
2+
class CopyOfAnswersController < BaseController
3+
before_action :redirect_if_feature_disabled
4+
5+
def show
6+
return redirect_to form_page_path(current_context.form.id, current_context.form.form_slug, current_context.next_page_slug) unless can_visit_copy_of_answers?
7+
8+
@back_link = back_link
9+
@copy_of_answers_input = CopyOfAnswersInput.new
10+
end
11+
12+
def save
13+
@copy_of_answers_input = CopyOfAnswersInput.new(copy_of_answers_params)
14+
15+
unless @copy_of_answers_input.valid?
16+
@back_link = back_link
17+
return render :show, status: :unprocessable_content
18+
end
19+
20+
current_context.save_copy_of_answers_preference(@copy_of_answers_input.wants_copy?)
21+
22+
redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
23+
end
24+
25+
private
26+
27+
def copy_of_answers_params
28+
params.require(:copy_of_answers_input).permit(:copy_of_answers)
29+
end
30+
31+
def can_visit_copy_of_answers?
32+
current_context.can_visit?(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
33+
end
34+
35+
def back_link
36+
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
37+
38+
if previous_step.present?
39+
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
40+
end
41+
end
42+
43+
def redirect_if_feature_disabled
44+
return if FeatureService.enabled?("filler_answer_email_enabled")
45+
46+
redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
47+
end
48+
end
49+
end

app/controllers/forms/page_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ def next_step_changing
148148
end
149149

150150
def next_step_in_form_path
151-
form_page_path(@form.id, @form.form_slug, @step.next_page_slug_after_routing)
151+
if @step.next_page_slug_after_routing == CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG
152+
if FeatureService.enabled?("filler_answer_email_enabled")
153+
copy_of_answers_path(form_id: @form.id, form_slug: @form.form_slug)
154+
else
155+
check_answers_path
156+
end
157+
else
158+
form_page_path(@form.id, @form.form_slug, @step.next_page_slug_after_routing)
159+
end
152160
end
153161

154162
def check_answers_path
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CopyOfAnswersInput
2+
include ActiveModel::Model
3+
include ActiveModel::Validations
4+
5+
attr_accessor :copy_of_answers
6+
7+
RADIO_OPTIONS = { yes: "yes", no: "no" }.freeze
8+
9+
validates :copy_of_answers, presence: true, inclusion: { in: RADIO_OPTIONS.values }
10+
11+
def wants_copy?
12+
copy_of_answers == RADIO_OPTIONS[:yes]
13+
end
14+
15+
def values
16+
RADIO_OPTIONS.keys
17+
end
18+
end

app/lib/flow/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(form:, store:)
1212
delegate :support_details, to: :form
1313
delegate :find_or_create, :previous_step, :next_page_slug, :next_step, :can_visit?, :completed_steps, :all_steps, to: :journey
1414
delegate :clear_stored_answer, :clear, :form_submitted?, :answers, :locales_used, to: :answer_store
15-
delegate :save_submission_details, :get_submission_reference, :requested_email_confirmation?, :clear_submission_details, to: :confirmation_details_store
15+
delegate :save_submission_details, :get_submission_reference, :requested_email_confirmation?, :clear_submission_details, :save_copy_of_answers_preference, :wants_copy_of_answers?, to: :confirmation_details_store
1616

1717
def save_step(step, locale: :en, context: nil)
1818
return false unless step.valid?(context)

app/lib/store/confirmation_details_store.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ConfirmationDetailsStore
33
CONFIRMATION_KEY = :confirmation_details
44
SUBMISSION_REFERENCE_KEY = :submission_reference
55
REQUESTED_EMAIL_KEY = :requested_email_confirmation
6+
COPY_OF_ANSWERS_KEY = :wants_copy_of_answers
67

78
def initialize(store, form_id)
89
@store = store
@@ -24,6 +25,15 @@ def requested_email_confirmation?
2425
@store.dig(CONFIRMATION_KEY, @form_key, REQUESTED_EMAIL_KEY.to_s)
2526
end
2627

28+
def save_copy_of_answers_preference(wants_copy)
29+
@store[CONFIRMATION_KEY][@form_key] ||= {}
30+
@store[CONFIRMATION_KEY][@form_key][COPY_OF_ANSWERS_KEY.to_s] = wants_copy
31+
end
32+
33+
def wants_copy_of_answers?
34+
@store.dig(CONFIRMATION_KEY, @form_key, COPY_OF_ANSWERS_KEY.to_s)
35+
end
36+
2737
def clear_submission_details
2838
@store[CONFIRMATION_KEY][@form_key] = nil
2939
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<% set_page_title(form_title(form_name: @current_context.form.name, page_name: t('.title'), mode: @mode, error: @copy_of_answers_input&.errors&.any?)) %>
2+
3+
<% content_for :back_link do %>
4+
<% if @back_link.present? %>
5+
<%= link_to t("forms.back"), @back_link, class: "govuk-back-link" %>
6+
<% end %>
7+
<% end %>
8+
9+
<%= form_with(model: @copy_of_answers_input, method: :post, url: save_copy_of_answers_path(form_id: @form.id, form_slug: @form.form_slug)) do |f| %>
10+
<div class="govuk-grid-row">
11+
<div class="govuk-grid-column-two-thirds">
12+
<% if @copy_of_answers_input&.errors&.any? %>
13+
<%= f.govuk_error_summary(t("error_summary_title")) %>
14+
<% end %>
15+
16+
<%= f.govuk_collection_radio_buttons :copy_of_answers,
17+
@copy_of_answers_input.values, ->(option) { option }, ->(option) { t("helpers.label.copy_of_answers_input.options.#{option}") },
18+
legend: { text: t('.heading'), tag: 'h1', size: 'l' },
19+
hint: { text: t('.hint') } %>
20+
21+
<%= f.govuk_submit(t("continue")) %>
22+
</div>
23+
</div>
24+
<% end %>

config/locales/cy.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ cy:
8383
add_another_answer:
8484
blank: Dewiswch ydw os ydych angen ychwanegu ateb arall
8585
max_answers_reached: Dewiswch ydw os ydych angen ychwanegu ateb arall
86+
copy_of_answers_input:
87+
attributes:
88+
copy_of_answers:
89+
blank: PLACEHOLDER! Dewiswch ydw os hoffech dderbyn copi o'ch atebion
8690
email_confirmation_input:
8791
attributes:
8892
confirmation_email_address:
@@ -378,6 +382,11 @@ cy:
378382
view_english_form: 'Gallwch lenwi’r ffurflen yn Saesneg o hyd:'
379383
welsh_version_archived: Mae’r fersiwn Gymraeg o’r ffurflen hon wedi’i harchifo ac nid yw ar gael mwyach.
380384
back: Yn ôl
385+
copy_of_answers:
386+
show:
387+
heading: PLACEHOLDER! Ydych chi eisiau copi o'ch atebion?
388+
hint: PLACEHOLDER! Byddwn ond yn defnyddio'r cyfeiriad e-bost rydych yn ei ddarparu yma i anfon cadarnhad bod eich ffurflen wedi'i chyflwyno'n llwyddiannus. Ni fydd yn cynnwys copi o'ch atebion.
389+
title: PLACEHOLDER! Ydych chi eisiau copi o'ch atebion?
381390
remove_answer:
382391
show:
383392
address_heading: Dileu cyfeiriad
@@ -414,6 +423,10 @@ cy:
414423
options:
415424
'no': Na
416425
'yes': Ydw
426+
copy_of_answers_input:
427+
options:
428+
'no': Na
429+
'yes': Ydw
417430
email_confirmation_input:
418431
confirmation_email_address: Pa gyfeiriad e-bost ydych chi eisiau i ni anfon eich cadarnhad ato?
419432
send_confirmation_options:

config/locales/en.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ en:
8383
add_another_answer:
8484
blank: Select ‘Yes’ if you need to add another answer
8585
max_answers_reached: You cannot add another answer
86+
copy_of_answers_input:
87+
attributes:
88+
copy_of_answers:
89+
blank: Select 'Yes' if you want to get a copy of your answers
8690
email_confirmation_input:
8791
attributes:
8892
confirmation_email_address:
@@ -378,6 +382,11 @@ en:
378382
view_english_form: 'You can still complete the form in English:'
379383
welsh_version_archived: The Welsh version of this form has been archived and is no longer available.
380384
back: Back
385+
copy_of_answers:
386+
show:
387+
heading: Do you want to get an email with a copy of your answers?
388+
hint: You’ll need a GOV.UK One Login for this - you’ll be able to create one now if you do not already have one.
389+
title: Do you want a copy of your answers?
381390
remove_answer:
382391
show:
383392
address_heading: Remove an address
@@ -414,6 +423,10 @@ en:
414423
options:
415424
'no': 'No'
416425
'yes': 'Yes'
426+
copy_of_answers_input:
427+
options:
428+
'no': 'No'
429+
'yes': 'Yes'
417430
email_confirmation_input:
418431
confirmation_email_address: What email address do you want us to send your confirmation to?
419432
send_confirmation_options:

0 commit comments

Comments
 (0)