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: distance - share with accountant #51517

Merged

Conversation

paultsimura
Copy link
Contributor

@paultsimura paultsimura commented Oct 26, 2024

Details

This PR is intended to fix several issues with the tracked distance expenses shared with accountants.

Fixed Issues

$ #46897
PROPOSAL: #46897 (comment)

Tests

Same as QA

Offline tests

Same as QA

QA Steps

Violation flow

  1. Create a workspace if needed
  2. Enable distance rates in settings from more features
  3. Add a custom rate
  4. Edit the default rate to a different value
  5. Open the chat with yourself
  6. Track a Distance expense
  7. In the Concierge prompt, click "Share it with my accountant"
  8. Select a workspace
  9. Verify there's an error on the rate field instructing you to choose a workspace rate
  10. Verify you can't submit the expense with the error present
  11. Select a workspace rate
  12. Verify the error clears
  13. Submit the expense
  14. Verify it's moved to the workspace
  15. Verify it uses with the proper rate and distance, and the receipt image is updated

Auto-select rate flow

  1. Open the chat with yourself
  2. Track a Distance expense
  3. Check the mileage rate automatically set on the request
  4. Create a workspace if needed
  5. Enable distance rates in settings from more features
  6. Add a custom rate with the exact same value as in the step 3
  7. Go back to the chat with yourself
  8. In the Concierge prompt, click "Share it with my accountant"
  9. Select a workspace
  10. Verify there is no error on the rate field
  11. Click the "Rate" field
  12. Verify the custom rate which you've added in step 6 is automatically marked as "Selected"
  13. Submit the expense
  14. Verify it's moved to the workspace
  15. Verify it uses with the proper rate and distance, and the receipt image is updated

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 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
    • 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 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 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.

Screenshots/Videos

Android: Native
2024-11-13.-.20.27.-.android.mp4
Android: mWeb Chrome
2024-11-13.-.20.27.-.chrome.mp4
iOS: Native
2024-11-13.-.20.20.-.Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-11-13.at.19.54.36.mp4
iOS: mWeb Safari
2024-11-13.-.20.20.-.Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-11-13.at.19.53.07.mp4
MacOS: Chrome / Safari
2024-11-13.-.16.08.-.Screen.Recording.2024-11-13.at.16.05.08.mp4
MacOS: Desktop
2024-11-13.-.17.01.-.Screen.Recording.2024-11-13.at.17.00.31.mp4

Comment on lines 142 to 144
if (reportActionOriginalMessage?.movedToReportID) {
return "Moved this expense"; // todo: copy needed
}
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 could we please request a copy for this action?
It's added as the first report action after I share my tracked expense with an accountant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we already have a message like this when moving a manual expense for example? Can we use the same copy?

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 no, the fallback is shown for those expenses as well:

image

@paultsimura
Copy link
Contributor Author

Made some progress on the PR today.

@paultsimura
Copy link
Contributor Author

paultsimura commented Nov 13, 2024

With the recent changes, seems like the flow works fine (please see the recordings).
Still need the "Moved expense" copy though.

@paultsimura paultsimura marked this pull request as ready for review November 15, 2024 11:46
@paultsimura paultsimura requested a review from a team as a code owner November 15, 2024 11:46
@melvin-bot melvin-bot bot requested review from Pujan92 and removed request for a team November 15, 2024 11:46
Copy link

melvin-bot bot commented Nov 15, 2024

@Pujan92 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]

@paultsimura
Copy link
Contributor Author

@Pujan92 I believe only the copy is pending here, therefore you can start testing the flow.

@neil-marcellini
Copy link
Contributor

I asked for a copy check on the issue

@neil-marcellini neil-marcellini changed the title fix: distance - share with accountant [HOLD Web-E 44237] fix: distance - share with accountant Nov 22, 2024
@paultsimura
Copy link
Contributor Author

@neil-marcellini since we went live with the P2P distance requests, will there be any cleanup for the canUseP2PDistanceRequests usages?

@paultsimura
Copy link
Contributor Author

@neil-marcellini for the in-existing rate, would this format work (message TBD)?

image

When incorrect route is selected, we don't show the field error, but a form error at the bottom. I'm wondering if we should keep this behavior consistent (I just added the RBR for better clarity of which field is faulty):

image

@neil-marcellini
Copy link
Contributor

@neil-marcellini since we went live with the P2P distance requests, will there be any cleanup for the canUseP2PDistanceRequests usages?

I already removed all of them on main, so please make sure that's removed here too.

@neil-marcellini
Copy link
Contributor

@paultsimura I like what you did there with the RBR on the field and the form error message at the bottom. If you want, you could also do that for the route error, or tackled that in a separate PR.

@paultsimura
Copy link
Contributor Author

Got a bit stuck on the PR – asked a couple of clarifying questions here.

@paultsimura
Copy link
Contributor Author

paultsimura commented Dec 5, 2024

@neil-marcellini @Pujan92 the PR is almost ready. However, I have an issue with the dependency cycle.

We've agreed on using the root level report name in the MODIFIEDEXPENSE message:
moved expense from self DM to chat with {username} or moved expense from self DM to {workspace name}.

I'd like to reuse the ReportUtils.getReportName function inside the ModifiedExpenseMessage.getForReportAction, but ReportUtils.getReportName uses ModifiedExpenseMessage.getForReportAction in one specific case:

App/src/libs/ReportUtils.ts

Lines 4015 to 4018 in c049ac7

if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isModifiedExpenseAction(parentReportAction)) {
const modifiedMessage = ModifiedExpenseMessage.getForReportAction(report?.reportID, parentReportAction);
return formatReportLastMessageText(modifiedMessage);
}

What would be your suggestion to avoid this cycle?
It's nearly impossible to decouple the ReportUtils.getReportName as it uses a lot of the utilitary functions, such as isGroupChat, isPolicyExpenseChat, etc.

I could potentially move all of these functions into separate files and export them all from ReportUtils/index.ts, but it will create a dozen of one-file functions.

Or I could force allow the dependency cycle.

But maybe you could suggest a more elegant approach.

neil-marcellini
neil-marcellini previously approved these changes Dec 9, 2024
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.

Looks great to me, thanks

@Pujan92
Copy link
Contributor

Pujan92 commented Dec 10, 2024

Only issue I am seeing is that there is some distance unit(km and ml) inconsistency after the rate selection and with the price in the preview.

Screen.Recording.2024-12-10.at.23.23.06.mov

@paultsimura
Copy link
Contributor Author

Only issue I am seeing is that there is some distance unit(km and ml) inconsistency after the rate selection and with the price in the preview.

Screen.Recording.2024-12-10.at.23.23.06.mov

I saw that too, but it should be out of scope here

Copy link
Contributor

@Pujan92 Pujan92 left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@melvin-bot melvin-bot bot requested a review from neil-marcellini December 10, 2024 18:13
Comment on lines -3589 to -3590
const parameters = {
onyxData,
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 I had a conflict with recently merged #52221 which you reviewed as well.
Please let me know what you think about explicitly specifying the params subtypes that I've added in this PR (this change and a couple below) to avoid passing redundant data.
If it's a good practice, maybe it should be encouraged in other refactoring PRs as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, that does seem like a good practice. Thanks.

@neil-marcellini neil-marcellini changed the title [HOLD Web-E 44237] fix: distance - share with accountant fix: distance - share with accountant Dec 11, 2024
@neil-marcellini
Copy link
Contributor

@paultsimura can you please explain why the bug with the unit inconsistency should be out of scope? It seems like something we can and should fix as part of this flow.

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.

Looks good except that one bug

Comment on lines -3589 to -3590
const parameters = {
onyxData,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, that does seem like a good practice. Thanks.

@paultsimura
Copy link
Contributor Author

paultsimura commented Dec 11, 2024

@paultsimura can you please explain why the bug with the unit inconsistency should be out of scope? It seems like something we can and should fix as part of this flow.

Because it is something that already exists in prod (so not caused by my changes) and is not described in the initial issue steps and expectations. Also, the nature of the bug is different from the one we are resolving now, although it's also related to the "share expense" flow.

If we want to fix this as well, I would like to request bounty bump to $500 as it is a good chunk of extra work — we've already expanded the scope on this PR compared to the accepted proposal.

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.

Thanks for clarifying that the bug is on prod and yes I agree that this has already been a lot of work 😅. Please report the bug, tag me, and let's work on it as a quick follow up.

@neil-marcellini neil-marcellini merged commit 567bd21 into Expensify:main Dec 11, 2024
21 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.

Copy link
Contributor

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 9.0.75-0 🚀

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

@izarutskaya
Copy link

izarutskaya commented Dec 12, 2024

@paultsimura
Copy link
Contributor Author

@paultsimura QA team found issue #53988 when validation this PR

Thanks @izarutskaya, we've already established that it's only been revealed by this PR, not caused by it.

@Julesssss
Copy link
Contributor

Hey @paultsimura @Pujan92 @neil-marcellini. We have a blocker that might be related to these distance changes. Users are now unable to change distance rate because backend is not receiving the required customUnit.name data. Which seems possibly related to these changes.

If you could take a quick look that would be very helpful.

@paultsimura
Copy link
Contributor Author

That issue indeed seems to be caused by this PR, although it looks BE to me. I replied in your GH, let's keep the conversation there for clarity.

Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.0.75-6 🚀

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

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.

6 participants