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

525 implement ability to change password #527

Merged
merged 19 commits into from
Apr 19, 2024

Conversation

YanZhylavy
Copy link
Collaborator

Added ability to change password for user.
Знімок екрана 2024-04-15 151604
Знімок екрана 2024-04-15 151640
Знімок екрана 2024-04-15 151734
Знімок екрана 2024-04-15 151914
Знімок екрана 2024-04-15 152057

@YanZhylavy YanZhylavy self-assigned this Apr 15, 2024
@YanZhylavy YanZhylavy linked an issue Apr 15, 2024 that may be closed by this pull request
re_new_password: formData.reNewPassword
})
.then(() => toast.success('Пароль успішно змінено'))
.catch(() => toast.error('Виникла помилка. Можливо, вказано невірний поточний пароль'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

The .catch() block only displays a generic error message. Consider improving error handling by parsing the error response from the server to provide more specific feedback to the user

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you! Initially, I was outputting the error status code, but the team advised against it as it's not user-friendly. I'll consider better ways to inform the user.

Comment on lines 19 to 21
useEffect(() => {
props.currentFormNameHandler(props.curForm);
}, [props]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

useEffect has [props] as a dependency, which could lead to unnecessary re-executions if props object itself changes but not its values. Consider destructuring props outside useEffect and using specific properties in the dependency array
e.g.

const { currentFormNameHandler, curForm } = props;
useEffect(() => {
  currentFormNameHandler(curForm);
}, [currentFormNameHandler, curForm]);

label="Поточний пароль"
updateHandler={handleInputChange}
value={formData.currentPassword}
requredField={true}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There seems to be a typo in the requredField prop (should be requiredField). Moreover, HTML5 form validation could be utilized by using the required attribute on inputs instead of handling this manually

Comment on lines 42 to 54
const handleInputChange = (e) => {
e.preventDefault();
const updatedFormData = { ...formData, [e.target.name]: e.target.value };
setFormData(updatedFormData);
(updatedFormData.newPassword !== '' &&
!PASSWORD_PATTERN.test(updatedFormData.newPassword)) ?
setInvalidPasswordError('Пароль не відповідає вимогам') :
setInvalidPasswordError(null);
(updatedFormData.reNewPassword !== '' &&
updatedFormData.newPassword !== updatedFormData.reNewPassword) ?
setPasswordsDontMatchError('Паролі не співпадають') :
setPasswordsDontMatchError(null);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

The function updates state multiple times which can lead to performance issues or unexpected renders. It would be better to consolidate state updates into a single function call if possible

Copy link
Collaborator

Choose a reason for hiding this comment

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

const handleInputChange = (e) => {
    e.preventDefault();
    const { name, value } = e.target;
    const newFormData = { ...formData, [name]: value };

    const newInvalidPasswordError = newFormData.newPassword !== '' && !PASSWORD_PATTERN.test(newFormData.newPassword)
        ? 'Пароль не відповідає вимогам'
        : null;

    const newPasswordsDontMatchError = newFormData.reNewPassword !== '' && newFormData.newPassword !== newFormData.reNewPassword
        ? 'Паролі не співпадають'
        : null;

    // Update all states in one go
    setFormData(newFormData);
    setInvalidPasswordError(newInvalidPasswordError);
    setPasswordsDontMatchError(newPasswordsDontMatchError);
};

return (
<div className={css['password-field__item']}>
<div className={css['password-field__label-wrapper']}>
{props.requredField &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

requredField seems to be misspelled. The correct spelling should be requiredField

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you're right! Initially, I was reusing the existing HalfFormField component in the project where this typo was present (the component was taking prop 'requredField' instead of 'requiredField'), and then I forgot to correct the improper prop passing when I wrote my PasswordField.

Comment on lines 39 to 42
<span
className={css['password-visibility']}
onClick={togglePassword}
>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The toggle button for showing/hiding the password doesn’t have an accessible label or an aria-label attribute. Adding accessible labels should be useful for users who rely on screen readers
e.g.

<span className={css['password-visibility']} onClick={togglePassword} aria-label={showPassword ? "Hide password" : "Show password"}>
   {!showPassword ? <EyeInvisible /> : <EyeVisible />}
</span>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, will be done.

{!showPassword ? <EyeInvisible /> : <EyeVisible />}
</span>
</div>
{(props.requredField || props.error) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error message section will display even if props.error is an empty string and props.requredField is true. It might be more logical to display this section only if there is an error message to show

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, I'll consider it.

required={props.requredField}
/>
</div>
<span
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using a <span> for the password visibility toggle is not ideal because spans are not inherently focusable or interactive elements. Consider using a <button> instead, which is more appropriate for actions and improves accessibility
e.g.

<button className={css['password-visibility']} onClick={togglePassword} type="button">
   {!showPassword ? <EyeInvisible /> : <EyeVisible />}
</button>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with this point. I added a span there because it's done that way in our LoginPage component.

@YanZhylavy YanZhylavy merged commit d3829c5 into develop Apr 19, 2024
4 checks passed
@YanZhylavy YanZhylavy deleted the 525-implement-ability-to-change-password branch April 19, 2024 09:16
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.

Company/Startup Profile: Implement ability to change passowrd
3 participants