From 717b17776afadedbeb35096add80bfe0ec202adc Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Tue, 16 Feb 2021 11:48:15 -0300 Subject: [PATCH 1/3] Revert "Merge branch 'develop' into gsheet-contentful" This reverts commit 4857f1689fc98822b350b2e0ca06455f05497bbe, reversing changes made to cf02e745442c23e4b5c4ca33b52fd4c9f667476c. --- .circleci/config.yml | 2 +- .../Email/__snapshots__/index.jsx.snap | 87 +++++++++---- package-lock.json | 48 -------- src/server/routes/mailchimp.js | 2 +- src/server/services/mailchimp.js | 2 +- src/shared/actions/newsletterPreferences.js | 59 ++------- .../ConfirmModal/style.scss | 4 - .../Settings/Preferences/Email/index.jsx | 114 +++++------------- .../Settings/Preferences/Email/styles.scss | 27 +---- .../Settings/ToggleableItem/index.jsx | 8 -- .../containers/EmailSubscribeForm/index.jsx | 31 +++-- .../containers/NewsletterPreferences.jsx | 12 +- .../containers/NewsletterSignupForMembers.jsx | 32 ++--- src/shared/reducers/newsletterPreferences.js | 32 ++--- 14 files changed, 146 insertions(+), 314 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d723a4d47b..60fb462786 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -282,7 +282,7 @@ workflows: filters: branches: only: - - free + - gsheet-contentful # This is alternate dev env for parallel testing - "build-qa": context : org-global diff --git a/__tests__/shared/components/Settings/Preferences/Email/__snapshots__/index.jsx.snap b/__tests__/shared/components/Settings/Preferences/Email/__snapshots__/index.jsx.snap index a3800f0773..ab117b50c9 100644 --- a/__tests__/shared/components/Settings/Preferences/Email/__snapshots__/index.jsx.snap +++ b/__tests__/shared/components/Settings/Preferences/Email/__snapshots__/index.jsx.snap @@ -10,32 +10,69 @@ exports[`renders email preferences setting page correctly 1`] = ` E-Mail Preferences
-

- You are not subscribed to receive Topcoder emails -

-

- If this was a mistake or if you would like to resubscribe, please click the button below. -

- - Resubscribe - + Your preferences +
+
+ Challenge Pipeline page." + value="Pipeline" + /> + Gig Work page." + value="Gig Work" + /> + + + + Topcoder Open you should definitely be subscribing to this one. Expect an update in your mailbox every Tuesday!" + value="TCO Tuesdays" + /> +
`; diff --git a/package-lock.json b/package-lock.json index e82b894f8a..565d69b21c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1333,54 +1333,6 @@ "integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==", "dev": true }, - "@sendgrid/client": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/@sendgrid/client/-/client-7.4.2.tgz", - "integrity": "sha512-bu8lLbRD+OV7YsYNemEy8DRoxs8/8u325EXNlQ3VaqhcpbM0eSvdL5e5Wa7VZpbczcNCJmf/sr/uqFmwcO5S+A==", - "requires": { - "@sendgrid/helpers": "^7.4.2", - "axios": "^0.21.1" - }, - "dependencies": { - "axios": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", - "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", - "requires": { - "follow-redirects": "^1.10.0" - } - }, - "follow-redirects": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz", - "integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==" - } - } - }, - "@sendgrid/helpers": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/@sendgrid/helpers/-/helpers-7.4.2.tgz", - "integrity": "sha512-b/IyBwT4zrOfXA0ISvWZsnhYz+5uAO20n68J8n/6qe5P1E2p0L7kWNTN5LYu0S7snJPUlbEa6FpfrSKzEcP9JA==", - "requires": { - "deepmerge": "^4.2.2" - }, - "dependencies": { - "deepmerge": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", - "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" - } - } - }, - "@sendgrid/mail": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-7.4.2.tgz", - "integrity": "sha512-hvIOnm8c3zVyDnJcyBuAeujmpKX56N3D/LpiZrFuLHjAz4iEHrmL2sJ3iU9O6hxcb07gd1CES+z9Fg7FBT26uQ==", - "requires": { - "@sendgrid/client": "^7.4.2", - "@sendgrid/helpers": "^7.4.2" - } - }, "@tanem/svg-injector": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@tanem/svg-injector/-/svg-injector-1.2.1.tgz", diff --git a/src/server/routes/mailchimp.js b/src/server/routes/mailchimp.js index 2ebe70056c..0b8b2a98fe 100644 --- a/src/server/routes/mailchimp.js +++ b/src/server/routes/mailchimp.js @@ -20,7 +20,7 @@ routes.post('/:listId/members', (req, res, next) => new MailchimpService().doReg routes.get('/:listId/members/:emailHash', (req, res) => new MailchimpService().checkSubscription(req).then(res.send.bind(res))); -routes.put('/:listId/members/:emailHash', (req, res) => new MailchimpService().updateMember(req).then(res.send.bind(res))); +routes.put('/:listId/members/:emailHash', (req, res) => new MailchimpService().subscribeInterests(req).then(res.send.bind(res))); routes.post('/:listId/members/:emailHash/tags', (req, res) => new MailchimpService().subscribeTags(req).then(res.send.bind(res))); diff --git a/src/server/services/mailchimp.js b/src/server/services/mailchimp.js index 1e06769f23..1a22665a24 100644 --- a/src/server/services/mailchimp.js +++ b/src/server/services/mailchimp.js @@ -51,7 +51,7 @@ export default class MailchimpService { return res.json(); } - async updateMember(req) { + async subscribeInterests(req) { const formData = JSON.stringify(req.body); const res = await fetch(`${this.mailchimpBaseUrl}/lists/${req.params.listId}/members/${req.params.emailHash}`, { method: 'PUT', diff --git a/src/shared/actions/newsletterPreferences.js b/src/shared/actions/newsletterPreferences.js index 84d08e3540..40a415c34a 100644 --- a/src/shared/actions/newsletterPreferences.js +++ b/src/shared/actions/newsletterPreferences.js @@ -35,8 +35,7 @@ async function fetchDataDone(emailHash, listId = config.NEWSLETTER_SIGNUP.DEFAUL return { email: emailHash, - preferences: subs.interests, - status: subs.status, + preferences: subs.tags, error, }; } catch (error) { @@ -49,7 +48,7 @@ async function fetchDataDone(emailHash, listId = config.NEWSLETTER_SIGNUP.DEFAUL // Updates member newsletter subscription async function updateSubscriptionsDone( - emailHash, groupId, status, listId = config.NEWSLETTER_SIGNUP.DEFAUL_LIST_ID, + emailHash, tagId, status, listId = config.NEWSLETTER_SIGNUP.DEFAUL_LIST_ID, ) { /* NOTE: In the real life in most cases you don't want to use fetch() directly * in an action. You want to create a service for your calls and use it here. @@ -57,16 +56,18 @@ async function updateSubscriptionsDone( * directly here. */ try { let error = false; - const fetchUrl = `${PROXY_ENDPOINT}/${listId}/members/${emailHash}`; + const fetchUrl = `${PROXY_ENDPOINT}/${listId}/members/${emailHash}/tags`; const data = { - interests: { [groupId]: !!status }, + tags: [ + { name: tagId, status: status ? 'active' : 'inactive' }, + ], }; const formData = JSON.stringify(data); // use proxy for avoid 'Access-Control-Allow-Origin' bug await fetch(fetchUrl, { - method: 'PUT', + method: 'POST', headers: { 'Content-Type': 'application/json', }, @@ -78,14 +79,14 @@ async function updateSubscriptionsDone( }); return { - id: groupId, + id: tagId, checked: status, email: emailHash, error, }; } catch (error) { return { - id: groupId, + id: tagId, checked: status, email: emailHash, error, @@ -93,53 +94,11 @@ async function updateSubscriptionsDone( } } -/** - * Resubscribe member for TC emails/list - * @param {string} emailHash the email - */ -async function resubscribeDone(emailHash, listId = config.NEWSLETTER_SIGNUP.DEFAUL_LIST_ID) { - try { - let error = false; - const fetchUrl = `${PROXY_ENDPOINT}/${listId}/members/${emailHash}`; - - const data = { - status: 'subscribed', - }; - - const formData = JSON.stringify(data); - // use proxy for avoid 'Access-Control-Allow-Origin' bug - await fetch(fetchUrl, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json', - }, - body: formData, - }) - .then((result) => { - if (!result.ok) error = true; - return result.json(); - }); - - return { - email: emailHash, - resubscribe: true, - error, - }; - } catch (error) { - return { - email: emailHash, - error, - }; - } -} - export default createActions({ NEWSLETTER_PREFERENCES: { FETCH_DATA_INIT: fetchDataInit, FETCH_DATA_DONE: fetchDataDone, UPDATE_TAG_INIT: _.identity, UPDATE_TAG_DONE: updateSubscriptionsDone, - RESUBSCRIBE_INIT: _.identity, - RESUBSCRIBE_DONE: resubscribeDone, }, }); diff --git a/src/shared/components/NewsletterSignupForMembers/ConfirmModal/style.scss b/src/shared/components/NewsletterSignupForMembers/ConfirmModal/style.scss index ea3f288646..7f44328bda 100644 --- a/src/shared/components/NewsletterSignupForMembers/ConfirmModal/style.scss +++ b/src/shared/components/NewsletterSignupForMembers/ConfirmModal/style.scss @@ -33,9 +33,5 @@ button { margin: 24px 12px 0; - - &:first-child { - margin-right: 12px !important; - } } } diff --git a/src/shared/components/Settings/Preferences/Email/index.jsx b/src/shared/components/Settings/Preferences/Email/index.jsx index 443dbd3ad4..b8666c7a80 100644 --- a/src/shared/components/Settings/Preferences/Email/index.jsx +++ b/src/shared/components/Settings/Preferences/Email/index.jsx @@ -1,4 +1,3 @@ -/* eslint-disable max-len */ /** * Email Preferences component. */ @@ -6,7 +5,6 @@ import { debounce, map } from 'lodash'; import React from 'react'; import PT from 'prop-types'; import { toastr } from 'react-redux-toastr'; -import { PrimaryButton } from 'topcoder-react-ui-kit'; import ToggleableItem from 'components/Settings/ToggleableItem'; @@ -28,48 +26,41 @@ const SAVE_DELAY = 1000; const newsletters = [ { - id: '9f950b43a1', + id: 'Pipeline', name: 'Challenge Pipeline', desc: 'Subscribe to this newsletter if you want to get updates on the types of challenges coming up in the future. To view these challenges at your leisure you can always visit the Challenge Pipeline page.', }, { - id: 'd0c48e9da3', + id: 'Gig Work', name: 'Gig Work', desc: 'This newsletter gets sent out at various times, specifically when we have an opportunity of mass appeal. For more information you can visit the Gig Work page.', }, { - id: 'a8f858cdf1', + id: 'Monthly Newsletter', name: 'Monthly Newsletter', desc: 'This newsletter gets sent out at the end of every month and contains a variety of important information across all of our tracks.', }, { - id: '5e67dba327', + id: 'Marathon Match Reminders', name: 'Marathon Match Reminders', desc: 'Receive updates whenever a new marathon match is scheduled.', }, { - id: '9091b438cc', + id: 'Single Round Match Reminders', name: 'Single Round Match (SRM) Reminders', desc: 'Attention Competitive Programmers! If there is any newsletter you are subscribing too, it better be this one. Receive updates when a new SRM event is scheduled.', }, { - id: '603c900c32', + id: 'TCO Tuesdays', name: 'TCO Newsletter', desc: 'For all the latest updates surrounding the Topcoder Open you should definitely be subscribing to this one. Expect an update in your mailbox every Tuesday!', }, { - id: '3460574ddd', + id: 'RDM', name: 'Rapid Development Match (RDM) Reminders', desc: 'Receive notifications of our brand new RDMs! These rated, development matches will be a fun new way to engage with us!', }, ]; -const programs = [ - { - id: 'cafe98d7a7', - name: 'Beta Testers', - desc: 'If you have applied and been approved as a Beta Tester, you may control the emails you receive here.', - }, -]; export default class EmailPreferences extends React.Component { saveEmailPreferences = debounce((id, checked) => { @@ -81,7 +72,6 @@ export default class EmailPreferences extends React.Component { super(props); this.state = { emailPreferences: { ...props.preferences }, - status: props.status, }; this.onChange = this.onChange.bind(this); } @@ -92,14 +82,14 @@ export default class EmailPreferences extends React.Component { if (updated.error) { toastrError('Error! ', 'Failed to update Your email preferences :-('); } - const { emailPreferences, status } = this.state; + const { emailPreferences } = this.state; const { id, checked } = updated; - emailPreferences[id] = checked; + if (!emailPreferences[id]) emailPreferences[id] = { id, checked }; + else emailPreferences[id].checked = checked; // eslint-disable-next-line react/no-did-update-set-state this.setState({ emailPreferences, - status: updated.resubscribe ? 'subscribed' : status, }); toastrSuccess('Success! ', 'Your email preferences were updated.'); } @@ -111,69 +101,34 @@ export default class EmailPreferences extends React.Component { } render() { - const { emailPreferences, status } = this.state; - const { resubscibeEmails, email } = this.props; + const { emailPreferences } = this.state; return (

E-Mail Preferences

- { - status !== 'subscribed' ? ( -
-

You are not subscribed to receive Topcoder emails

-

If this was a mistake or if you would like to resubscribe, please click the button below.

- resubscibeEmails(email)} - > - Resubscribe - -
- ) : ( - -
Newsletters
-
- { - map(newsletters, (newsletter) => { - const checked = emailPreferences[newsletter.id]; - return ( - this.onChange(newsletter.id, e.target.checked)} - disabled={status !== 'subscribed'} - /> - ); - }) - } -
-
Programs
-
- { - map(programs, (program) => { - const checked = emailPreferences[program.id]; - return ( - this.onChange(program.id, e.target.checked)} - disabled={status !== 'subscribed'} - /> - ); - }) - } -
-
- ) - } +
+ Your preferences +
+
+ { + map(newsletters, (newsletter) => { + const checked = emailPreferences[newsletter.id] + ? emailPreferences[newsletter.id].checked : false; + return ( + this.onChange(newsletter.id, e.target.checked)} + /> + ); + }) + } +
); } @@ -181,7 +136,6 @@ export default class EmailPreferences extends React.Component { EmailPreferences.defaultProps = { updated: null, - status: null, }; EmailPreferences.propTypes = { @@ -189,6 +143,4 @@ EmailPreferences.propTypes = { preferences: PT.shape().isRequired, saveEmailPreferences: PT.func.isRequired, updated: PT.shape(), - status: PT.string, - resubscibeEmails: PT.func.isRequired, }; diff --git a/src/shared/components/Settings/Preferences/Email/styles.scss b/src/shared/components/Settings/Preferences/Email/styles.scss index 25e81f8d12..e0b07a58f1 100644 --- a/src/shared/components/Settings/Preferences/Email/styles.scss +++ b/src/shared/components/Settings/Preferences/Email/styles.scss @@ -13,8 +13,7 @@ } } - .sub-title, - .sub-title-2 { + .sub-title { @include roboto-light; color: #888894; @@ -29,31 +28,7 @@ } } - .sub-title-2 { - margin-top: 30px; - } - .preferences-container { border-top: 1px solid $tc-gray-neutral-dark; } - - .unsubscribed-msg { - @include sofia-pro-regular; - - display: flex; - flex-direction: column; - background-color: $tc-red-10; - border: 1px solid $tc-red-30; - color: $tc-red; - line-height: 20px; - margin-bottom: 25px; - padding: 10px; - text-align: left; - font-size: 13px; - align-items: flex-start; - - button { - margin: 20px 0 0 0; - } - } } diff --git a/src/shared/components/Settings/ToggleableItem/index.jsx b/src/shared/components/Settings/ToggleableItem/index.jsx index d5d4552a71..bbfe110863 100644 --- a/src/shared/components/Settings/ToggleableItem/index.jsx +++ b/src/shared/components/Settings/ToggleableItem/index.jsx @@ -18,7 +18,6 @@ export default function ToggleableItem({ primaryText, secondaryText, value, - disabled, }) { return (
@@ -39,7 +38,6 @@ export default function ToggleableItem({ checked={checked} onChange={onToggle} className="onoffswitch-checkbox" - disabled={disabled} />