Skip to content

Develop #56

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 6 commits into from
Apr 18, 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
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.9",
"version": "0.7.10",
"dependencies": {
"auth0-js": "^6.8.4",
"isomorphic-fetch": "^2.2.1",
Expand Down
11 changes: 11 additions & 0 deletions src/actions/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ function verifyMemberNewEmailDone(handle, tokenV3, emailVerifyToken) {
.then(res => ({ data: res }));
}

/**
* @static
* @desc Creates an action that toggles isEmailConflict state
* @param {boolean} state
* @return {Action}
*/
function updateEmailConflict(state = false) {
return state;
}

export default createActions({
PROFILE: {
LOAD_PROFILE: loadProfile,
Expand Down Expand Up @@ -480,5 +490,6 @@ export default createActions({
UPDATE_PASSWORD_DONE: updatePasswordDone,
VERIFY_MEMBER_NEW_EMAIL_INIT: verifyMemberNewEmailInit,
VERIFY_MEMBER_NEW_EMAIL_DONE: verifyMemberNewEmailDone,
UPDATE_EMAIL_CONFLICT: updateEmailConflict,
},
});
22 changes: 22 additions & 0 deletions src/reducers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ function onDeletePhotoDone(state, { payload, error }) {
function onUpdateProfileDone(state, { payload, error }) {
const newState = { ...state, updatingProfile: false };

if (payload.isEmailConflict) {
return {
...newState,
isEmailConflict: true,
updateProfileSuccess: false,
};
}

if (error) {
logger.error('Failed to update user profile', payload);
fireErrorMessage('ERROR: Failed to update user profile!');
Expand Down Expand Up @@ -455,6 +463,19 @@ function onVerifyMemberNewEmailDone(state, { payload, error }) {
};
}

/**
* Handles UPDATE_EMAIL_CONFLICT action
* @param {Object} state
* @param {Object} action Payload will be a boolean value
* @return {Object} New state
*/
function onUpdateEmailConflict(state, { payload }) {
return {
...state,
isEmailConflict: payload,
};
}

/**
* Creates a new Profile reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand Down Expand Up @@ -509,6 +530,7 @@ function create(initialState) {
[a.updatePasswordDone]: onUpdatePasswordDone,
[a.verifyMemberNewEmailInit]: state => ({ ...state, verifyingEmail: true }),
[a.verifyMemberNewEmailDone]: onVerifyMemberNewEmailDone,
[a.updateEmailConflict]: onUpdateEmailConflict,
}, _.defaults(initialState, {
achievements: null,
copilot: false,
Expand Down
3 changes: 3 additions & 0 deletions src/services/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class MembersService {
async updateMemberProfile(profile) {
const url = profile.verifyUrl ? `/members/${profile.handle}?verifyUrl=${profile.verifyUrl}` : `/members/${profile.handle}`;
const res = await this.private.api.putJson(url, { param: profile.verifyUrl ? _.omit(profile, ['verifyUrl']) : profile });
if (profile.verifyUrl && res.status === 409) {
return Promise.resolve(Object.assign({}, profile, { isEmailConflict: true }));
}
return getApiResponsePayload(res);
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ class User {
async getEmailPreferences(userId) {
const url = `/users/${userId}/preferences/email`;
const res = await this.private.api.get(url);
return getApiResponsePayload(res);
const x = (await res.json()).result;
return x.content;
}

/**
Expand Down