Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor email signup on NoRent footer to use new API #1556

Merged
merged 6 commits into from
Jun 24, 2020
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
6 changes: 1 addition & 5 deletions frontend/lib/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ export class AppWithoutRouter extends React.Component<

@autobind
handleFetchError(e: Error) {
window.alert(
li18n._(
t`Unfortunately, a network error occurred. Please try again later.`
)
);
window.alert(li18n._(t`Oops! A network error occurred. Try again later.`));
// We're going to track exceptions in GA because we want to know how frequently
// folks are experiencing them. However, we won't report the errors
// to a service like Rollbar because these errors are only worth investigating
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/networking/loading-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function LoadingPageWithRetry(
if (props.error) {
return (
<Page title="Network error">
<p>Unfortunately, a network error occurred.</p>
<p>Oops! A network error occurred. Try again later.</p>
<br />
<button className="button" onClick={props.retry}>
Retry
Expand Down
67 changes: 15 additions & 52 deletions frontend/lib/norent/components/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,29 @@ import { FooterLanguageToggle } from "./language-toggle";
import { NorentRoutes as Routes } from "../routes";
import { Link } from "react-router-dom";
import { NorentLogo } from "./logo";
import { StaticImage } from "../../ui/static-image";
import { getImageSrc } from "../homepage";
import { PrivacyPolicyLink, TermsOfUseLink } from "../../ui/privacy-info-modal";
import { SocialIcons } from "./social-icons";
import { Trans, t } from "@lingui/macro";
import { li18n } from "../../i18n-lingui";

const MAILCHIMP_URL =
"https://nyc.us13.list-manage.com/subscribe?u=d4f5d1addd4357eb77c3f8a99&id=588f6c6ef4";

const EmailSignupForm = () => (
<form
action={MAILCHIMP_URL}
className="email-form is-horizontal-center"
method="post"
target="_blank"
>
<div className="mc-field-group">
<div className="control is-expanded">
<label htmlFor="mce-EMAIL" className="jf-sr-only">
<Trans>Email</Trans>
</label>
<input
type="email"
name="EMAIL"
className="required email input"
id="mce-EMAIL"
placeholder={li18n._(t`ENTER YOUR EMAIL`)}
/>
</div>
<div className="control has-text-centered-touch">
<button
className="button"
type="submit"
aria-label={li18n._(t`Submit email`)}
>
<StaticImage
ratio="is-16x16"
src={getImageSrc("submitarrow")}
alt={li18n._(t`Submit email`)}
/>
</button>
</div>
</div>
</form>
);
import { Trans } from "@lingui/macro";
import Subscribe from "./subscribe";
import { SimpleProgressiveEnhancement } from "../../ui/progressive-enhancement";

export const NorentFooter: React.FC<{}> = () => (
<footer>
<div className="container has-background-dark">
<div className="columns">
<div className="column is-8">
<h6 className="title is-size-3 has-text-weight-bold has-text-white">
<Trans>
Join our <br className="is-hidden-tablet" />
mailing list
</Trans>
</h6>
<EmailSignupForm />
<SocialIcons color="white" />
<SimpleProgressiveEnhancement>
<>
Comment on lines +17 to +18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, we should really change this component to accept multiple JSX elements as children. Filed #1560 to address this later.

<h6 className="title is-size-3 has-text-weight-bold has-text-white">
<Trans>
Join our <br className="is-hidden-tablet" />
mailing list
</Trans>
</h6>
<Subscribe />
<SocialIcons color="white" />
</>
</SimpleProgressiveEnhancement>
</div>
<div className="column is-4 has-text-right is-uppercase content">
<Link to={Routes.locale.letter.latestStep}>
Expand Down
104 changes: 104 additions & 0 deletions frontend/lib/norent/components/subscribe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useState } from "react";
import { Trans, t } from "@lingui/macro";
import { li18n } from "../../i18n-lingui";
import { StaticImage } from "../../ui/static-image";
import { getImageSrc } from "../homepage";
import { AriaAnnouncement } from "../../ui/aria";
import { awesomeFetch } from "../../networking/fetch";

const Subscribe = () => {
const [email, setEmail] = useState("");
const [isSuccessful, setSuccess] = useState(false);
const [response, setResponse] = useState("");

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setEmail(e.target.value);
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const locale = li18n.language;

if (!email) {
setResponse(li18n._(t`Please enter an email address!`));
return;
}

awesomeFetch("/mailchimp/subscribe", {
method: "POST",
body: `email=${encodeURIComponent(
email
)}&language=${locale}&source=norent`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
.then((result) => result.json())
.then((result) => {
if (result.status === 200) {
setSuccess(true);
setResponse(li18n._(t`All set! Thanks for subscribing!`));
} else if (result.errorCode === "INVALID_EMAIL") {
setResponse(li18n._(t`Oops! That email is invalid.`));
} else {
window.Rollbar?.error(
`Mailchimp email signup responded with error code ${result.errorCode}.`
);
setResponse(
li18n._(t`Oops! A network error occurred. Try again later.`)
);
}
})
.catch((err) => {
setResponse(
li18n._(t`Oops! A network error occurred. Try again later.`)
);
});
};

return (
<div>
<form className="email-form is-horizontal-center" onSubmit={handleSubmit}>
<div className="mc-field-group">
<div className="control is-expanded">
<label htmlFor="mce-EMAIL" className="jf-sr-only">
<Trans>Email</Trans>
</label>
<input
type="email"
name="EMAIL"
className="input"
id="mce-EMAIL"
onChange={handleChange}
placeholder={li18n._(t`ENTER YOUR EMAIL`)}
/>
</div>
<div className="control has-text-centered-touch">
<button
className="button"
type="submit"
aria-label={li18n._(t`Submit email`)}
>
<StaticImage
ratio="is-16x16"
src={getImageSrc("submitarrow")}
alt={li18n._(t`Submit email`)}
/>
</button>
</div>
</div>
</form>
{response && (
<>
<br />
<p className={isSuccessful ? "has-text-white" : "has-text-danger"}>
<AriaAnnouncement text={response} />
{response}
</p>
</>
)}
</div>
);
};

export default Subscribe;
45 changes: 30 additions & 15 deletions locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ msgstr "<0>If you’re facing an emergency, you can find further legal assistanc
msgid "<0>No, you can use this website to send a letter to your landlord via email or USPS mail. You do not have to pay for the letter to be mailed.</0>"
msgstr "<0>No, you can use this website to send a letter to your landlord via email or USPS mail. You do not have to pay for the letter to be mailed.</0>"

#: frontend/lib/norent/components/footer.tsx:71
#: frontend/lib/norent/components/footer.tsx:58
msgid "<0>NoRent</0> <1>brought to you by JustFix.nyc</1>"
msgstr "<0>NoRent</0> <1>brought to you by JustFix.nyc</1>"

Expand Down Expand Up @@ -80,7 +80,7 @@ msgstr "A national tool by non-profit <0>JustFix.nyc</0>"

#: frontend/lib/norent/about.tsx:48
#: frontend/lib/norent/about.tsx:53
#: frontend/lib/norent/components/footer.tsx:52
#: frontend/lib/norent/components/footer.tsx:39
#: frontend/lib/norent/site.tsx:74
msgid "About"
msgstr "About"
Expand Down Expand Up @@ -118,6 +118,10 @@ msgstr "Alas."
msgid "Alaska"
msgstr "Alaska"

#: frontend/lib/norent/components/subscribe.tsx:34
msgid "All set! Thanks for subscribing!"
msgstr "All set! Thanks for subscribing!"

#: frontend/lib/norent/homepage.tsx:188
msgid "Answer a few questions about yourself and your landlord or management company. It'll take no more than 8 minutes."
msgstr "Answer a few questions about yourself and your landlord or management company. It'll take no more than 8 minutes."
Expand Down Expand Up @@ -170,7 +174,7 @@ msgstr "Browse the FAQs"
msgid "Build a letter using our free letter builder"
msgstr "Build a letter using our free letter builder"

#: frontend/lib/norent/components/footer.tsx:43
#: frontend/lib/norent/components/footer.tsx:30
#: frontend/lib/norent/site.tsx:65
msgid "Build my Letter"
msgstr "Build my Letter"
Expand Down Expand Up @@ -323,11 +327,11 @@ msgstr "Do you still want to mail to:"
msgid "Don’t worry, we’ll save your progress so you’ll be able to come back to your last step when you log back in."
msgstr "Don’t worry, we’ll save your progress so you’ll be able to come back to your last step when you log back in."

#: frontend/lib/norent/components/footer.tsx:19
#: frontend/lib/norent/components/subscribe.tsx:55
msgid "ENTER YOUR EMAIL"
msgstr "ENTER YOUR EMAIL"

#: frontend/lib/norent/components/footer.tsx:17
#: frontend/lib/norent/components/subscribe.tsx:53
msgid "Email"
msgstr "Email"

Expand Down Expand Up @@ -363,7 +367,7 @@ msgstr "Explore the tool"
msgid "FAQs"
msgstr "FAQs"

#: frontend/lib/norent/components/footer.tsx:49
#: frontend/lib/norent/components/footer.tsx:36
#: frontend/lib/norent/site.tsx:71
msgid "Faqs"
msgstr "Faqs"
Expand Down Expand Up @@ -428,6 +432,7 @@ msgstr "Hawaii"
#: frontend/lib/tests/i18n-lingui.test.tsx:25
#: frontend/lib/tests/i18n-lingui.test.tsx:32
#: frontend/lib/ui/tests/localized-outbound-link.test.tsx:18
#: frontend/lib/ui/tests/localized-outbound-link.test.tsx:25
msgid "Hello world"
msgstr "Hello world"

Expand Down Expand Up @@ -592,7 +597,7 @@ msgstr "It’s possible that your landlord will retaliate once they’ve receive
msgid "It’s your first time here!"
msgstr "It’s your first time here!"

#: frontend/lib/norent/components/footer.tsx:33
#: frontend/lib/norent/components/footer.tsx:18
msgid "Join our <0/>mailing list"
msgstr "Join our <0/>mailing list"

Expand Down Expand Up @@ -855,6 +860,16 @@ msgstr "Ohio"
msgid "Oklahoma"
msgstr "Oklahoma"

#: frontend/lib/app.tsx:55
#: frontend/lib/norent/components/subscribe.tsx:41
#: frontend/lib/norent/components/subscribe.tsx:45
msgid "Oops! A network error occurred. Try again later."
msgstr "Oops! A network error occurred. Try again later."

#: frontend/lib/norent/components/subscribe.tsx:37
msgid "Oops! That email is invalid."
msgstr "Oops! That email is invalid."

#: common-data/us-state-choices.ts:102
msgid "Oregon"
msgstr "Oregon"
Expand Down Expand Up @@ -901,6 +916,10 @@ msgstr "Please <0>go back and choose a state</0>."
msgid "Please agree to our terms and conditions"
msgstr "Please agree to our terms and conditions"

#: frontend/lib/norent/components/subscribe.tsx:19
msgid "Please enter an email address!"
msgstr "Please enter an email address!"

#: frontend/lib/norent/letter-builder/letter-preview.tsx:117
msgid "Please note, the email will be sent in English."
msgstr "Please note, the email will be sent in English."
Expand Down Expand Up @@ -1035,8 +1054,8 @@ msgstr "Strategic Actions for a Just Economy"
msgid "Street address"
msgstr "Street address"

#: frontend/lib/norent/components/footer.tsx:22
#: frontend/lib/norent/components/footer.tsx:23
#: frontend/lib/norent/components/subscribe.tsx:58
#: frontend/lib/norent/components/subscribe.tsx:59
msgid "Submit email"
msgstr "Submit email"

Expand All @@ -1060,7 +1079,7 @@ msgstr "Terms of Use"
msgid "Texas"
msgstr "Texas"

#: frontend/lib/norent/components/footer.tsx:46
#: frontend/lib/norent/components/footer.tsx:33
#: frontend/lib/norent/site.tsx:68
#: frontend/lib/norent/the-letter.tsx:10
#: frontend/lib/norent/the-letter.tsx:15
Expand All @@ -1087,10 +1106,6 @@ msgstr "To:"
msgid "USPS Tracking #:"
msgstr "USPS Tracking #:"

#: frontend/lib/app.tsx:55
msgid "Unfortunately, a network error occurred. Please try again later."
msgstr "Unfortunately, a network error occurred. Please try again later."

#: frontend/lib/norent/letter-builder/know-your-rights.tsx:36
msgid "Unfortunately, we do not currently recommend sending a notice of non-payment to your landlord. Sending a notice could put you at risk of harassment."
msgstr "Unfortunately, we do not currently recommend sending a notice of non-payment to your landlord. Sending a notice could put you at risk of harassment."
Expand Down Expand Up @@ -1450,7 +1465,7 @@ msgstr "In order to benefit from the eviction protections that local elected off
msgid "norent.legacyUserBlurb"
msgstr "<0>This is a new system. You will need a new account to use it. We're happy to set you up with one!</0><1>Meanwhile, whenever you want to sign into your \"Build your case\" or Advocate Dashboard account, you can sign in with your old account information at this URL:</1><2><3>beta.justfix.nyc</3> </2><4><5>Please write this URL down to remember it later.</5></4><6>Your new account will be used to access JustFix.nyc's new services.</6><7>If you have any questions, please feel free to email us at <8/>.</7>"

#: frontend/lib/norent/components/footer.tsx:62
#: frontend/lib/norent/components/footer.tsx:49
msgid "norent.legalDisclaimer"
msgstr "<0>Disclaimer: The information in JustFix.nyc does not constitute legal advice and must not be used as a substitute for the advice of a lawyer qualified to give advice on legal issues pertaining to housing. We can help direct you to free legal services if necessary.</0>"

Expand Down
Loading