Skip to content

Commit

Permalink
Await Server Replies When Updating User (#5392)
Browse files Browse the repository at this point in the history
* Await Server Replies When Updating User

* implement pr feedback
  • Loading branch information
fm3 authored Apr 14, 2021
1 parent 1c75b1d commit acfb3bc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed a bug in Safari which could cause an error message (which is safe to ignore). [#5373](https://github.com/scalableminds/webknossos/pull/5373)
- Fixed artifacts in screenshots near the dataset border. [#5324](https://github.com/scalableminds/webknossos/pull/5324)
- Fixed a bug where the page would scroll up unexpectedly when showing various confirm modals. [#5371](https://github.com/scalableminds/webknossos/pull/5371)
- Fixed a bug where user changes (email, activation) would show as successful even if they actually failed. [#5392](https://github.com/scalableminds/webknossos/pull/5392)

### Removed
-
Expand Down
69 changes: 36 additions & 33 deletions frontend/javascripts/admin/user/user_list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,48 +107,51 @@ class UserListView extends React.PureComponent<PropsWithRouter, State> {
});
}

activateUser = (selectedUser: APIUser, isActive: boolean = true): void => {
this.setState(prevState => {
const newUsers = prevState.users.map(user => {
if (selectedUser.id === user.id) {
const newUser = Object.assign({}, user, { isActive });
updateUser(newUser);
return newUser;
}
return user;
});

return {
users: newUsers,
selectedUserIds: [selectedUser.id],
isTeamRoleModalVisible: isActive,
};
activateUser = async (selectedUser: APIUser, isActive: boolean = true) => {
const newUserPromises = this.state.users.map(user => {
if (selectedUser.id === user.id) {
const newUser = Object.assign({}, user, { isActive });
return updateUser(newUser);
}
return Promise.resolve(user);
});

Promise.all(newUserPromises).then(
newUsers => {
this.setState({
users: newUsers,
selectedUserIds: [selectedUser.id],
isTeamRoleModalVisible: isActive,
});
},
() => {}, // Do nothing, change did not succeed
);
};

deactivateUser = (user: APIUser): void => {
this.activateUser(user, false);
};

changeEmail = (selectedUser: APIUser, newEmail: string): void => {
this.setState(prevState => {
const newUsers = prevState.users.map(user => {
if (selectedUser.id === user.id) {
const newUser = Object.assign({}, user, { email: newEmail });
updateUser(newUser);
return newUser;
}
return user;
});

return {
users: newUsers,
selectedUserIds: [selectedUser.id],
};
changeEmail = async (selectedUser: APIUser, newEmail: string) => {
const newUserPromises = this.state.users.map(user => {
if (selectedUser.id === user.id) {
const newUser = Object.assign({}, user, { email: newEmail });
return updateUser(newUser);
}
return Promise.resolve(user);
});
Toast.success(messages["users.change_email_confirmation"]);

if (this.props.activeUser.email === selectedUser.email) Store.dispatch(logoutUserAction());
Promise.all(newUserPromises).then(
newUsers => {
this.setState({
users: newUsers,
selectedUserIds: [selectedUser.id],
});
Toast.success(messages["users.change_email_confirmation"]);
if (this.props.activeUser.email === selectedUser.email) Store.dispatch(logoutUserAction());
},
() => {}, // Do nothing, change did not succeed
);
};

handleUsersChange = (updatedUsers: Array<APIUser>): void => {
Expand Down

0 comments on commit acfb3bc

Please sign in to comment.