Skip to content

Commit ed39d37

Browse files
authored
Merge pull request #1188 from isaacphysics/hotfix/rollback-spurious-warning-bugfix
Rollback bugfix to update user on email change
2 parents 2dfe400 + c657bf8 commit ed39d37

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

src/app/state/actions/index.tsx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -277,52 +277,54 @@ export const updateCurrentUser = (
277277
async function continueSettingsUpdate() {
278278
const editingOtherUser = currentUser.loggedIn && currentUser.id != updatedUser.id;
279279

280-
await dispatch(requestCurrentUser() as any);
280+
try {
281+
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_REQUEST});
282+
const currentUser = await api.users.updateCurrent(updatedUser, updatedUserPreferences, passwordCurrent, userContexts);
283+
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_SUCCESS, user: currentUser.data});
281284

282-
if (!editingOtherUser) {
283-
// Invalidate tagged caches that are dependent on the current user's settings
284-
dispatch(questionsApi.util.invalidateTags(['CanAttemptQuestionType']) as any);
285-
}
285+
await dispatch(requestCurrentUser() as any);
286286

287-
const isFirstLogin = isFirstLoginInPersistence() || false;
288-
if (isFirstLogin) {
289-
persistence.session.remove(KEY.FIRST_LOGIN);
290-
if (redirect) {
291-
history.push(persistence.pop(KEY.AFTER_AUTH_PATH) || '/account', {firstLogin: isFirstLogin});
287+
if (!editingOtherUser) {
288+
// Invalidate tagged caches that are dependent on the current user's settings
289+
dispatch(questionsApi.util.invalidateTags(['CanAttemptQuestionType']) as any);
292290
}
293-
} else if (!editingOtherUser) {
294-
dispatch(showToast({
295-
title: "Account settings updated",
296-
body: "Your account settings were updated successfully.",
297-
color: "success",
298-
timeout: 5000,
299-
closable: false,
300-
}) as any);
301-
} else if (editingOtherUser) {
302-
redirect && history.push('/');
303-
dispatch(showToast({
304-
title: "Account settings updated",
305-
body: "The user's account settings were updated successfully.",
306-
color: "success",
307-
timeout: 5000,
308-
closable: false,
309-
}) as any);
291+
292+
const isFirstLogin = isFirstLoginInPersistence() || false;
293+
if (isFirstLogin) {
294+
persistence.session.remove(KEY.FIRST_LOGIN);
295+
if (redirect) {
296+
history.push(persistence.pop(KEY.AFTER_AUTH_PATH) || '/account', {firstLogin: isFirstLogin});
297+
}
298+
} else if (!editingOtherUser) {
299+
dispatch(showToast({
300+
title: "Account settings updated",
301+
body: "Your account settings were updated successfully.",
302+
color: "success",
303+
timeout: 5000,
304+
closable: false,
305+
}) as any);
306+
} else if (editingOtherUser) {
307+
if (redirect) {
308+
history.push('/');
309+
}
310+
dispatch(showToast({
311+
title: "Account settings updated",
312+
body: "The user's account settings were updated successfully.",
313+
color: "success",
314+
timeout: 5000,
315+
closable: false,
316+
}) as any);
317+
}
318+
} catch (e: any) {
319+
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_FAILURE, errorMessage: extractMessage(e)});
310320
}
311321
}
312322

313323
// Confirm email change
314324
if (currentUser.loggedIn && currentUser.id == updatedUser.id && currentUser.email !== updatedUser.email) {
315325
showEmailChangeModal();
316326
} else {
317-
try {
318-
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_REQUEST});
319-
const currentUser = await api.users.updateCurrent(updatedUser, updatedUserPreferences, passwordCurrent, userContexts);
320-
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_SUCCESS, user: currentUser.data});
321-
continueSettingsUpdate();
322-
}
323-
catch (e: any) {
324-
dispatch({type: ACTION_TYPE.USER_DETAILS_UPDATE_RESPONSE_FAILURE, errorMessage: extractMessage(e)});
325-
}
327+
continueSettingsUpdate();
326328
}
327329
};
328330

0 commit comments

Comments
 (0)