Skip to content
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

Await Server Replies When Updating User #5392

Merged
merged 3 commits into from
Apr 14, 2021
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 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