-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Conversation
There was a problem hiding this 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' |
There was a problem hiding this comment.
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.
src/components/Users.js
Outdated
setUserEditing({ ...userEditing, userName: e.target.value }); | ||
} | ||
|
||
function handleUniqueUsername(e) { | ||
setUserNameValid(true); | ||
users.forEach((user) => { |
There was a problem hiding this comment.
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);
}
Awesome, Thank you for the feedback. |
@zato91 No need to close the PR, just push any additional changes to the branch and they will automatically be included in this PR. |
line 407- refactored function handleUniqueUsername |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zato91!
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