Skip to content

Commit c96abd4

Browse files
authored
Merge pull request #2159 from Sefaria/feature/sc-29891/add-email-newsletter-signups-for-sidebar
Email newsletter sign up forms for sidebar ads
2 parents 5caecaa + 80a41e1 commit c96abd4

File tree

6 files changed

+61
-50
lines changed

6 files changed

+61
-50
lines changed

static/js/NewsletterSignUpForm.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function NewsletterSignUpForm({
66
includeEducatorOption = true,
77
emailPlaceholder = {en: 'Sign up for Newsletter', he: "הרשמו לניוזלטר"},
88
subscribe=Sefaria.subscribeSefariaNewsletter, // function which sends form data to API to subscribe
9+
additionalNewsletterMailingLists = [],
910
}) {
1011
const [email, setEmail] = useState('');
1112
const [firstName, setFirstName] = useState('');
@@ -24,15 +25,15 @@ export function NewsletterSignUpForm({
2425
if (showNameInputs === true) { // submit
2526
if (firstName.length > 0 && lastName.length > 0) {
2627
setSubscribeMessage("Subscribing...");
27-
subscribe(firstName, lastName, email, educatorCheck).then(res => {
28+
subscribe(firstName, lastName, email, educatorCheck, additionalNewsletterMailingLists).then(res => {
2829
setSubscribeMessage("Subscribed! Welcome to our list.");
2930
Sefaria.track.event("Newsletter", "Subscribe from " + contextName, "");
3031
}).catch(error => {
3132
setSubscribeMessage(error?.message || "Sorry, there was an error.");
3233
setShowNameInputs(false);
3334
});
3435
} else {
35-
setSubscribeMessage("Please enter a valid first and last name");// get he copy
36+
setSubscribeMessage("Please enter a valid first and last name");
3637
}
3738
} else if (Sefaria.util.isValidEmailAddress(email)) {
3839
setShowNameInputs(true);

static/js/Promotions.jsx

+47-34
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import classNames from "classnames";
44
import Sefaria from "./sefaria/sefaria";
55
import {EnglishText, HebrewText, InterfaceText, OnInView} from "./Misc";
66
import $ from "./sefaria/sefariaJquery";
7+
import { NewsletterSignUpForm } from "./NewsletterSignUpForm";
78

89
const Promotions = () => {
910
const [inAppAds, setInAppAds] = useState(Sefaria._inAppAds); // local cache
@@ -36,6 +37,11 @@ const Promotions = () => {
3637
buttonIcon: sidebarAd.buttonIcon,
3738
buttonLocation: sidebarAd.buttonAboveOrBelow,
3839
hasBlueBackground: sidebarAd.hasBlueBackground,
40+
isNewsletterSubscriptionInputForm: sidebarAd.isNewsletterSubscriptionInputForm,
41+
newsletterMailingLists:
42+
sidebarAd.newsletterMailingLists?.data.map(
43+
(mailingLists) => mailingLists.attributes.newsletterName
44+
) ?? [],
3945
trigger: {
4046
showTo: sidebarAd.showTo,
4147
interfaceLang: "english",
@@ -209,40 +215,47 @@ const SidebarAd = React.memo(({ context, matchingAd }) => {
209215
);
210216
}
211217

212-
return (
213-
<OnInView onVisible={() => trackSidebarAdImpression(matchingAd)}>
214-
<div className={classes}>
215-
<h3
216-
className={context.interfaceLang === "hebrew" ? "int-he" : "int-en"}
217-
>
218-
{matchingAd.title}
219-
</h3>
220-
{matchingAd.buttonLocation === "below" ? (
221-
<>
222-
<p
223-
className={
224-
context.interfaceLang === "hebrew" ? "int-he" : "int-en"
225-
}
226-
>
227-
{matchingAd.bodyText}
228-
</p>
229-
{getButton()}
230-
</>
231-
) : (
232-
<>
233-
{getButton()}
234-
<p
235-
className={
236-
context.interfaceLang === "hebrew" ? "int-he" : "int-en"
237-
}
238-
>
239-
{matchingAd.bodyText}
240-
</p>
241-
</>
242-
)}
243-
</div>
244-
</OnInView>
245-
);
218+
const isHebrew = context.interfaceLang === "hebrew";
219+
const getLanguageClass = () => (isHebrew ? "int-he" : "int-en");
220+
221+
return (
222+
<OnInView onVisible={() => trackSidebarAdImpression(matchingAd)}>
223+
<div className={classes}>
224+
<h3 className={getLanguageClass()}>{matchingAd.title}</h3>
225+
{matchingAd.buttonLocation === "below" ? (
226+
matchingAd.isNewsletterSubscriptionInputForm ? (
227+
<>
228+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
229+
<NewsletterSignUpForm
230+
context={"Sidebar Ad: " + context.keywordTargets.toString()}
231+
includeEducatorOption={false}
232+
additionalNewsletterMailingLists={matchingAd.newsletterMailingLists}
233+
/>
234+
</>
235+
) : (
236+
<>
237+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
238+
{getButton()}
239+
</>
240+
)
241+
) : matchingAd.isNewsletterSubscriptionInputForm ? (
242+
<>
243+
<NewsletterSignUpForm
244+
context={"Sidebar Ad: " + context.keywordTargets.toString()}
245+
includeEducatorOption={false}
246+
additionalNewsletterMailingLists={matchingAd.newsletterMailingLists}
247+
/>
248+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
249+
</>
250+
) : (
251+
<>
252+
{getButton()}
253+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
254+
</>
255+
)}
256+
</div>
257+
</OnInView>
258+
);
246259
});
247260

248261
export { Promotions, GDocAdvertBox };

static/js/context.js

+8
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ function StrapiDataProvider({ children }) {
163163
showTo
164164
startTime
165165
updatedAt
166+
isNewsletterSubscriptionInputForm
167+
newsletterMailingLists {
168+
data {
169+
attributes {
170+
newsletterName
171+
}
172+
}
173+
}
166174
}
167175
}
168176
}

static/js/sefaria/sefaria.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,13 @@ Sefaria = extend(Sefaria, {
654654
Sefaria._portals[portalSlug] = response;
655655
return response;
656656
},
657-
subscribeSefariaNewsletter: async function(firstName, lastName, email, educatorCheck) {
657+
subscribeSefariaNewsletter: async function(firstName, lastName, email, educatorCheck, lists = []) {
658658
const payload = {
659659
language: Sefaria.interfaceLang === "hebrew" ? "he" : "en",
660660
educator: educatorCheck,
661661
firstName: firstName,
662662
lastName: lastName,
663+
...(lists?.length && { lists }),
663664
};
664665
return await Sefaria.apiRequestWithBody(`/api/subscribe/${email}`, null, payload);
665666
},

static/js/sefaria/strings.js

+1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ const Strings = {
500500
"Please enter a valid email address.": 'כתובת הדוא"ל שהוזנה אינה תקינה.',
501501
"Subscribed! Welcome to our list.": "הרשמה בוצעה בהצלחה!",
502502
"Sorry, there was an error.": "סליחה, ארעה שגיאה",
503+
"Please enter a valid first and last name.": "נא להוסיף שם פרטי ושם משפחה.",
503504

504505
// Footer
505506
"Connect": "צרו קשר",

static/js/sefaria/util.js

-13
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,6 @@ class Util {
112112
};
113113
const postData = {json: JSON.stringify(feedback)};
114114
$.post('/api/send_feedback', postData);
115-
}
116-
static subscribeToNbList(email, lists) {
117-
if (Sefaria.util.isValidEmailAddress(email)) {
118-
$.post("/api/subscribe/" + email + "?lists=" + lists, function(data) {
119-
if ("error" in data) {
120-
console.log(data.error);
121-
} else {
122-
console.log("Subscribed! Welcome to our list.");
123-
}
124-
}).error(data => console.log("Sorry, there was an error."));
125-
} else {
126-
console.log("not valid email address")
127-
}
128115
}
129116
static naturalTimePlural(n, singular, plural) {
130117
return n <= 1 ? singular : plural;

0 commit comments

Comments
 (0)