Skip to content

Commit f692994

Browse files
committed
Implements #4165
1 parent 0055da4 commit f692994

File tree

13 files changed

+456
-121
lines changed

13 files changed

+456
-121
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`renders email preferences setting page correctly 1`] = `
4+
<div
5+
className="src-shared-components-Settings-Preferences-Email-___styles__EmailPreferences___2FUGT"
6+
>
7+
<h1
8+
className="src-shared-components-Settings-Preferences-Email-___styles__title___1q6eb"
9+
>
10+
E-Mail Preferences
11+
</h1>
12+
<div
13+
className="src-shared-components-Settings-Preferences-Email-___styles__sub-title___2Fh1W"
14+
>
15+
Your preferences
16+
</div>
17+
<div
18+
className="src-shared-components-Settings-Preferences-Email-___styles__preferences-container___38AVF"
19+
>
20+
<ToggleableItem
21+
checked={false}
22+
id="Pipeline"
23+
onToggle={[Function]}
24+
primaryText="Challenge Pipeline"
25+
secondaryText="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 <a href=\\"https://www.topcoder.com/community/pipeline\\" style=\\"color:#0d61bf;text-decoration:underline\\">Challenge Pipeline</a> page."
26+
value="Pipeline"
27+
/>
28+
<ToggleableItem
29+
checked={false}
30+
id="TaaS"
31+
onToggle={[Function]}
32+
primaryText="Gig Work"
33+
secondaryText="This newsletter gets sent out at various times, specifically when we have an opportunity of mass appeal. For more information you can visit the <a href=\\"https://www.topcoder.com/community/taas\\" style=\\"color:#0d61bf;text-decoration:underline\\">Gig Work</a> page."
34+
value="TaaS"
35+
/>
36+
<ToggleableItem
37+
checked={false}
38+
id="Monthly Newsletter"
39+
onToggle={[Function]}
40+
primaryText="Monthly Newsletter"
41+
secondaryText="This newsletter gets sent out at the end of every month and contains a variety of important information across all of our tracks."
42+
value="Monthly Newsletter"
43+
/>
44+
<ToggleableItem
45+
checked={false}
46+
id="Marathon Match Reminders"
47+
onToggle={[Function]}
48+
primaryText="Marathon Match Reminders"
49+
secondaryText="Receive updates whenever a new marathon match is scheduled."
50+
value="Marathon Match Reminders"
51+
/>
52+
<ToggleableItem
53+
checked={false}
54+
id="Single Round Match Reminders"
55+
onToggle={[Function]}
56+
primaryText="Single Round Match (SRM) Reminders"
57+
secondaryText="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."
58+
value="Single Round Match Reminders"
59+
/>
60+
<ToggleableItem
61+
checked={false}
62+
id="TCO Tuesdays"
63+
onToggle={[Function]}
64+
primaryText="TCO Newsletter"
65+
secondaryText="For all the latest updates surrounding the <a href=\\"https://www.topcoder.com/community/member-programs/topcoder-open\\" style=\\"color:#0d61bf;text-decoration:underline\\">Topcoder Open</a> you should definitely be subscribing to this one. Expect an update in your mailbox every Tuesday!"
66+
value="TCO Tuesdays"
67+
/>
68+
</div>
69+
</div>
70+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import Renderer from 'react-test-renderer/shallow';
3+
4+
import Email from 'components/Settings/Preferences/Email';
5+
6+
const rnd = new Renderer();
7+
8+
it('renders email preferences setting page correctly', () => {
9+
rnd.render((<Email email={'[email protected]'} preferences={[]}/>));
10+
expect(rnd.getRenderOutput()).toMatchSnapshot();
11+
});

__tests__/shared/components/Settings/Preferences/__snapshots__/index.jsx.snap

-50
This file was deleted.

__tests__/shared/components/Settings/Preferences/index.jsx

-11
This file was deleted.

config/default.js

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = {
7171

7272
/* Holds params to signup for different newsletters. */
7373
NEWSLETTER_SIGNUP: {
74+
DEFAUL_LIST_ID: '28bfd3c062',
7475
COGNITIVE: {
7576
APIKEY: '',
7677
URL: '',
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* Actions for the Newsletter preference container.
3+
*/
4+
5+
/* global fetch */
6+
import _ from 'lodash';
7+
import { createActions } from 'redux-actions';
8+
import { config } from 'topcoder-react-utils';
9+
10+
const PROXY_ENDPOINT = `${config.URL.COMMUNITY_APP}/api/mailchimp`;
11+
12+
// Fetching member's newsletter preferences init
13+
function fetchDataInit(email) {
14+
return email;
15+
}
16+
17+
// Fetching member's newsletter preferences
18+
async function fetchDataDone(emailHash, listId = config.NEWSLETTER_SIGNUP.DEFAUL_LIST_ID) {
19+
/* NOTE: In the real life in most cases you don't want to use fetch() directly
20+
* in an action. You want to create a service for your calls and use it here.
21+
* However, in this example, to keep it a bit more compact, we use fetch()
22+
* directly here. */
23+
try {
24+
let error = false;
25+
const subs = await fetch(`${PROXY_ENDPOINT}/${listId}/members/${emailHash}`, {
26+
method: 'GET',
27+
headers: {
28+
'Content-Type': 'application/json',
29+
},
30+
})
31+
.then((result) => {
32+
if (result.status !== 200) error = true;
33+
return result.json();
34+
});
35+
36+
return {
37+
email: emailHash,
38+
preferences: subs.tags,
39+
error,
40+
};
41+
} catch (error) {
42+
return {
43+
email: emailHash,
44+
error,
45+
};
46+
}
47+
}
48+
49+
// Updates member newsletter subscription
50+
async function updateSubscriptionsDone(
51+
emailHash, tagId, status, listId = config.NEWSLETTER_SIGNUP.DEFAUL_LIST_ID,
52+
) {
53+
/* NOTE: In the real life in most cases you don't want to use fetch() directly
54+
* in an action. You want to create a service for your calls and use it here.
55+
* However, in this example, to keep it a bit more compact, we use fetch()
56+
* directly here. */
57+
try {
58+
let error = false;
59+
const fetchUrl = `${PROXY_ENDPOINT}/${listId}/members/${emailHash}/tags`;
60+
61+
const data = {
62+
tags: [
63+
{ name: tagId, status: status ? 'active' : 'inactive' },
64+
],
65+
};
66+
67+
const formData = JSON.stringify(data);
68+
// use proxy for avoid 'Access-Control-Allow-Origin' bug
69+
await fetch(fetchUrl, {
70+
method: 'POST',
71+
headers: {
72+
'Content-Type': 'application/json',
73+
},
74+
body: formData,
75+
})
76+
.then((result) => {
77+
if (!result.ok) error = true;
78+
return result.json();
79+
});
80+
81+
return {
82+
id: tagId,
83+
checked: status,
84+
email: emailHash,
85+
error,
86+
};
87+
} catch (error) {
88+
return {
89+
id: tagId,
90+
checked: status,
91+
email: emailHash,
92+
error,
93+
};
94+
}
95+
}
96+
97+
export default createActions({
98+
NEWSLETTER_PREFERENCES: {
99+
FETCH_DATA_INIT: fetchDataInit,
100+
FETCH_DATA_DONE: fetchDataDone,
101+
UPDATE_TAG_INIT: _.identity,
102+
UPDATE_TAG_DONE: updateSubscriptionsDone,
103+
},
104+
});

0 commit comments

Comments
 (0)