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: magic code input (passwordless login) #16076

Merged
merged 34 commits into from
Apr 28, 2023

Conversation

BeeMargarida
Copy link
Contributor

@BeeMargarida BeeMargarida commented Mar 17, 2023

Details

Added a new component MagicCodeInput that is useful for the passwordless login. It contains 6 numeric inputs and supports copy paste.

Fixed Issues

$ #15403
#15403 (comment)

Tests

  1. Use passwordless login (modify Permissions.js method canUsePasswordlessLogins to return true)
  2. Enter the app (logged out) and set your email
  3. Should see the new component
  4. Add the code and submit (should work similar to how it was before in terms of submit logic)
  • Verify that no errors appear in the JS console

Offline tests

Not applicable

QA Steps

  1. Use passwordless login (modify Permissions.js method canUsePasswordlessLogins to return true)
  2. Enter the app (logged out) and set your email
  3. Should see the new component
  4. Add the code and submit (should work similar to how it was before in terms of submit logic)
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-03-31.at.18.11.19.mov
Mobile Web - Chrome
Screen.Recording.2023-03-31.at.18.22.06.mov
Mobile Web - Safari
Screen.Recording.2023-03-31.at.18.13.54.mov
Desktop
Screen.Recording.2023-03-31.at.18.12.52.mov
iOS
Screen.Recording.2023-03-31.at.18.10.44.mov
Android
Screen.Recording.2023-03-31.at.18.20.43.mov

@MelvinBot
Copy link

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

zayidmohamedy

This comment was marked as off-topic.

src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ArekChr ArekChr left a comment

Choose a reason for hiding this comment

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

I left some minor comments, overall LGTM 🙌

src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
@BeeMargarida BeeMargarida marked this pull request as ready for review March 20, 2023 08:54
@BeeMargarida BeeMargarida requested a review from a team as a code owner March 20, 2023 08:54
@melvin-bot melvin-bot bot requested review from aimane-chnaif and cristipaval and removed request for a team March 20, 2023 08:54
@MelvinBot
Copy link

@cristipaval @aimane-chnaif One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

src/CONST.js Outdated Show resolved Hide resolved
src/libs/ValidationUtils.js Outdated Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
@neil-marcellini neil-marcellini requested review from neil-marcellini and removed request for neil-marcellini March 21, 2023 17:16
@neil-marcellini neil-marcellini dismissed their stale review March 21, 2023 17:20

Changes were made!

@BeeMargarida
Copy link
Contributor Author

Updated!

Copy link
Contributor

@cristipaval cristipaval left a comment

Choose a reason for hiding this comment

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

Minor comments.

src/components/MagicCodeInput.js Show resolved Hide resolved
src/components/MagicCodeInput.js Outdated Show resolved Hide resolved
@BeeMargarida
Copy link
Contributor Author

Updated!

@aimane-chnaif
Copy link
Contributor

reviewing today

@dhairyasenjaliya
Copy link
Contributor

@aimane-chnaif flickering issue is created here #18218

@BeeMargarida
Copy link
Contributor Author

I'm currently checking if the iOS 16.4 issue is related to the app code or is a RN/iOS bug. Will post updates when I find an answer

@aimane-chnaif
Copy link
Contributor

It seems build is not generated again. We may have to test staging build on Testflight and also get feedback from QA team.
cc: @cristipaval

@BeeMargarida
Copy link
Contributor Author

@aimane-chnaif
Update: it seems like this is a problem throughout the app related to the onKeyPress callback in TextInput, not specific to MagicCodeInput.
In any TextInput, if you add the callback onKeyPress, it is always triggered with the nativeEvent.key as Backspace when any key is pressed. Even switching to the RN TextInput, the problem remains (see video).

Screen.Recording.2023-05-02.at.12.14.05.mov

I've tried replicating in a new clean app with the latest RN version (0.71.7), I can't seem to replicate it. And using this latest version in the NewDot, the problem still keeps happening. The last thing I've tested was seeing if this was related to differences between old/new arch, but testing in RN-tester with the old arch, the problem was not replicated. I'm still not sure related to this last point, since I had some troubles with the setup though. Would have to spend more time on this.

Just to clarify again, this problem only happens in iOS 16.4 (only tested in simulator). It seems like a RN issue however, even though I was not able to replicate it in rn-tester.

@aimane-chnaif
Copy link
Contributor

@BeeMargarida thanks for the deep research. So you confirmed that this doesn't happen on 0.71.7.
I'm still curious if it happens on 0.71.2 as well since our forked version is 0.71.2-alpha.3.
If happens, should be RN issue and may have been fixed between 71.2 - 71.7
If not happens, should be issue from our forked repo.

@BeeMargarida
Copy link
Contributor Author

So you confirmed that this doesn't happen on 0.71.7. I'm still curious if it happens on 0.71.2 as well since our forked version is 0.71.2-alpha.3. If happens, should be RN issue and may have been fixed between 71.2 - 71.7 If not happens, should be issue from our forked repo.

That's the weird part, when using 0.71.7 in the NewDot repo, the issue still remains. However, using the same version in a clean app, I can't replicate it. What makes me think this is a RN issue is that it happens even a simple TextInput imported from 'react-native'.

@OSBotify
Copy link
Contributor

OSBotify commented May 3, 2023

🚀 Deployed to staging by https://github.com/cristipaval in version: 1.3.9-12 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@BeeMargarida
Copy link
Contributor Author

I'll be ooo today due to a national holiday, will continue migrating the component to function component tomorrow

@cristipaval
Copy link
Contributor

Alright, I also created a new issue for the migration to the function component. @BeeMargarida, please add a comment to that issue when you have time, so I can assign you to it.

@BeeMargarida
Copy link
Contributor Author

please add a comment to that issue when you have time, so I can assign you to it.

Thank you, done!

@OSBotify
Copy link
Contributor

OSBotify commented May 9, 2023

🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.12-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

*
* @param {Object} event
*/
onKeyPress({nativeEvent: {key: keyValue}}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Methods should never be named for what they handle, they should only be named for what they do. This is part of the checklist:

I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I must have skipped it when I read it. There's an issue regarding MagicCodeInput yet - #18325 - where this can be fixed, if I end up assigned, I can do it there.

*
* @param {String} value
*/
onChangeText(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here about naming

@thesahindia
Copy link
Member

#18736 was created because we weren't changing the border color to red, when there was an error.

@mananjadhav
Copy link
Collaborator

We added opacity0 as a style, and iOS Safari cannot handle user interactions when we set opacity to 0. #18482 was created to fix this.

Comment on lines +108 to +110
this.setState({
input: '',
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Clearing input has caused this regression

@Santhosh-Sellavel
Copy link
Collaborator

This PR caused a regression here. Should have been caught while testing this offline, we should have considered the offline state before submitting post validation

Comment on lines 118 to 123
onFocus(event, index) {
onFocus(event) {
event.preventDefault();
this.setState({
input: '',
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not setting the focused index onFocus caused a regression #23596

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

Successfully merging this pull request may close these issues.