diff --git a/__tests__/actions/__snapshots__/profile.js.snap b/__tests__/actions/__snapshots__/profile.js.snap index b784f238..7cfcbef7 100644 --- a/__tests__/actions/__snapshots__/profile.js.snap +++ b/__tests__/actions/__snapshots__/profile.js.snap @@ -166,6 +166,7 @@ Object { }, }, "handle": "tcscoder", + "preferences": Object {}, }, "type": "PROFILE/SAVE_EMAIL_PREFERENCES_DONE", } diff --git a/__tests__/reducers/__snapshots__/profile.js.snap b/__tests__/reducers/__snapshots__/profile.js.snap index a76358ad..da9208ec 100644 --- a/__tests__/reducers/__snapshots__/profile.js.snap +++ b/__tests__/reducers/__snapshots__/profile.js.snap @@ -740,7 +740,7 @@ Object { "deletingPhoto": false, "deletingWebLink": false, "emailPreferences": Object { - "TOPCODER_NL_DATA": true, + "Dev Newsletter": true, }, "externalLinks": Array [ Object { @@ -939,7 +939,7 @@ Object { "deletingPhoto": false, "deletingWebLink": false, "emailPreferences": Object { - "TOPCODER_NL_DATA": true, + "Dev Newsletter": true, }, "externalLinks": Array [ Object { @@ -989,7 +989,7 @@ Object { "deletingPhoto": false, "deletingWebLink": false, "emailPreferences": Object { - "TOPCODER_NL_DATA": true, + "Dev Newsletter": true, }, "externalLinks": Array [ Object { @@ -1926,7 +1926,7 @@ Object { "deletingPhoto": false, "deletingWebLink": false, "emailPreferences": Object { - "TOPCODER_NL_DATA": true, + "Dev Newsletter": true, }, "externalLinks": Array [ Object { @@ -2125,7 +2125,7 @@ Object { "deletingPhoto": false, "deletingWebLink": false, "emailPreferences": Object { - "TOPCODER_NL_DATA": true, + "Dev Newsletter": true, }, "externalLinks": Array [ Object { @@ -2175,7 +2175,7 @@ Object { "deletingPhoto": false, "deletingWebLink": false, "emailPreferences": Object { - "TOPCODER_NL_DATA": true, + "Dev Newsletter": true, }, "externalLinks": Array [ Object { diff --git a/__tests__/reducers/profile.js b/__tests__/reducers/profile.js index 0992cf13..3e9c5ea8 100644 --- a/__tests__/reducers/profile.js +++ b/__tests__/reducers/profile.js @@ -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'), diff --git a/config/test.js b/config/test.js index 30d81af5..919351db 100644 --- a/config/test.js +++ b/config/test.js @@ -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', }; diff --git a/package.json b/package.json index b8be6639..d0fa7e8c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/actions/challenge-listing.js b/src/actions/challenge-listing.js index ad872794..2e9c0d08 100644 --- a/src/actions/challenge-listing.js +++ b/src/actions/challenge-listing.js @@ -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); diff --git a/src/actions/profile.js b/src/actions/profile.js index 21643c99..dd1a88c0 100644 --- a/src/actions/profile.js +++ b/src/actions/profile.js @@ -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 })); } /** diff --git a/src/reducers/profile.js b/src/reducers/profile.js index 8ca03fdf..1cfe741e 100644 --- a/src/reducers/profile.js +++ b/src/reducers/profile.js @@ -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, }; } diff --git a/src/services/user.js b/src/services/user.js index 802f5af3..2fa7c0f6 100644 --- a/src/services/user.js +++ b/src/services/user.js @@ -114,6 +114,7 @@ class User { this.private = { api: getApi('V3', tokenV3), apiV2: getApi('V2', tokenV2), + apiV5: getApi('V5', tokenV3), tokenV2, tokenV3, }; @@ -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; } /** @@ -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; } /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy