Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Stop sending users to mozilla's newsletter page in submit handler #5963

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
8 changes: 2 additions & 6 deletions kuma/javascript/src/__snapshots__/newsletter.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ exports[`Newsletter de-DE 1`] = `
id="newsletter-form-container"
>
<form
action="https://www.mozilla.org/en-US/newsletter/"
className="newsletter-form nodisable"
method="post"
name="newsletter-form"
onSubmit={[Function]}
>
<section
className="newsletter-head"
Expand Down Expand Up @@ -95,7 +94,6 @@ exports[`Newsletter de-DE 1`] = `
<button
className="button neutral newsletter-submit"
id="newsletter-submit"
onClick={[Function]}
type="submit"
>
Sign up now
Expand Down Expand Up @@ -127,10 +125,9 @@ exports[`Newsletter en-US 1`] = `
id="newsletter-form-container"
>
<form
action="https://www.mozilla.org/en-US/newsletter/"
className="newsletter-form nodisable"
method="post"
name="newsletter-form"
onSubmit={[Function]}
>
<section
className="newsletter-head"
Expand Down Expand Up @@ -213,7 +210,6 @@ exports[`Newsletter en-US 1`] = `
<button
className="button neutral newsletter-submit"
id="newsletter-submit"
onClick={[Function]}
type="submit"
>
Sign up now
Expand Down
38 changes: 3 additions & 35 deletions kuma/javascript/src/newsletter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default function Newsletter() {

const [showNewsletter, setShowNewsletter] = useState(true);
const [showPrivacyCheckbox, setShowPrivacyCheckbox] = useState(false);
const [submitToServer, setSubmitToServer] = useState(false);
const [errors, setError] = useState([]);
const [
showSuccessfulSubscription,
Expand Down Expand Up @@ -99,29 +98,12 @@ export default function Newsletter() {
* @param {Object} event - The MouseEvent object
*/
const submit = event => {
let newsletterForm = newsletterFormRef.current;
event.preventDefault();

let newsletterForm = newsletterFormRef.current;
if (!newsletterForm) {
return;
}

if (submitToServer) {
/*
* An error occured while attempting to subscribe
* the user via Ajax, but no specific error was provided. We
* therefore just send the user directly to the Mozorg
* newsletter subscription page and log the occurence
*/
ga('send', {
hitType: 'event',
eventCategory: 'newsletter',
eventAction: 'progression',
eventLabel: 'error-forward'
});
return true;
}

event.preventDefault();
submitNewsletterSubscription(newsletterForm)
.then(({ success, errors }) => {
if (success) {
Expand All @@ -138,10 +120,6 @@ export default function Newsletter() {

if (errors && errors.length) {
setError(errors);
} else if (errors && errors.length === 0) {
// resubmit for diagnoses on the server (see skipFetch-
// comment above)
setSubmitToServer(true);
}
})
.catch(e => {
Expand Down Expand Up @@ -169,14 +147,6 @@ export default function Newsletter() {
}
}, []);

useEffect(() => {
const newsletterForm = newsletterFormRef.current;
if (submitToServer && newsletterForm) {
setSubmitToServer(false);
newsletterForm.submit();
}
}, [submitToServer]);

if (!showNewsletter) {
return null;
}
Expand Down Expand Up @@ -207,8 +177,7 @@ export default function Newsletter() {
ref={newsletterFormRef}
className="newsletter-form nodisable"
name="newsletter-form"
action={NEWSLETTER_SUBSCRIBE_URL}
method="post"
onSubmit={submit}
>
<section className="newsletter-head">
<h2 className="newsletter-teaser">
Expand Down Expand Up @@ -298,7 +267,6 @@ export default function Newsletter() {
</div>
<div className="newsletter-group-submit">
<button
onClick={submit}
id="newsletter-submit"
type="submit"
className="button neutral newsletter-submit"
Expand Down