Show error if user creation fails due to existing email (#317)

- Fix https://github.com/ToolJet/ToolJet/issues/316

Co-authored-by: Nishant Samel <nishant@saeloun.com>
This commit is contained in:
Nishant Samel 2021-06-25 21:35:52 +05:30 committed by GitHub
parent 511022b3e9
commit de76116c38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 20 deletions

View file

@ -14,23 +14,27 @@ class OrganizationUsersController < ApplicationController
password = SecureRandom.uuid
org = @current_user.organization
user = User.create(
first_name: first_name,
last_name: last_name,
email: email,
password: password,
password_confirmation: password,
organization: org,
invitation_token: SecureRandom.uuid
)
if User.find_by(email: email).present?
render json: { message: "Email address is already taken" }, status: :unprocessable_entity
else
user = User.create(
first_name: first_name,
last_name: last_name,
email: email,
password: password,
password_confirmation: password,
organization: org,
invitation_token: SecureRandom.uuid
)
org_user = OrganizationUser.new(
role: role,
user: user,
organization: org
)
org_user = OrganizationUser.new(
role: role,
user: user,
organization: org
)
UserMailer.with(user: user, sender: @current_user).invitation_email.deliver if org_user.save
UserMailer.with(user: user, sender: @current_user).invitation_email.deliver if org_user.save
end
end
def change_role

View file

@ -86,11 +86,17 @@ class ManageOrgUsers extends React.Component {
const { firstName, lastName, email, role } = this.state.newUser;
organizationUserService.create(firstName, lastName, email, role).then(() => {
this.setState({ creatingUser: false, showNewUserForm: false, newUser: {} });
toast.success('User has been created', { hideProgressBar: true, position: 'top-center' });
this.fetchUsers();
});
organizationUserService
.create(firstName, lastName, email, role)
.then(() => {
this.setState({ creatingUser: false, showNewUserForm: false, newUser: {} });
toast.success('User has been created', { hideProgressBar: true, position: 'top-center' });
this.fetchUsers();
})
.catch(({ error }) => {
toast.error(error, { hideProgressBar: true, position: 'top-center' });
this.setState({ creatingUser: false, showNewUserForm: true, newUser: {} });
});
};
logout = () => {