Skip to content

Commit 9801d57

Browse files
authored
Merge pull request #33 from alphagov/main-7279-create-ui-for-response
Main 7279 - Create UI for happy path response
2 parents f780395 + 1a6453c commit 9801d57

17 files changed

+338
-31
lines changed

app/assets/config/manifest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
//= link_tree ../images
22
//= link application.js
33
//= link_tree ../builds
4+
//= link es6-components.js

app/assets/javascripts/application.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
//= require govuk_publishing_components/dependencies
44
//= require govuk_publishing_components/lib
55

6-
// Analytics modules
7-
// require analytics_modules/ga4-form-setup
8-
// require analytics_modules/ga4-form-change-tracker
9-
// require analytics_modules/ga4-index-section-setup
10-
116
window.GOVUK.approveAllCookieTypes()
127
window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// These modules from govuk_publishing_components
2+
// depend on govuk-frontend modules. govuk-frontend
3+
// now targets browsers that support `type="module"`.
4+
//
5+
// To gracefully prevent execution of these scripts
6+
// on browsers that don't support ES6, this script
7+
// should be included in a `type="module"` script tag
8+
// which will ensure they are never loaded.
9+
10+
//= require govuk_publishing_components/components/radio

app/assets/stylesheets/application.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ $govuk-page-width: 1140px;
66
@import 'govuk_publishing_components/components/back-link';
77
@import 'govuk_publishing_components/components/button';
88
@import 'govuk_publishing_components/components/error-summary';
9+
@import 'govuk_publishing_components/components/fieldset';
910
@import 'govuk_publishing_components/components/govspeak';
1011
@import 'govuk_publishing_components/components/heading';
1112
@import 'govuk_publishing_components/components/inset-text';
1213
@import 'govuk_publishing_components/components/layout-footer';
1314
@import 'govuk_publishing_components/components/layout-for-admin';
1415
@import 'govuk_publishing_components/components/layout-header';
16+
@import 'govuk_publishing_components/components/panel';
17+
@import 'govuk_publishing_components/components/radio';
1518
@import 'govuk_publishing_components/components/skip-link';
19+
@import 'govuk_publishing_components/components/summary-list';
1620
@import 'govuk_publishing_components/components/tag';
21+
@import 'govuk_publishing_components/components/textarea';
1722
@import "nokodiff";
1823
@import "options_sidebar";
1924
@import "compare-editions";
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class FactCheckResponseController < ApplicationController
2+
def respond_to_fact_check
3+
session.delete(:fact_check_response) unless params[:back]
4+
@article_title = "Title"
5+
@errors = {}
6+
@form_data = session[:fact_check_response] || {}
7+
8+
render :fact_check_response
9+
end
10+
11+
def verify_fact_check_response
12+
@form_data = permitted_params
13+
@errors = validate(@form_data)
14+
15+
if @errors.any?
16+
@article_title = "Title"
17+
render :fact_check_response
18+
else
19+
session[:fact_check_response] = @form_data
20+
confirm_response
21+
end
22+
end
23+
24+
def confirm_response
25+
render :confirm_response
26+
end
27+
28+
def send_response
29+
# TODO: API submission here
30+
31+
fact_check_submitted
32+
end
33+
34+
def fact_check_submitted
35+
render :fact_check_submitted
36+
end
37+
38+
private
39+
40+
def permitted_params
41+
params.fetch(:fact_check_response, {})
42+
.permit(:page_title, :page_id, :status, :details)
43+
end
44+
45+
def validate(data)
46+
errors = {}
47+
errors[:status] = t("fact_check_response.selection_error") if data[:status].blank?
48+
49+
if data[:status] == "incorrect" && data[:details].blank?
50+
errors[:details] = t("fact_check_response.factual_errors_empty_field")
51+
end
52+
53+
errors
54+
end
55+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<% content_for :page_title, @form_data[:page_title] %>
2+
<% content_for :title_context, @form_data[:page_title] %>
3+
<% content_for :back_link, respond_path(back: :true) %>
4+
<% content_for :title, t("fact_check_verification.heading") %>
5+
<div class="govuk-grid-row">
6+
<div class="govuk-grid-column-two-thirds">
7+
<%= form_with url: confirm_response_path,
8+
method: :post,
9+
scope: :fact_check_response do |confirm| %>
10+
<%= hidden_field_tag "status", @form_data[:status] %>
11+
<%= hidden_field_tag "details", @form_data[:details] %>
12+
<%= render "govuk_publishing_components/components/summary_list", {
13+
items: [
14+
{
15+
field: t("fact_check_verification.confirm_changes"),
16+
edit: {
17+
href: respond_path(back: :true),
18+
text: t("fact_check_verification.change_link"),
19+
},
20+
value: @form_data[:status] == "correct" ?
21+
t("fact_check_response.correct") :
22+
t("fact_check_response.incorrect"),
23+
},
24+
],
25+
margin_bottom: 6,
26+
} %>
27+
28+
<%= render "govuk_publishing_components/components/heading", {
29+
text: t("fact_check_verification.send_response"),
30+
margin_bottom: 6,
31+
} %>
32+
33+
<%= render "govuk_publishing_components/components/warning_text", {
34+
text: t("fact_check_verification.send_response_warning"),
35+
} %>
36+
37+
<%= render "govuk_publishing_components/components/button", {
38+
text: t("fact_check_verification.confirm_button"),
39+
margin_bottom: 6,
40+
} %>
41+
42+
<% end %>
43+
</div>
44+
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%= render "govuk_publishing_components/components/textarea", {
2+
label: {
3+
text: t("fact_check_response.factual_errors"),
4+
heading_size: "m",
5+
},
6+
name: "fact_check_response[details]",
7+
textarea_id: "fact_check_details",
8+
hint: sanitize(t("fact_check_response.factual_errors_hint")),
9+
error: @errors[:details].presence,
10+
rows: 18,
11+
} %>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%= render "govuk_publishing_components/components/error_summary", {
2+
id: "error-summary",
3+
title: t("fact_check_response.error_heading"),
4+
items: [
5+
{
6+
text: @errors[:status] || @errors[:details],
7+
href: @errors[:status].present? ? "#selection_radio_buttons" : "#fact_check_details",
8+
},
9+
],
10+
} %>

app/views/application/fact_check_comparison.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% content_for :title_context, @article_title %>
2-
<% content_for :title, t("fact_check_comparison.fact_check_heading") %>
2+
<% content_for :title, t("fact_check_comparison.heading") %>
33

44
<div class="govuk-grid-row">
55
<div class="govuk-grid-column-two-thirds">
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<% content_for :page_title, @article_title %>
2+
<% content_for :title_context, @article_title %>
3+
<% content_for :back_link, "_blank" %>
4+
<% content_for :title, t("fact_check_response.heading") %>
5+
<% if @errors.any? %>
6+
<% content_for :error_summary, render(partial: "application/confirmations/response_error_summary") %>
7+
<% end %>
8+
<div class="govuk-grid-row">
9+
<div class="govuk-grid-column-two-thirds">
10+
<%= form_with url: respond_path,
11+
method: :post,
12+
scope: :fact_check_response do |f| %>
13+
<%= f.hidden_field :page_title, :value => @article_title %>
14+
<%= f.hidden_field :page_id, :value => "id" %>
15+
<%= render "govuk_publishing_components/components/radio", {
16+
name: "fact_check_response[status]",
17+
heading: t("fact_check_response.form_heading"),
18+
id: "selection_radio_buttons",
19+
visually_hidden_heading: true,
20+
error_message: (@errors[:status].presence),
21+
items: [
22+
{
23+
value: "correct",
24+
text: t("fact_check_response.correct"),
25+
id: "correct",
26+
checked: @form_data.present? && @form_data["status"] == "correct",
27+
},
28+
{
29+
value: "incorrect",
30+
text: t("fact_check_response.incorrect"),
31+
id: "incorrect",
32+
checked: @errors[:details].present? || @form_data.present? && @form_data["status"] == "incorrect",
33+
conditional: render(partial: "application/confirmations/factual_error_textarea"),
34+
},
35+
],
36+
} %>
37+
38+
<%= render "govuk_publishing_components/components/button", {
39+
text: t("fact_check_response.continue_button"),
40+
margin_bottom: 6,
41+
} %>
42+
<% end %>
43+
</div>
44+
</div>

0 commit comments

Comments
 (0)