Skip to content

Develop #67

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

Merged
merged 8 commits into from
May 10, 2019
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
1 change: 1 addition & 0 deletions __tests__/actions/__snapshots__/profile.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Object {
},
},
"handle": "tcscoder",
"preferences": Object {},
},
"type": "PROFILE/SAVE_EMAIL_PREFERENCES_DONE",
}
Expand Down
12 changes: 6 additions & 6 deletions __tests__/reducers/__snapshots__/profile.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -939,7 +939,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -989,7 +989,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -1926,7 +1926,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -2125,7 +2125,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down Expand Up @@ -2175,7 +2175,7 @@ Object {
"deletingPhoto": false,
"deletingWebLink": false,
"emailPreferences": Object {
"TOPCODER_NL_DATA": true,
"Dev Newsletter": true,
},
"externalLinks": Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const mockActions = {
deleteWebLinkInit: mockAction('DELETE_WEB_LINK_INIT'),
deleteWebLinkDone: mockAction('DELETE_WEB_LINK_DONE', { handle, data: webLink }),
saveEmailPreferencesInit: mockAction('SAVE_EMAIL_PREFERENCES_INIT'),
saveEmailPreferencesDone: mockAction('SAVE_EMAIL_PREFERENCES_DONE', { handle, data: { subscriptions: { TOPCODER_NL_DATA: true } } }),
saveEmailPreferencesDone: mockAction('SAVE_EMAIL_PREFERENCES_DONE', { handle, preferences: { 'Dev Newsletter': true } }),
linkExternalAccountInit: mockAction('LINK_EXTERNAL_ACCOUNT_INIT'),
linkExternalAccountDone: mockAction('LINK_EXTERNAL_ACCOUNT_DONE', { handle, data: linkedAccount2 }),
unlinkExternalAccountInit: mockAction('UNLINK_EXTERNAL_ACCOUNT_INIT'),
Expand Down
1 change: 1 addition & 0 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
API: {
V2: 'https://api.topcoder-dev.com/v2',
V3: 'https://api.topcoder-dev.com/v3',
V5: 'https://api.topcoder-dev.com/v5',
},
dummyConfigKey: 'Dummy config value',
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "0.7.13",
"version": "0.7.14",
"dependencies": {
"auth0-js": "^6.8.4",
"isomorphic-fetch": "^2.2.1",
Expand Down
23 changes: 12 additions & 11 deletions src/actions/challenge-listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,27 @@ function getActiveChallengesDone(
}).catch(() => ({ challenges: [] })));
}
return Promise.all(calls).then(([ch, uch]) => {
let fullCH = ch;
/* uch array contains challenges where the user is participating in
* some role. The same challenge are already listed in res array, but they
* are not attributed to the user there. This block of code marks user
* challenges in an efficient way. */
if (uch) {
const map = {};
uch.challenges.forEach((item) => { map[item.id] = item; });
ch.challenges.forEach((item) => {
if (map[item.id]) {
/* It is fine to reassing, as the array we modifying is created just
* above within the same function. */
/* eslint-disable no-param-reassign */
item.users[user] = true;
item.userDetails = map[item.id].userDetails;
/* eslint-enable no-param-reassign */
}
uch.challenges.forEach((item) => {
map[item.id] = item;
/* eslint-disable no-param-reassign */
item.users[user] = true;
item.userDetails = map[item.id].userDetails;
/* eslint-enable no-param-reassign */
});
}

let { challenges, meta } = ch;
if (uch) {
fullCH = uch;
}
let { challenges } = fullCH;
let { meta } = ch;
// filter by date range and re-compute meta
// we can safely remove the next two lines when backend support date range
challenges = filterUtil.filterByDate(challenges, frontFilter);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function saveEmailPreferencesInit() {}
function saveEmailPreferencesDone(profile, tokenV3, preferences) {
const service = getUserService(tokenV3);
return service.saveEmailPreferences(profile, preferences)
.then(res => ({ data: res, handle: profile.handle }));
.then(res => ({ data: res, handle: profile.handle, preferences }));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ function onSaveEmailPreferencesDone(state, { payload, error }) {
return newState;
}

if (newState.profileForHandle !== payload.handle || !payload.data) {
if (newState.profileForHandle !== payload.handle) {
return newState;
}

return {
...newState,
emailPreferences: payload.data.subscriptions,
emailPreferences: payload.preferences,
};
}

Expand Down
28 changes: 14 additions & 14 deletions src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class User {
this.private = {
api: getApi('V3', tokenV3),
apiV2: getApi('V2', tokenV2),
apiV5: getApi('V5', tokenV3),
tokenV2,
tokenV3,
};
Expand Down Expand Up @@ -174,10 +175,10 @@ class User {
* @returns {Promise} Resolves to the email preferences result
*/
async getEmailPreferences(userId) {
const url = `/users/${userId}/preferences/email`;
const res = await this.private.api.get(url);
const x = (await res.json()).result;
return x.content;
const url = `/users/${userId}/preferences`;
const res = await this.private.apiV5.get(url);
const x = (await res.json());
return x.email;
}

/**
Expand All @@ -193,18 +194,17 @@ class User {
const settings = {
firstName,
lastName,
subscriptions: {},
createdBy: String(userId),
updatedBy: String(userId),
subscriptions: preferences,
};

if (!preferences) {
settings.subscriptions.TOPCODER_NL_GEN = true;
} else {
settings.subscriptions = preferences;
}
const url = `/users/${userId}/preferences/email`;

const res = await this.private.api.putJson(url, { param: settings });
return getApiResponsePayload(res);
const url = `/users/${userId}/preferences`;
const res = await this.private.apiV5.putJson(
url,
{ email: settings, objectId: String(userId) },
);
return res;
}

/**
Expand Down