Skip to content
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 34 deletions.
37 changes: 17 additions & 20 deletions app/contact/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ContactRadioInput,
ContactCheckboxInput,
ContactSelectField,
ContactTextInput,
)
from wtforms.fields import SubmitField
from app.categories.widgets import CategoryCheckboxInput
Expand Down Expand Up @@ -560,26 +561,6 @@ def get_callback_time(self) -> datetime | None:

return None

@staticmethod
def format_callback_time(
start_time: datetime, callback_duration: timedelta = timedelta(minutes=30)
) -> str | None:
"""Helper function to format the callback time string.
Returns:
str | None: formatted callback time string in the form of "Friday, 3 January at 09:00 - 09:30"
"""
if not start_time or not isinstance(start_time, datetime):
return None
end_time = start_time + callback_duration

formatted_start_date = start_time.strftime(
"%A, %d %B at %H:%M"
) # E.g. Monday, 1 January at 09:00
formatted_end_time = end_time.strftime("%H:%M") # E.g. 09:30

return f"{formatted_start_date} - {formatted_end_time}"

def get_payload(self) -> dict:
"""Returns the contact payload."""

Expand Down Expand Up @@ -635,3 +616,19 @@ def get_payload(self) -> dict:
payload["requires_action_at"] = requires_action_at

return payload


class ConfirmationEmailForm(FlaskForm):
email = StringField(
_("Receive this confirmation by email"),
widget=ContactTextInput(
heading_class="govuk-fieldset__legend--s",
hint_text=_("We will use this to send your reference number."),
),
validators=[
Length(max=255, message=_("Your address must be 255 characters or less")),
Email(message=_("Enter a valid email address")),
InputRequired(message=_("Tell us what email address to send to")),
],
)
submit = SubmitField(_("Send"), widget=GovSubmitInput())
23 changes: 23 additions & 0 deletions app/contact/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime, timedelta
from app.contact import bp


@bp.app_template_filter("format_callback_time")
def format_callback_time(
start_time: datetime, callback_duration: timedelta = timedelta(minutes=30)
) -> str | None:
"""Helper function to format the callback time string.
Returns:
str | None: formatted callback time string in the form of "Friday, 3 January at 09:00 - 09:30"
"""
if not start_time or not isinstance(start_time, datetime):
return None
end_time = start_time + callback_duration

formatted_start_date = start_time.strftime(
"%A, %d %B at %H:%M"
) # E.g. Monday, 1 January at 09:00
formatted_end_time = end_time.strftime("%H:%M") # E.g. 09:30

return f"{formatted_start_date} - {formatted_end_time}"
4 changes: 2 additions & 2 deletions app/contact/notify/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from app import get_locale
from app.contact.notify.templates import GOVUK_NOTIFY_TEMPLATES
from app.contact.forms import ContactUsForm
from app.contact.helpers import format_callback_time

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -92,7 +92,7 @@ def generate_confirmation_email_data(
third_party_phone_number: str | None = None,
) -> (str, str):
"""Generates the data used in the sending of the confirmation Gov Notify emails."""
formatted_callback_time = ContactUsForm.format_callback_time(callback_time)
formatted_callback_time = format_callback_time(callback_time)
callback_requested = callback_time is not None

template_id = ""
Expand Down
29 changes: 26 additions & 3 deletions app/contact/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from flask.views import View
from app.contact.forms import ContactUsForm, ReasonsForContactingForm
from app.contact.forms import (
ContactUsForm,
ReasonsForContactingForm,
ConfirmationEmailForm,
)
import logging
from flask import session, render_template, request, redirect, url_for
from app.api import cla_backend
Expand Down Expand Up @@ -105,10 +109,29 @@ def _attach_rfc_to_case(case_ref: str, rfc_ref: str):

class ConfirmationPage(View):
template = "contact/confirmation.html"
methods = ["GET", "POST"]

@staticmethod
def get_context():
return {}
return {
"case_reference": session.get("case_reference"),
"callback_time": session.get("callback_time"),
"contact_type": session.get("contact_type"),
}

def dispatch_request(self):
return render_template(self.template, **self.get_context())
form = ConfirmationEmailForm()
if form.validate_on_submit():
notify.create_and_send_confirmation_email(
form.email.data,
session.get("case_reference"),
session.get("callback_time"),
session.get("contact_type"),
)
return render_template(
self.template,
form=form,
confirmation_email=form.email.data,
**self.get_context(),
)
return render_template(self.template, form=form, **self.get_context())
10 changes: 9 additions & 1 deletion app/contact/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from govuk_frontend_wtf.wtforms_widgets import GovRadioInput, GovCheckboxesInput
from govuk_frontend_wtf.wtforms_widgets import (
GovRadioInput,
GovCheckboxesInput,
GovTextInput,
)
from app.means_test.widgets import MeansTestInputField
from wtforms import SelectField

Expand All @@ -15,3 +19,7 @@ class ContactSelectField(SelectField):
def pre_validate(self, form):
"""Override to prevent WTForms' internal choice validation"""
pass


class ContactTextInput(MeansTestInputField, GovTextInput):
pass
5 changes: 4 additions & 1 deletion app/means_test/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def map_gov_params(self, field, **kwargs):
item["checked"] = True

label_class = self.heading_class
params["fieldset"]["legend"]["classes"] = label_class
if "fieldset" in params:
params["fieldset"]["legend"]["classes"] = label_class
else:
params["label"]["classes"] = label_class
return params


Expand Down
45 changes: 38 additions & 7 deletions app/templates/contact/confirmation.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
{# TODO: Add conditional logic to this section #}
Your reference number is
<br>
<strong>AB-1234-5678</strong>
<p class="confirmation-inset govuk-body">
{{ _('You can now call CLA on') }} <strong class="laa-telephone">0345 345 4 345</strong>.<br>
{% trans %}Please quote your reference number when you call. Find out about
<a class="govuk-link" href="https://www.gov.uk/call-charges" rel="external">call charges</a>.{% endtrans %}
</p>
<strong>{{ case_reference }}</strong>
{% if not callback_time %}
<p class="confirmation-inset govuk-body">
{{ _('You can now call CLA on') }} <strong class="laa-telephone">0345 345 4 345</strong>.<br>
{% trans %}Please quote your reference number when you call. Find out about
<a class="govuk-link" href="https://www.gov.uk/call-charges" rel="external">call charges</a>.{% endtrans %}
</p>
{% endif %}
<div class="confirmation-actions">
<button id="print-button" class="govuk-!-margin-top-5 govuk-!-font-size-19 govuk-link confirmation-button-link ">{{ _('Print this page') }}</button>
<script nonce="{{ csp_nonce() }}">
Expand All @@ -29,13 +31,42 @@
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{% set panelTitle = _('We will call you back') if callback_time else _("Your details have been submitted") %}

{{ govukPanel({
"titleText": _("Your details have been submitted"),
"titleText":panelTitle,
"html": panelHtml
}) }}

{% if confirmation_email and not form.errors %}
<p class="govuk-body">
{{ _('Your reference number was sent to') }}
<strong>{{ confirmation_email }}</strong>.
</p>
{% else %}
<form class="confirmation-email-form" method="POST" novalidate>
{{ form.csrf_token }}
{{ form.email }}
{{ form.submit }}
</form>
{% endif %}

<h2 class="govuk-heading-m">{% trans %}What happens next?{% endtrans %}</h2>

{% if callback_time %}
<p class="govuk-body">
{% if contact_type == "thirdparty" %}
{% trans %}Your details have been submitted and an operator will call
the person you nominated at least once during your chosen time, or as close to the time as possible{% endtrans %}
{% else %}
{% trans %}Your details have been submitted and an operator will call
you at least once during your chosen time, or as close to the time as possible{% endtrans %}
{% endif %}
(<strong>{{ callback_time|format_callback_time }}</strong>).
{% trans %}When a CLA operator calls, the call will come from an anonymous number.{% endtrans %}
</p>
{% endif %}

{# TODO: Add conditioanl logic to this section #}
<ul class="govuk-list govuk-list--bullet">
<li>{% trans %}The first person they speak to will be an operator who will ask about your problem and your financial circumstances.{% endtrans %}
Expand Down

0 comments on commit 7631974

Please sign in to comment.