Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.49k stars 2.84k forks source link

Distance rates - Error shows up when adding distance rates to the workspace created from actionable whisper #51035

Open lanitochka17 opened 4 days ago

lanitochka17 commented 4 days ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.50-3 Reproducible in staging?: Y Reproducible in production?: Y If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): applausetester+giugihiuhi@applause.expensifail.com Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to self DM
  3. Track a manual expense
  4. Click Categorize it from the whisper
  5. Click New workspace
  6. Select a category, proceed to confirmation page and submit it
  7. Go to workspace settings of the new workspace > More features
  8. Enable Distance rates
  9. Go to Distance rates
  10. Add a distance rate

Expected Result:

Distance rates will be added without issue

Actual Result:

Error shows up when adding distance rates to the workspace created from actionable whisper

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/26d248bd-0d4d-4db9-a82f-7674e0f5c18d

View all open jobs on GitHub

melvin-bot[bot] commented 4 days ago

Triggered auto assignment to @anmurali (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

lanitochka17 commented 4 days ago

@anmurali FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

mkzie2 commented 4 days ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Error shows up when adding distance rates to the workspace created from actionable whisper

What is the root cause of that problem?

The error is an invalid ID in the custom unit

Screenshot 2024-10-18 at 00 44 31

The RCA is when we categorize with a new workspace, it's created in frontend with a customUnitID but we don't pass this to the parameter of TrackExpense API then BE returns another customUnitID for the new WS.

https://github.com/Expensify/App/blob/91c6e0c510a032bca87e529c82cb3c28d8755ab4/src/libs/actions/IOU.ts#L3402

What changes do you think we should make in order to solve the problem?

If it's the new WS, we've passed some data in createdWorkspaceParams, we can pass additional data customUnitID and customUnitRateID to the parameter. BE also needs to use these parameters to update customUnits data of the workspace if required.

customUnitID: createdWorkspaceParams?.customUnitID,
customUnitRateID: createdWorkspaceParams?.customUnitRateID

https://github.com/Expensify/App/blob/91c6e0c510a032bca87e529c82cb3c28d8755ab4/src/libs/actions/IOU.ts#L3422-L3425

What alternative solutions did you explore? (Optional)

NA

FitseTLT commented 4 days ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Distance rates - Error shows up when adding distance rates to the workspace created from actionable whisper

What is the root cause of that problem?

When we press new workspace button a new workspace will be created with customUnits generated in FE onyx only https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/pages/iou/request/step/IOURequestStepParticipants.tsx#L134 https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/libs/ReportUtils.ts#L8004 now we will have a draft policy in onyx only and when we open the workspace profile page we fetch the policy with that policyID from BE here https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/pages/workspace/WorkspaceProfilePage.tsx#L97 so now OPEN_POLICY_PROFILE_PAGE API will return a policy data and it will merge the customUnit that only existed in FE with customUnits from the server. Therefore, when we create a distance rate the customUnitRateID in onyx will be sent but the BE doesn't know it so it returns error

What changes do you think we should make in order to solve the problem?

By the way, the problem is even more serious: if you finish on categorizing with the new workspace you created in track flow and create the expense but sign out or clear cache before opening the profile page of the new workspace created the workspace along with the expense created from the track expense will be lost as the data was only saved in onyx only not in server. What we should do is call createWorkspace instead of createDraftWorkspace (that will create the workspace both optimisticData and in server) here https://github.com/Expensify/App/blob/4a25c36e50b58ef9e5ba8b63cf32132f95a0b005/src/libs/ReportUtils.ts#L8004 similar to what we do when we create workspace in onboarding flow here

    const {expenseChatReportID, policyID, policyName} = PolicyActions.createWorkspace();

We can then remove createDraftWorkspace as we no longer need it.

What alternative solutions did you explore? (Optional)