-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Fx News one-click-subscribe page (Fixes #15142)
- Loading branch information
1 parent
2daa613
commit 290bed4
Showing
8 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
bedrock/newsletter/templates/newsletter/firefox-confirm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{# | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
#} | ||
|
||
{% extends 'base-protocol.html' %} | ||
|
||
{% block page_title %}Firefox Newsletter{% endblock page_title %} | ||
|
||
{% block page_css %} | ||
{{ css_bundle('newsletter-firefox-confirm') }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main class="mzp-l-content mzp-t-content-lg mzp-u-centered"> | ||
<header> | ||
<h1 class="page-title">Stay connected with Mozilla, courtesy of our Firefox News newsletter</h1> | ||
</header> | ||
|
||
<form id="confirmation-form" class="c-confirm-form" method="post" action="{{ action }}" data-recovery-url="{{ url('newsletter.recovery') }}"> | ||
<input type="hidden" name="newsletters" value="{{ newsletters }}"> | ||
<input type="hidden" name="source_url" value="{{ source_url|absolute_url }}"> | ||
<input type="hidden" name="lang" value="{{ newsletter_lang }}"> | ||
<p class="c-confirm-form-tagline"> | ||
By subscribing, you’ll receive the latest product updates, expert tips, and important news from Mozilla—ensuring you stay safe and informed online. | ||
</p> | ||
<div class="c-confirm-form-errors mzp-c-form-errors hidden" id="confirm-form-errors"> | ||
<p class="c-confirm-error-msg error-invalid-token hidden"> | ||
We are sorry, but could not find your email address in our system. | ||
</p> | ||
<p class="c-confirm-error-msg error-try-again-later hidden"> | ||
We are sorry, but there was a problem with our system. Please try again later! | ||
</p> | ||
<p class="c-confirm-error-msg error-update-browser hidden"> | ||
Please update your web browser in order to use this page. | ||
</p> | ||
</div> | ||
<button type="submit" class="c-confirm-form-submit mzp-c-button">Subscribe</button> | ||
<p class="c-confirm-small"> | ||
<small>We will only send you Firefox-related information. You can unsubscribe at any time.</small> | ||
</p> | ||
</form> | ||
<div class="c-confirm-form-thanks hidden"> | ||
<p>Thank you for subscribing!</p> | ||
<p>Check your inbox soon for the latest Firefox newsletter.</p> | ||
</div> | ||
</main> | ||
{% endblock %} | ||
|
||
{% block js %} | ||
{{ js_bundle('newsletter-firefox-confirm') }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
$font-path: '/media/protocol/fonts'; | ||
$image-path: '/media/protocol/img'; | ||
|
||
@import '~@mozilla-protocol/core/protocol/css/includes/lib'; | ||
@import '~@mozilla-protocol/core/protocol/css/components/forms/form'; | ||
@import '~@mozilla-protocol/core/protocol/css/components/forms/field'; | ||
@import '~@mozilla-protocol/core/protocol/css/components/forms/button-container'; | ||
|
||
main { | ||
min-height: 500px; | ||
} | ||
|
||
.c-confirm-form { | ||
margin-top: $layout-lg; | ||
} | ||
|
||
.c-confirm-form-tagline { | ||
@include text-body-xl; | ||
} | ||
|
||
.c-confirm-small { | ||
margin-top: $spacing-lg; | ||
} | ||
|
||
.c-confirm-form-thanks { | ||
margin-top: $layout-lg; | ||
@include text-body-xl; | ||
} | ||
|
||
.c-confirm-form-errors { | ||
max-width: 400px; | ||
margin: 0 auto $spacing-xl; | ||
} | ||
|
||
.c-confirm-error-msg { | ||
margin-bottom: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import ConfirmForm from './confirm.es6'; | ||
|
||
ConfirmForm.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import FormUtils from './form-utils.es6'; | ||
|
||
let _form; | ||
|
||
const ConfirmationForm = { | ||
meetsRequirements: () => { | ||
return 'Promise' in window; | ||
}, | ||
|
||
handleFormError: (msg) => { | ||
FormUtils.enableFormFields(_form); | ||
_form.querySelector('.mzp-c-form-errors').classList.remove('hidden'); | ||
|
||
if (msg && msg === FormUtils.errorList.TOKEN_INVALID) { | ||
_form | ||
.querySelector('.error-invalid-token') | ||
.classList.remove('hidden'); | ||
} else if (msg && msg === FormUtils.errorList.UPDATE_BROWSER) { | ||
_form | ||
.querySelector('.error-update-browser') | ||
.classList.remove('hidden'); | ||
} else { | ||
_form | ||
.querySelector('.error-try-again-later') | ||
.classList.remove('hidden'); | ||
} | ||
}, | ||
|
||
handleFormSuccess: () => { | ||
_form.classList.add('hidden'); | ||
document | ||
.querySelector('.c-confirm-form-thanks') | ||
.classList.remove('hidden'); | ||
}, | ||
|
||
redirectToRecoveryPage: () => { | ||
const recoveryUrl = _form.getAttribute('data-recovery-url'); | ||
|
||
if (FormUtils.isWellFormedURL(recoveryUrl)) { | ||
window.location.href = recoveryUrl; | ||
} else { | ||
ConfirmationForm.handleFormError(); | ||
} | ||
}, | ||
|
||
getFormActionURL: () => { | ||
return _form.getAttribute('action'); | ||
}, | ||
|
||
serialize: () => { | ||
const params = FormUtils.serialize(_form); | ||
const token = FormUtils.getUserToken(); | ||
|
||
if (params && token) { | ||
return `${params}&token=${token}`; | ||
} | ||
|
||
return ''; | ||
}, | ||
|
||
subscribe: (e) => { | ||
const url = ConfirmationForm.getFormActionURL(); | ||
|
||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
// Disable form fields until POST has completed. | ||
FormUtils.disableFormFields(_form); | ||
|
||
// Clear any prior messages that might have been displayed. | ||
FormUtils.clearFormErrors(_form); | ||
|
||
const params = ConfirmationForm.serialize(); | ||
|
||
FormUtils.postToBasket( | ||
null, | ||
params, | ||
url, | ||
ConfirmationForm.handleFormSuccess, | ||
ConfirmationForm.handleFormError | ||
); | ||
}, | ||
|
||
init: () => { | ||
_form = document.getElementById('confirmation-form'); | ||
|
||
if (!ConfirmationForm.meetsRequirements()) { | ||
ConfirmationForm.handleFormError('Update your browser'); | ||
return; | ||
} | ||
|
||
_form.addEventListener('submit', ConfirmationForm.subscribe, false); | ||
|
||
// Look for a valid user token before rendering the page. | ||
// If not found, redirect to /newsletter/recovery/. | ||
return FormUtils.checkForUserToken().catch( | ||
ConfirmationForm.redirectToRecoveryPage | ||
); | ||
} | ||
}; | ||
|
||
export default ConfirmationForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.