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

fix(PrimaryModal): backup password validation [WPB-11590] #18172

Merged
merged 3 commits into from
Oct 18, 2024

Conversation

olafsulich
Copy link
Contributor

@olafsulich olafsulich commented Oct 18, 2024

BugWPB-11590 [Web] No checks for password complexity on setting a password for backups

Screenshots/Screencast (for UI changes)

before:

Screen.Recording.2024-10-18.at.08.04.41.mov

after:

Screen.Recording.2024-10-18.at.08.00.01.mov

Checklist

  • mentions the JIRA issue in the PR name (Ex. WPB-423)
  • PR has been self reviewed by the author;
  • Hard-to-understand areas of the code have been commented;
  • If it is a core feature, unit tests have been added;

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 46.38%. Comparing base (0fd0dda) to head (2a49d5a).
Report is 6 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #18172      +/-   ##
==========================================
- Coverage   46.40%   46.38%   -0.03%     
==========================================
  Files         796      796              
  Lines       25780    25790      +10     
  Branches     5881     5884       +3     
==========================================
- Hits        11964    11963       -1     
- Misses      12319    12331      +12     
+ Partials     1497     1496       -1     

markInvalid={isBackupPasswordInvalid}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
updatePasswordWithRules(event.target.value);
setIsBackupPasswordInvalid(false);
Copy link
Member

Choose a reason for hiding this comment

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

Is firing this hook with every single digit change necessary?

I'd love to see a condition that it only fires once (while true)

@@ -55,6 +55,7 @@ export const PrimaryModalComponent: FC = () => {
const isModalVisible = currentId !== null;
const passwordValueRef = useRef<HTMLInputElement>(null);
const [isFormSubmitted, setIsFormSubmitted] = useState(false);
const [isBackupPasswordInvalid, setIsBackupPasswordInvalid] = useState(false);
Copy link
Contributor

@przemvs przemvs Oct 18, 2024

Choose a reason for hiding this comment

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

We need additional state for this? 🤔
Can't we do smth like that?

const isBackupPasswordValid = useMemo(() => isValidPassword(passwordInput), [passwordInput]);

And then in error use this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this approach, the initial state is broken - when input is empty, the isBackupPasswordValid will be set to true, causing an error message to show up.

We can't make an exception for an empty state (e.g passwordInput === "" ? true : isValidPassword(passwordInput) cause then we would submit the form with no password)

I'm not happy with that logic either, I gonna refactor it in this sprint, task - https://wearezeta.atlassian.net/browse/WPB-10932

Copy link
Contributor

Choose a reason for hiding this comment

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

So this can be like that: const isBackupPasswordValid = useMemo(() => passwordInput && isValidPassword(passwordInput), [passwordInput]);

And there will be easy check :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm missing something, but I think we can't do that either. Then the initial state (no value) would cause isBackupPasswordValid to be true, and we don't want that:

Screenshot 2024-10-18 at 09 37 08

Copy link
Contributor

Choose a reason for hiding this comment

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

But if You check also isFormSubmitted, we will don't have error on initial state. Only after submit button :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I see, missed that isFormSubmitted earlier, Friday vibes 😅 Give me a see, I'm gonna refactor this code real quick

Copy link

sonarcloud bot commented Oct 18, 2024

@olafsulich olafsulich merged commit 0f86852 into dev Oct 18, 2024
12 checks passed
@olafsulich olafsulich deleted the fix/WPB-11590-backup-password-validation branch October 18, 2024 07:55
@echoes-hq echoes-hq bot added the echoes: bugs Technical or functional defects in the product label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: bugs Technical or functional defects in the product 👕 size: S type: bug / fix 🐞
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants