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/36985 create new rate field #38543

Merged

Conversation

koko57
Copy link
Contributor

@koko57 koko57 commented Mar 18, 2024

Details

Fixed Issues

$ #36985
PROPOSAL: -

Tests

P2P / Splits

  1. Go to global create (+) > Submit expense
  2. Change the request type to Distance
  3. Choose and submit the start/finish points
  4. Choose one user or add to a split and go to the confirmation page
  5. Verify that the distance is displayed correctly
  6. Verify that clicking the distance field navigates to the distance editing page
  7. Go back to the confirmation page
  8. Verify that the rate is displayed correctly
  9. Verify that the field is non-interactive

** Workspace Requests**

Prerequisites:

  1. Log in to expensify.com
  2. Go to Settings > Workspaces
  3. Create a new Collect workspace if needed
  4. Click on the workspace to open its settings page
  5. Open the JS console (command + option + j)
  6. Paste in the following and hit enter to enable the workspace to be used in NewDot
p = Policy.getCurrent(); 
p.policy.isPolicyExpenseChatEnabled = "true"; 
p.save();

  1. Click on Expenses in the left hand menu of the workspace settings and scroll down to the Distance card
  2. Click “Add a mileage rate”, then enter a unique name and value
  3. Click Members in the left hand menu and invite a member (required so that an expense chat is created for NewDot)
  4. Log in as the member on new expensify

  1. Go to global create (+) > Submit expense
  2. Change the request type to Distance
  3. Choose and submit the start/finish points
  4. Select the collect workspace and go to the confirmation page
  5. Verify that the distance is displayed correctly
  6. Verify that clicking the distance field navigates to the distance editing page
  7. Go back to the confirmation page
  8. Verify that the default rate is used and displayed correctly
  9. Verify that the field has a right arrow icon, is interactive and navigates to the rate selection page
  10. Verify that both workspace rates are displayed correctly on the selection page, and the default is currently selected
  11. Select the other rate
  12. Verify you are navigated back to the confirmation page and the amount and the rate field are properly updated

Money Request View

  1. Open the expense report
  2. Verify that a request preview is displayed with the proper distance and rate
  3. Open the request
  4. Verify that the Distance field is displayed with the correct value
  5. Verify that the Rate is displayed with correct value
  6. Rate field is not interactive for now, it'll be changed later

Sign in/out

  1. Create a distance request with a custom rate.
  2. Sign out.
  3. Sign back in.
  4. Go to the money request view.
  5. Verify that the data is shown properly.
  • Verify that no errors appear in the JS console

Offline tests

n/a

QA Steps

P2P / Splits

  1. Go to global create (+) > Request money
  2. Change the request type to Distance
  3. Choose and submit the start/finish points
  4. Choose one user or add to a split and go to the confirmation page
  5. Verify that the distance is displayed correctly
  6. Verify that clicking the distance field navigates to the distance editing page
  7. Go back to the confirmation page
  8. Verify that the rate is displayed correctly
  9. Verify that the field is non-interactive

** Workspace Requests**

Prerequisites:

  1. Log in to expensify.com
  2. Go to Settings > Workspaces
  3. Create a new Collect workspace if needed
  4. Click on the workspace to open its settings page
  5. Open the JS console (command + option + j)
  6. Paste in the following and hit enter to enable the workspace to be used in NewDot
p = Policy.getCurrent(); 
p.policy.isPolicyExpenseChatEnabled = "true"; 
p.save();

  1. Click on Expenses in the left hand menu of the workspace settings and scroll down to the Distance card
  2. Click “Add a mileage rate”, then enter a unique name and value
  3. Click Members in the left hand menu and invite a member (required so that an expense chat is created for NewDot)
  4. Log in as the member on new expensify

  1. Go to global create (+) > Request money
  2. Change the request type to Distance
  3. Choose and submit the start/finish points
  4. Select the collect workspace and go to the confirmation page
  5. Verify that the distance is displayed correctly
  6. Verify that clicking the distance field navigates to the distance editing page
  7. Go back to the confirmation page
  8. Verify that the default rate is used and displayed correctly
  9. Verify that the field has a right arrow icon, is interactive and navigates to the rate selection page
  10. Verify that both workspace rates are displayed correctly on the selection page, and the default is currently selected
  11. Select the other rate
  12. Verify you are navigated back to the confirmation page and the amount and the rate field are properly updated

Money Request View

  1. Open the expense report
  2. Verify that a request preview is displayed with the proper distance and rate
  3. Open the request
  4. Verify that the Distance field is displayed with the correct value
  5. Verify that the Rate is displayed with correct value
  6. Rate field is not interactive for now, it'll be changed later

Sign in/out

  1. Create a distance request with a custom rate.
  2. Sign out.
  3. Sign back in.
  4. Go to the money request view.
  5. Verify that the data is shown properly.
  • 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is 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
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
      • 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 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 form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label 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.
  • 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

Android: Native

Screenshot_1711713434

Screen.Recording.2024-03-29.at.12.56.06.mp4
Android: mWeb Chrome

Screenshot_1711712481
Screenshot_1711712444
Screenshot_1711712410

iOS: Native
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-03-28.at.21.30.34.mov

Simulator Screenshot - iPhone 15 Pro - 2024-03-28 at 21 31 28

iOS: mWeb Safari

Simulator Screenshot - iPhone 15 Pro - 2024-03-28 at 21 49 56

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-03-28.at.21.49.07.mov
MacOS: Chrome / Safari

https://github.com/Expensify/App/assets/28020445/3ac987f8-0e5c-482a-bb0e-23eeab7c8f02
Screenshot 2024-03-28 at 18 44 12

MacOS: Desktop Screenshot 2024-03-28 at 21 53 49
Screen.Recording.2024-03-28.at.21.54.30.mp4

@koko57
Copy link
Contributor Author

koko57 commented Apr 18, 2024

@getusha done

Copy link
Contributor

@getusha getusha left a comment

Choose a reason for hiding this comment

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

lgtm & tests well

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

All good to go except one tiny thing which is passing the right iouType to usePermissions for p2p distance on the money request view.

I left a bunch of non blocking comments too. You can address some now if you like, or handle them all in a follow up.


const currency = policy ? policy.outputCurrency : PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) ? DistanceRequestUtils.getRateForP2P(currency) : rates[rateID as string] ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: There's another complication here that we forgot about. Let's handle it in a follow up PR please, since I don't want to delay this one more and add more complexity.

If we're viewing an old request, and the defaultP2P rates have changed since the request was created, then we might display the wrong rate because the rate the request was created with is no longer in the default mapping.

Therefore when viewing a created request we should first try to get the default rate from transaction.comment.customUnit.defaultP2PRate. It stores the rate value number only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neil-marcellini ok I missed this one - will implement this

src/libs/DistanceRequestUtils.ts Show resolved Hide resolved
src/libs/DistanceRequestUtils.ts Show resolved Hide resolved
src/libs/DistanceRequestUtils.ts Show resolved Hide resolved

return `${formattedDistance} @ ${currencySymbol}${ratePerUnit} / ${singularDistanceUnit}`;
function getRateForP2P(currency: string): RateAndUnit {
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Noting that this is where we need to handle getting the rate from the transaction defaultP2PRate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neil-marcellini you mean adding a comment what this function does?

Copy link
Contributor

Choose a reason for hiding this comment

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

Implementing this

}

const distance = Number(merchant.split(' ')[0]);
if (!distance) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: It would also be a good idea to validate that the merchant has the expected format and return 0 if it does not. The regex we're using on the backend is found in a comment I posted here. Let's do this in a follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neil-marcellini FYI: I needed to change this regex a bit, /^[0-9.]+ \w+ @ (-|-\()?(\p{Sc}|\p{L}|\w){1,3} ?[0-9.]+\)? \/ \w+$/u - added an "u" flag to catch unicode and this one: \p{L} bc the regex didn't work when we had PLN currency - "zł"

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok great thanks. If you would please provide some examples where it breaks with the old regex, then I can get the backend fixed too so that the regexes match.

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

I found that requesting money with a custom rate on a workspace doesn't work. @getusha your test video shows it failing in a different way, so it looks like maybe you skipped this.

It looks like we're not sending the customUnitRateID param to the backend. After the updates, @getusha would you please also test the case of viewing an expense with a custom rate shortly after signing in?

customRate720.mov

@koko57
Copy link
Contributor Author

koko57 commented Apr 19, 2024

@getusha could you please retest?

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

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

Great, it looks like creating with a custom rate is fixed.

Screen.Recording.2024-04-19.at.12.10.31.PM.mov

Also viewing the money request after signing back in works well. All set! We will handle the rest in follow ups.

Screen.Recording.2024-04-19.at.12.11.43.PM.mov

@neil-marcellini neil-marcellini dismissed tgolen’s stale review April 19, 2024 19:14

Tim is out today and I want to get this merged for #urgency

@neil-marcellini neil-marcellini merged commit cba5f03 into Expensify:main Apr 19, 2024
16 checks passed
@OSBotify
Copy link
Contributor

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 1.4.64-6 🚀

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

function hasRoute(transaction: OnyxEntry<Transaction>): boolean {
return !!transaction?.routes?.route0?.geometry?.coordinates;
function hasRoute(transaction: OnyxEntry<Transaction>, isDistanceRequestType: boolean): boolean {
return !!transaction?.routes?.route0?.geometry?.coordinates || (isDistanceRequestType && !!transaction?.comment?.customUnit?.quantity);
Copy link
Contributor

Choose a reason for hiding this comment

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

In saveWaypoint function, you forgot to clear comment.customUnit.quantity, which caused #40934

@ikevin127
Copy link
Contributor

This PR also created issue:

which consists of 2 bugs:

  1. Not checking if lastSelectedDistanceRates is disabled. Additionally, in the getDefaultMileageRate function -> we're not excluding disabled rates.
  2. We're using getMileageRates to get rate list in IOURequestStepDistanceRate, but in this function we don't filter out disabled rates.

Neil acknowledged the oversight in #42284 (comment):

I guess we forgot about handling this during the initial implementation.

const customUnitRateID = TransactionUtils.getRateID(transaction) ?? '';

useEffect(() => {
if (customUnitRateID || !canUseP2PDistanceRequests) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't have returned early for P2P distance requests, instead we should had checked for canUseP2PDistanceRequests while assigning rateID, this caused #45856

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.