Skip to content

Commit

Permalink
Added form submission thank you message on donate help page (#11495)
Browse files Browse the repository at this point in the history
* added form submission thank you message on donate help page

* linting/formatting

* updated function and tests
  • Loading branch information
danielfmiranda authored Dec 1, 2023
1 parent 1ede432 commit 364c150
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
15 changes: 15 additions & 0 deletions network-api/networkapi/donate/pagemodels/help_page.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import urlencode

from wagtail.admin.panels import FieldPanel
from wagtail.fields import StreamField
from wagtail.models import Page
Expand Down Expand Up @@ -44,3 +46,16 @@ class DonateHelpPage(BaseDonationPage):
TranslatableField("notice"),
TranslatableField("body"),
]

def get_context(self, request):
context = super().get_context(request)
context["thank_you_url"] = self.get_thank_you_url(request)
context["show_formassembly_thank_you"] = context["request"].GET.get("thank_you") == "true"
return context

def get_thank_you_url(self, request):
base_url = self.get_full_url()
existing_params = request.GET.dict()
existing_params["thank_you"] = "true"
thank_you_url = base_url + "?" + urlencode(existing_params)
return thank_you_url
23 changes: 23 additions & 0 deletions network-api/networkapi/donate/tests/test_help_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,26 @@ def test_help_page_notice_field(self):
Asserts that a 'notice' block was created in the 'notice' field by the factory.
"""
self.assertEqual(self.donate_help_page.notice[0].block_type, "notice")

def test_thank_you_url(self):
"""
Testing that the "thank_you_url" is correctly added to the page context.
"""
page_url = self.donate_help_page.get_full_url()
response = self.client.get(page_url)

expected_thank_you_url = page_url + "?thank_you=true"

self.assertEqual(response.context["thank_you_url"], expected_thank_you_url)

def test_thank_you_url_with_existing_query_params(self):
"""
Testing that the "thank_you_url" is correctly added to the page context when there
are existing query parameters.
"""
page_url = self.donate_help_page.get_full_url() + "?existing_param=value"
response = self.client.get(page_url)

expected_thank_you_url = page_url + "&thank_you=true"

self.assertEqual(response.context["thank_you_url"], expected_thank_you_url)
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@

2. Run `inv format-html` in terminal

3. Add nonce="{{ csp_nonce }}" to all script tags in this file
3. Update value for "Thank You Page URL" field
- In the FormAssembly form builder, this field currently has the ID of "tfa_236".
- If this field ID changes after making changes to the form, please update the line above.
- Find the element with the same ID in the code below, and update the value to: value="{{ thank_you_url }}".

4. Get localization working again.
4 Add nonce="{{ csp_nonce }}" to all script tags in this file

5. Get localization working again.
- Localize "title" attribute and label text for all fields using {% trans %} or {% blocktrans %}.
- If applicable, localize any other text on the form. For example, text within htmlContent divs.
- Localize "value" attribute for <input type="submit" ...>
- Go to formassembly_head.html and make sure everything has been updated according to the instructions.

5. Update the revision note on the next line. Revision number can be found on https://mozillafoundation.tfaforms.net/versions/index/12
6. Update the revision note on the next line. Revision number can be found on https://mozillafoundation.tfaforms.net/versions/index/12

The code snippet below is based on FormAssembly form revision #45
The code snippet below is based on FormAssembly form revision #46

{% endcomment %}

Expand Down Expand Up @@ -127,6 +132,7 @@
<option value="tfa_229" id="tfa_229" class="">{% trans "Portuguese" %}</option>
<option value="tfa_231" id="tfa_231" class="">{% trans "Spanish" %}</option></select></div>
</div>
<input type="hidden" id="tfa_236" name="tfa_236" value="{{ thank_you_url }}" class="">
<div class="actions" id="12-A" data-contentid="submit_button">
<div id="google-captcha" style="display: none">
<br><div class="captcha">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

5. Update the revision note on the next line. Revision number can be found on https://mozillafoundation.tfaforms.net/versions/index/12

The code snippet below is based on FormAssembly form revision #45
The code snippet below is based on FormAssembly form revision #46

{% endcomment %}

Expand Down
11 changes: 9 additions & 2 deletions network-api/networkapi/templates/donate/pages/help_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ <h1 class="tw-h1-heading"> {{ page.title }} </h1>
</p>
<div class="tw-border-t tw-border-b tw-py-10 tw-mt-28 tw-mb-10 tw-border-gray-20">
<p id="contact-us" class="tw-h3-heading">{% trans "Contact Us" %}</p>
{% include "../fragments/formassembly_body.html" %}
<link rel="stylesheet" href="{% static "_css/formassembly-override.compiled.css" %}">
{% if show_formassembly_thank_you %}
<div class="tw-py-22">
<p class="tw-h4-heading">{% trans "Thank you for contacting us." %}</p>
<p class="tw-body-large">{% trans "A case has been created for your issue and we will be in touch shortly." %}</p>
</div>
{% else %}
{% include "../fragments/formassembly_body.html" %}
<link rel="stylesheet" href="{% static "_css/formassembly-override.compiled.css" %}">
{% endif %}
</div>
{% for block in page.body %}
{% include_block block with parent_page=page %}
Expand Down

0 comments on commit 364c150

Please sign in to comment.