Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/controllers/contact/govuk_app/chat_feedback_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Contact::GovukApp::ChatFeedbackController < ApplicationController
include ThrottlingManager

def new; end

def create
ticket = AppChatFeedbackTicket.new(chat_feedback_params)

if ticket.valid?
ticket.save
redirect_to contact_govuk_app_confirmation_path
else
decrement_throttle_counts

@errors = ticket.errors.messages
@ticket = ticket
render "new"
end
end

private

def chat_feedback_params
params[:chat_feedback].slice(
:giraffe,
:feedback,
:reply,
:name,
:email,
).permit!
end
end
9 changes: 6 additions & 3 deletions app/controllers/contact/govuk_app_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ def create
return render "new"
end

if type == "problem"
case type
when "problem"
redirect_to contact_govuk_app_report_problem_path(params: phone_details_params)
else
when "suggestion"
redirect_to contact_govuk_app_make_suggestion_path
when "chat_feedback"
redirect_to contact_govuk_app_chat_feedback_path
end
end

Expand All @@ -29,7 +32,7 @@ def type
def blank_or_invalid_type?
return true unless params[:contact]

%w[problem suggestion].exclude?(type)
%w[problem suggestion chat_feedback].exclude?(type)
end

def errors
Expand Down
36 changes: 36 additions & 0 deletions app/lib/app_chat_feedback_ticket_creator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class AppChatFeedbackTicketCreator < TicketCreator
def subject
"Leave feedback about GOV.UK Chat"
end

def body
<<~MULTILINE_STRING
[Requester]
#{requester_sentence}

[Please leave your feedback]
#{ticket_params[:feedback]}
MULTILINE_STRING
end

def priority
NORMAL_PRIORTIY
end

def tags
%w[govuk_app govuk_app_chat]
end

private

def requester_sentence
requester = ticket_params[:requester] || {}
if requester[:name] && requester[:email]
requester[:name] + " <#{requester[:email]}>"
elsif requester[:email]
requester[:email]
else
"Anonymous"
end
end
end
24 changes: 24 additions & 0 deletions app/models/app_chat_feedback_ticket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class AppChatFeedbackTicket < AppTicket
include ReplyValidation

attr_accessor :feedback

validates :feedback, presence: { message: "Enter your feedback" }
validates :feedback, length: {
maximum: MAX_FIELD_CHARACTERS,
message: "Your feedback must be #{MAX_FIELD_CHARACTERS} characters or less",
}

def save
AppChatFeedbackTicketCreator.new(ticket_params).send if valid_ticket?
end

private

def ticket_params
named = name.presence || "Not submitted"
params = { feedback: }
params[:requester] = { name: named, email: } if can_reply?
params
end
end
123 changes: 123 additions & 0 deletions app/views/contact/govuk_app/chat_feedback/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<% content_for :head do %>
<meta name="robots" content="noindex">
<% end %>

<%
ga4_english_strings = {
page_title: t("controllers.contact.govuk_app.chat_feedback.new.title", locale: :en),
questions: {
feedback: t("controllers.contact.govuk_app.chat_feedback.new.feedback", locale: :en),
reply: t("controllers.contact.govuk_app.shared.can_we_reply", locale: :en),
email: t("controllers.contact.govuk_app.shared.email", locale: :en),
name: t("controllers.contact.govuk_app.shared.name", locale: :en),
},
send_message: t("controllers.contact.govuk_app.chat_feedback.new.send_feedback", locale: :en)
}

ga4_form_tracker_json = {
event_name: "form_response",
type: "contact",
section: ga4_english_strings[:questions].values.join(", "),
action: ga4_english_strings[:send_message],
tool_name: ga4_english_strings[:page_title]
}.to_json
%>

<% if @errors
ga4_erroring_sections = @errors.keys.map do |error_key|
ga4_english_strings[:questions][error_key]
end

ga4_auto_tracker_json = {
event_name: 'form_error',
type: 'contact',
action: 'error',
text: @errors.values.map { |field_errors| field_errors.join(', ') }.join(', '),
section: ga4_erroring_sections.join(', '),
tool_name: ga4_english_strings[:page_title]
}.to_json

content_for :error_summary do
render partial: "shared/error_summary", locals: { ga4_auto_tracker_json: ga4_auto_tracker_json }
end
end %>

<% content_for :title do t("controllers.contact.govuk_app.chat_feedback.new.title") end %>

<%= form_tag contact_govuk_app_chat_feedback_path, method: :post, class: "contact-form", data: { module: "ga4-form-tracker", ga4_form: ga4_form_tracker_json } do |f| %>
<%= render partial: "shared/spam_honeypot", locals: { form_name: "chat_feedback" } %>

<%= render "govuk_publishing_components/components/character_count", {
textarea: {
value: @ticket ? @ticket.feedback : nil,
error_message: @errors ? @errors[:feedback].first : nil,
label: {
text: t("controllers.contact.govuk_app.chat_feedback.new.feedback"),
heading_size: "m"
},
name: "chat_feedback[feedback]"
},
id: "feedback",
maxlength: 1200
} %>

<% reply_inputs = capture do %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: t("controllers.contact.govuk_app.shared.email"),
heading_size: "s"
},
name: "chat_feedback[email]",
id: "email",
value: @ticket ? @ticket.email : nil,
error_message: @errors ? @errors[:email].first : nil,
width: 20,
hint: "We will only use this to reply to your message"
} %>

<%= render "govuk_publishing_components/components/input", {
label: {
text: t("controllers.contact.govuk_app.shared.name"),
heading_size: "s"
},
name: "chat_feedback[name]",
id: "name",
value: @ticket ? @ticket.name : nil,
width: 20
} %>

<br />
<%= t("controllers.contact.govuk_app.shared.personal_information_html") %>
<% end %>

<%= render "govuk_publishing_components/components/radio", {
name: "chat_feedback[reply]",
error_message: @errors ? @errors[:reply].first : nil,
heading: t("controllers.contact.govuk_app.shared.can_we_reply"),
heading_size: "m",
heading_level: 0,
id: "reply",
items: [
{
value: "yes",
text: t("controllers.contact.govuk_app.shared.yes"),
conditional: reply_inputs,
checked: @ticket ? @ticket.reply == "yes" : false,
},
{
value: "no",
text: t("controllers.contact.govuk_app.shared.no"),
checked: @ticket ? @ticket.reply == "no" : false,
}
]
} %>

<p class="govuk-body">
Find out how we use your personal information in the <a class="govuk-link" href="/government/publications/govuk-chat-privacy-notice">privacy notice</a>.
</p>

<%= render "govuk_publishing_components/components/button", {
text: t("controllers.contact.govuk_app.chat_feedback.new.send_feedback"),
margin_bottom: true
} %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/contact/govuk_app/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ end %>
{
value: "suggestion",
text: t("controllers.contact.govuk_app.new.radio_suggestion_text")
},
{
value: "chat_feedback",
text: t("controllers.contact.govuk_app.new.radio_chat_feedback_text")
}
]
} %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ en:
radio_heading: What would you like to do?
radio_problem_text: Report a problem with the app
radio_suggestion_text: Make a suggestion for improving the app
radio_chat_feedback_text: Leave feedback about GOV.UK Chat
continue_text: Continue
description_html: |
<p class="govuk-body">You can use this form to report a problem with the app or make a suggestion for improving the app.</p>
Expand All @@ -50,6 +51,11 @@ en:
new:
title: Make a suggestion about the GOV.UK app
what_is_your_suggestion: What is your suggestion?
chat_feedback:
new:
title: Leave feedback about GOV.UK Chat
feedback: Please leave your feedback
send_feedback: Send feedback
govuk:
contact_govuk:
title: "Contact GOV.UK"
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

get "make-suggestion", to: "suggestions#new"
post "make-suggestion", to: "suggestions#create"

get "leave-feedback-about-govuk-chat", to: "chat_feedback#new", as: "chat_feedback"
post "leave-feedback-about-govuk-chat", to: "chat_feedback#create"
end

root to: redirect("/contact")
Expand Down
63 changes: 63 additions & 0 deletions spec/lib/app_chat_feedback_ticket_creator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "rails_helper"

RSpec.describe AppChatFeedbackTicketCreator do
let(:ticket_params) do
{
requester: {
email: "someone@example.com",
name: "Someone",
},
feedback: "Some feedback",
}
end

let(:support_ticket) { AppChatFeedbackTicketCreator.new(ticket_params) }

it "should inherit from TicketCreator" do
expect(AppChatFeedbackTicketCreator.superclass).to eq(TicketCreator)
end

it "includes priority" do
expect(support_ticket.priority).to eq("normal")
end

it "includes tags" do
expect(support_ticket.tags).to eq(%w[govuk_app govuk_app_chat])
end

it "includes subject" do
expect(support_ticket.subject).to eq("Leave feedback about GOV.UK Chat")
end

describe "#body" do
it "returns body text" do
body = <<~MULTILINE_STRING
[Requester]
Someone <someone@example.com>

[Please leave your feedback]
Some feedback
MULTILINE_STRING

expect(support_ticket.body).to eq(body)
end

it "returns anonymous without requester " do
ticket_params.delete(:requester)
body = <<~MULTILINE_STRING
[Requester]
Anonymous
MULTILINE_STRING
expect(support_ticket.body).to include(body)
end

it "returns only email if name isn't present" do
ticket_params[:requester].delete(:name)
body = <<~MULTILINE_STRING
[Requester]
someone@example.com
MULTILINE_STRING
expect(support_ticket.body).to include(body)
end
end
end
Loading
Loading