Skip to content

Preventing brief occurrences of emojis and non-digit chars.#65006

Merged
amyevans merged 10 commits into
Expensify:mainfrom
aadil42:issues/63127/emoji-alphabet-brifely-shown-in-per-diem-field-verified-commits
Jul 8, 2025
Merged

Preventing brief occurrences of emojis and non-digit chars.#65006
amyevans merged 10 commits into
Expensify:mainfrom
aadil42:issues/63127/emoji-alphabet-brifely-shown-in-per-diem-field-verified-commits

Conversation

@aadil42
Copy link
Copy Markdown
Contributor

@aadil42 aadil42 commented Jun 26, 2025

Explanation of Change

Using AmountWithoutCurrencyInput because it's already using react-native-advanced-input-mask to prevent brief occurrences of emojis and non-digits chars.

Adding logic in AmountWithoutCurrencyInput to allow negative values.

Removing AmountWithoutCurrencyForm As it's not being used anywhere in codebase anymore.

Fixed Issues

$ #63127
PROPOSAL: #63127(comment)

Tests

  1. Launch app
  2. Create Workspace - enable per diem rate - Import per diem
  3. Open a destination
  4. Tap amount
  5. Try to enter alphabet or emoji
  6. Verify the alphabet/emoji does not appear briefly
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

Same as tests

  • 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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 used JaimeGPT to get English > Spanish translation. I then posted it 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 grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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.ts 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 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(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • 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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • 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.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • 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.

Screenshots/Videos

Android: Native
android-native-test.mp4
Android: mWeb Chrome
android.mweb.test.mp4
iOS: Native
ios.native.test.mp4
iOS: mWeb Safari
ios.mweb.test.mp4
MacOS: Chrome / Safari
web.chrome.mp4
MacOS: Desktop
mac.os.desktop.mp4

@aadil42 aadil42 requested a review from a team as a code owner June 26, 2025 12:54
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Jun 26, 2025

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

@melvin-bot melvin-bot Bot requested review from brunovjk and removed request for a team June 26, 2025 12:54
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Jun 26, 2025

@brunovjk Please 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]

@brunovjk
Copy link
Copy Markdown
Contributor

@aadil42 I don't think we are controlling the value correctly, its missing when we first enter the field:

Screen.Recording.2025-06-26.at.11.45.57.mov

Can you reproduce this in this PR as well? Thanks.

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jun 26, 2025

@brunovjk How stupid of me. I found the issue. The reason it was working in the other PR is because we were passing uncontrolled prop to be true in EditPerDiemAmountPage.

image

I removed that part because github action was yelling at me for passing a boolean value as shown in the image above. So I removed it. But yes it is because of this that we don't have default values anymore because it becomes undefined when we don't pass uncontrolled as true when the input component is uncontrolled which is correct for our changes. We did make it uncontrolled.

This code is what is making defaultValue prop to be undefined and we also don't have the value prop in our input anymore so we see empty input.

// As the text input is controlled, we never set the defaultValue prop
// as this is already happening by the value prop.
// If it's uncontrolled, then we set the `defaultValue` prop to actual value
defaultValue: inputProps.uncontrolled ? inputProps.defaultValue : undefined,

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jun 26, 2025

Default value for uncontrolled prop is false. How do we make it true without passing true value? Do we create a constant or something?

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jun 27, 2025

@brunovjk

@brunovjk
Copy link
Copy Markdown
Contributor

I'm a bit busy with another PR, I'll be back here soon.

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jun 27, 2025

Ok @brunovjk

@brunovjk
Copy link
Copy Markdown
Contributor

Sorry for the delay @aadil42, I was busy with another PR, but you are doing a great job here.

Default value for uncontrolled prop is false. How do we make it true without passing true value? Do we create a constant or something?

You can keep the input uncontrolled by passing the prop name without a value:

<InputWrapper
    ...
    role={CONST.ROLE.PRESENTATION}
    shouldAllowNegative
    uncontrolled
/>

What do you think? Thank you

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 1, 2025

@brunovjk, This does work I thought it would make uncontrolled undefined.
That aside, we still have a problem. The negative default value are always shown as positive.

Screen.Recording.2025-07-01.at.2.mp4

This I think is happening because of the mask prop. we're only allowing positive values there.

This is what we're gonna do:

Instead of using affinityFormat we're gonna use customNotation

We're adding custom chars that allows specific chars and we're making it optional so we can also omit negative sign when typing positive value when positive and negative both are allowed.

    const customNotationForMask = [{
        character: '@',
        characterSet: '0123456789.-',
        isOptional: true,
    }];

dynamic masking based on shouldAllowNegative prop.

 mask={shouldAllowNegative ? `[@][99999999]${separator}[09]`: `[09999999]${separator}[09]`}

The reason for [@][99999999] instead of [@][09999999] is When we have optional @ in front that would be counted as 1 char so if you do 09 instead of 99 you won't be able to have a period after 1 digit like 3.14 so we're making that one char optional. It works out because we can have values like .32 already. So making the first char optional won't cause any problem but what do you think about it?

finally adding customNotations prop

            customNotations={customNotationForMask}

We can have other char instead of @ for negative in mask prop. I couldn't think of any other char let me know what you think of using @.

I apologize for the delay and for myriad of little bugs.

video of working solution.

Screen.Recording.2025-07-01.at.5.mp4

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 1, 2025

Hey @brunovjk, did you get a chance to read this comment? 🙂

@brunovjk
Copy link
Copy Markdown
Contributor

brunovjk commented Jul 1, 2025

Hey @brunovjk, did you get a chance to read this comment? 🙂

Yes, Im testing right now :D

@brunovjk
Copy link
Copy Markdown
Contributor

brunovjk commented Jul 1, 2025

Looking good @aadil42! I'm totally fine with @ works well in my initial tests. Just as a suggestion—what do you think of using ~ instead, just to make it a bit more visually distinct and less likely to be confused with something like an email? Either way works.

I think it’s important to include a comment in the code explaining that this character is used to enable optional negative values in the mask logic.

Everything else looks good! I just need a bit more time for broader testing and regression checks. Great job so far!

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 1, 2025

@brunovjk, yeah I think we can use ~. I'll do it. I'll add a comment as well.

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 1, 2025

@brunovjk, using ~ now. Added a comment for customNotations.

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 2, 2025

@brunovjk, I hope we can merge the PR today. 🙂

@brunovjk
Copy link
Copy Markdown
Contributor

brunovjk commented Jul 2, 2025

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (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
    • 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 grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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.ts or at the top of the file that uses the constant) are defined as such
  • 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(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • 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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
65006_android_native.mov
Android: mWeb Chrome
65006_android_web.mov
iOS: HybridApp
65006_ios_native.mov
iOS: mWeb Safari
65006_ios_web.mov
MacOS: Chrome / Safari
65006_web_chrome.mov
MacOS: Desktop
65006_web_esktop.mov

Copy link
Copy Markdown
Contributor

@brunovjk brunovjk left a comment

Choose a reason for hiding this comment

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

LGTM :D

@melvin-bot melvin-bot Bot requested a review from amyevans July 2, 2025 18:29
amyevans
amyevans previously approved these changes Jul 3, 2025
Copy link
Copy Markdown
Contributor

@amyevans amyevans left a comment

Choose a reason for hiding this comment

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

This is looking great, thank you both for sticking with it diligently!

2 quick things -

  1. It looks like there are conflicts in src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx, please resolve
  2. Let's add as a last step to the Tests section Verify the alphabet/emoji does not show (so that it is clear what the expected behavior is)

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 3, 2025

@amyevans, I resolved the conflict.

I don't know where to add the test for this inside tests directory.
Should I place it under unit or ui?
And should I make a new file EditPerDiemAmountPage somewhere in tests?

I could use some help @brunovjk.

Thank you.

@brunovjk
Copy link
Copy Markdown
Contributor

brunovjk commented Jul 5, 2025

@aadil42 they were just asking you to update this PR description with one more item :D

  • Launch app
  • Create Workspace - enable per diem rate - Import per diem
  • Open a destination
  • Tap amount
  • Try to enter alphabet or emoji
  • Verify the alphabet/emoji does not show

But I don't think it's correct, since we can open the emoji keyboard as well as the alphabetic keyboard, the point is that we shouldn't be able to type an emoji or letter, as we guarantee in this PR. What do you think? Thanks.

cc: @amyevans

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 7, 2025

@brunovjk, Yes, you're right about the keyboard behaviour. I think @amyevans meant to say we should add a final step saying "after typing alphabet or emoji they don't appear briefly". Let's wait for her. Sorry, I thought we needed to write a test for it in jest. Apologies.

@brunovjk
Copy link
Copy Markdown
Contributor

brunovjk commented Jul 7, 2025

Great! But I think you can add these step here anyway. If they disagree, we would change it to what they suggested. What do you think?

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 7, 2025

@brunovjk, I updated PR description.

@amyevans
Copy link
Copy Markdown
Contributor

amyevans commented Jul 7, 2025

Sorry for the delay! And yes, your suggestion for the adjusted test steps looks great. Thank you!

amyevans
amyevans previously approved these changes Jul 7, 2025
@amyevans
Copy link
Copy Markdown
Contributor

amyevans commented Jul 7, 2025

The ESLint and Prettier checks are failing. Are you able to see the output in the GH Actions run or would it be helpful if I screenshotted?

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 7, 2025

Yes looking at it right now. One error is about negate variable names and the other is about useOnyx. I'm looking into it trying to understand what's wrong. I'll ask for help if I get stuck.

image

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 7, 2025

I'll also look into Prettier check.

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 7, 2025

@brunovjk, @amyevans this is the gist of why the checks were failing.

in AmountWithoutCurrencyInput for some reason the variable customNotationForMask was not allowed so we changed it to customMask

in EditPerDiemAmountPage we had to pass canBeMissing arg when using useOnyx so I'm passing it as true

And lastly we just had to run npm run prettier I guess it prettifies our code formatting and stuff. So I did all those changes.

@amyevans amyevans merged commit d80d99a into Expensify:main Jul 8, 2025
19 checks passed
@OSBotify
Copy link
Copy Markdown
Contributor

OSBotify commented Jul 8, 2025

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 8, 2025

🚀 Deployed to staging by https://github.com/amyevans in version: 9.1.78-0 🚀

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

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.1.78-4 🚀

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

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 10, 2025

@brunovjk, @amyevans There's an ios failure. It is working well on my machine. I don't understand this error. Is this happening because of our changes?

image

@amyevans
Copy link
Copy Markdown
Contributor

Nope, it's not due to the changes here! You can see the same was commented on other PRs (e.g. #65551 (comment)). It just means there was a problem with automatically submitting the version to the App Store, we got a notification about it internally in Slack, and one of our deployers manually submitted to the App Store. So nothing to worry about!

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 10, 2025

Phew. Btw, I don't have access to the Slack open source channel. I have sent many emails to join almost 2 months ago but they're saying there's a problem going on which prevents them from adding people. Can you help me join guys? Thank you.

This is where I sent the email.
image

@amyevans
Copy link
Copy Markdown
Contributor

@aadil42 I asked internally and you should have gained access just now. Let me know if not. Thanks!

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 11, 2025

@amyevans No I haven't received any email. I'm not yet added.

@amyevans
Copy link
Copy Markdown
Contributor

Try just logging into the Slack channel again. I may have been mistaken regarding receiving an email, but I see your profile active in Slack now:
Screenshot 2025-07-11 at 9 30 07 AM

@aadil42
Copy link
Copy Markdown
Contributor Author

aadil42 commented Jul 11, 2025

Yes. I got in by re-logging. Thank you so much @amyevans!

@amyevans
Copy link
Copy Markdown
Contributor

You're welcome!

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.

4 participants