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

feat: add disabled save button if userName not unique #31

Merged
merged 3 commits into from
Mar 3, 2021

Conversation

zato91
Copy link

@zato91 zato91 commented Feb 25, 2021

line 143 add Boolean state userNameValid
line 407 add function HandleUniqueUsername to check duplicate
line 403 called handleUniqueUserName in handleUserNameChange function
line 633 add condition !userNameValid in error
line 634 add condition userNamevalid in helperText
line 795 add !userNameValid to disabled save button

@nmcharlton nmcharlton linked an issue Feb 25, 2021 that may be closed by this pull request
Copy link
Collaborator

@nmcharlton nmcharlton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a couple of minor comments.

helperText={
handleError(userEditing, ['userName']) ? 'No space allowed' : ''
handleError(userEditing, ['userName'])
? 'No space allowed'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chained ternary operation is quite difficult to read.
At the very least, it needs to parentheses to make it clearer, but would benefit from being split out into a function.

setUserEditing({ ...userEditing, userName: e.target.value });
}

function handleUniqueUsername(e) {
setUserNameValid(true);
users.forEach((user) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be made more efficient using Array.find:

if (users.find((user) => user.userName === e.target.value) {
  setUserNameValid(false);
} else {
  setUserNameValid(true);
}

@zato91
Copy link
Author

zato91 commented Feb 26, 2021

Awesome, Thank you for the feedback.

@zato91 zato91 closed this Feb 26, 2021
@nmcharlton
Copy link
Collaborator

@zato91 No need to close the PR, just push any additional changes to the branch and they will automatically be included in this PR.

@nmcharlton nmcharlton reopened this Mar 3, 2021
@zato91
Copy link
Author

zato91 commented Mar 3, 2021

line 407- refactored function handleUniqueUsername
line 463 - created handleUserNameError function
line 638 - called handleUserNameError

Copy link
Collaborator

@nmcharlton nmcharlton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zato91!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent username duplication in Add User dialog
3 participants