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

O3-1409: Support for users changing passwords #902

Closed
wants to merge 3 commits into from

Conversation

jnsereko
Copy link
Contributor

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. Ensure your PR title includes a conventional commit label (such as feat, fix, or chore, among others). See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

Summary

O3 screen to allow users to change their password.
cc @michaelbontyes @vasharma05 @denniskigen @hadijahkyampeire

Screenshots

change.passwords.mov

Related Issue

https://openmrs.atlassian.net/browse/O3-1409

Other

@denniskigen denniskigen requested a review from ibacher January 29, 2024 11:55
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

@jnsereko This is great work in many ways! A few things:

  1. I think it would be preferable to have this as part of the (much neglected) openmrs-esm-admin-tools repo.
  2. Instead of a full page, I think the password change could be handled as a modal.
  3. As a modal, I think the width could be much smaller than it presently is.


return (
<>
<SwitcherDivider className={styles.divider} />
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that the SwitcherDivider should be part of this class.

);
};

export default ChangePasswordLink;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export default ChangePasswordLink;
export default ChangePasswordLink;

padding-right: 0rem;
@include brand-02(background-color);
@extend .productiveHeading01;
width: 16rem;
Copy link
Member

Choose a reason for hiding this comment

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

Using the Carbon $spacing utils. I'm also not sure why you're importing ../root.scss here?

const minLengthPassword = minLengthRegExp.test(passwordInputValue);
let errMsg = '';
if (passwordLength === 0) {
errMsg = 'Password is empty';
Copy link
Member

Choose a reason for hiding this comment

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

Any display string always needs to be translatable.

{t('discard', 'Discard')}
</Button>
<Button
style={{ maxWidth: '50%' }}
Copy link
Member

Choose a reason for hiding this comment

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

I'd use SCSS rather than inline styles for this.

import { openmrsFetch } from '@openmrs/esm-framework';

export async function performPasswordChange(oldPassword: string, newPassword: string) {
const abortController = new AbortController();
Copy link
Member

Choose a reason for hiding this comment

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

Not much use for an AbortController inside this method. This is what useAbortController() is for (automatically aborts requests when the UI unmounts a component).

try {
setIsSavingPassword(true);
const response = await performPasswordChange(passwordInput.oldPassword, passwordInput.confirmPassword);
if (response.ok) {
Copy link
Member

Choose a reason for hiding this comment

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

if (repsonse.ok) is redundant. openmrsFetch throws an exception (so the Promise will throw an error) if the result isn't ok.

const response = await performPasswordChange(passwordInput.oldPassword, passwordInput.confirmPassword);
if (response.ok) {
performLogout().then(() => {
const defaultLang = document.documentElement.getAttribute('data-default-lang');
Copy link
Member

Choose a reason for hiding this comment

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

Uh... just redirect to the logout handler I guess... We've never forced people to re-login after changing their password though, so I'm not a huge fan of this.

@jnsereko
Copy link
Contributor Author

jnsereko commented Feb 1, 2024

thank you @ibacher for taking a look at this.
i have moved this logic to esm-admin-tools repo and added it to the `@openmrs/esm-system-admin-app' hence i am closing this PR
follow up PR -> openmrs/openmrs-esm-admin-tools#43

@jnsereko jnsereko closed this Feb 1, 2024
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.

2 participants