Skip to content

Fix: Optimistically copy submission/approval related report actions#77960

Merged
13 commits merged intoExpensify:mainfrom
mohammadjafarinejad:fix/74575
Jan 19, 2026
Merged

Fix: Optimistically copy submission/approval related report actions#77960
13 commits merged intoExpensify:mainfrom
mohammadjafarinejad:fix/74575

Conversation

@mohammadjafarinejad
Copy link
Contributor

@mohammadjafarinejad mohammadjafarinejad commented Dec 18, 2025

Explanation of Change

Optimistically copy submission/approval related report actions

Fixed Issues

$ #74575
PROPOSAL: #74575 (comment)

Tests

  1. Have a workspace with a Control workspace
  2. Go to the workspace settings -> Workflows -> and enable Add Approvals
  3. Configure multi-level approvers so that expenses from everyone have approver1 as the First approver, approver2 as the Second approver, and approver3 as the Third approver
  4. Have an user named submitter manually submit a report with 6 expenses (let's call it report1)
  5. As the user approver1, go to the submitter's workspace chat and open the report
  6. Hold 2 expenses from the report
  7. Click on the Approve button for the report1
  8. Choose to only approve the unheld expenses from the report
  9. Verify that you see the report action showing that the report1 was approved by approver1
  10. Verify that the report1 now has only the 4 expenses that are not held and is awaiting approval from approver2
  11. Go back to the submitter's workspace chat
  12. Verify that a new report (report2) was created and the 2 held expenses were moved to it
  13. Verify that the report2 with the held expenses is submitted and awaiting approval from approver1
  14. Verify that the SUBMITTED report action from the report1 is copied to the report2 (it has the same actor, submitter, and the same timestamp)
  15. Verify that a new report action is added to the report2 stating that it was created for the held expenses from the report1
  16. As approver2 go to the submitter's workspace chat and click on the report1
  17. Hold an expense and then click on the Approve button for the report1
  18. Choose to only approve the unheld expenses
  19. Verify that you see a report action for the approver2 approval and the report1 now only has the 3 unheld expenses, awaiting approval from approver3
  20. Go to the submitter's workspace chat and verify that a new report (report3) has been created and the held expense was moved to it
  21. Verify that the report3 has copies of the SUBMITTED and APPROVE report actions from the report1, with the same actors and timestamps
  22. Verify that a new report action is added to the report3 stating that it was created for the held expenses from the report1
  23. Verify that report3 is awaiting approval from approver2
  24. As approver3 go to the submitter's workspace chat and click on the report1
  25. Hold an expense and then click on the Approve button for the report1
  26. Choose to only approve the unheld expenses
  27. Verify that you see a report action for the approver3 approval and the report1 now only has the 2 unheld expenses, and is finally approved
  28. Go to the submitter's workspace chat and verify that a new report (report4) has been created and the held expense was moved to it
  29. Verify that the report4 has copies of the SUBMITTED and APPROVE report actions from the report1, with the same actors and timestamps
  30. Verify that a new report action is added to the report4 stating that it was created for the held expenses from the report1
  31. Verify that report4 is awaiting approval from approver3
  • Verify that no errors appear in the JS console

Offline tests

Same as test.

QA Steps

Same as test.

  • 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
  • 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 new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • 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.mp4
Android: mWeb Chrome
android_web.mp4
iOS: Native
ios.mp4
iOS: mWeb Safari
ios_web.mp4
MacOS: Chrome / Safari
web.mp4

@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/actions/IOU.ts 64.94% <66.66%> (+0.22%) ⬆️
... and 117 files with indirect coverage changes

@mohammadjafarinejad mohammadjafarinejad marked this pull request as ready for review December 21, 2025 23:33
@mohammadjafarinejad mohammadjafarinejad requested review from a team as code owners December 21, 2025 23:33
@melvin-bot melvin-bot bot requested review from heyjennahay and parasharrajat and removed request for a team December 21, 2025 23:33
@melvin-bot
Copy link

melvin-bot bot commented Dec 21, 2025

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

@parasharrajat
Copy link
Member

@mohammadjafarinejad I think you should use this #77960 (comment). It will automatically enable types based on the key used.

@parasharrajat
Copy link
Member

@mohammadjafarinejad Use these test steps

  1. Have a workspace with a Control workspace
  2. Go to the workspace settings -> Workflows -> and enable Add Approvals
  3. Configure multi-level approvers so that expenses from everyone have approver1 as the First approver, approver2 as the Second approver, and approver3 as the Third approver
  4. Have an user named submitter manually submit a report with 6 expenses (let's call it report1)
  5. As the user approver1, go to the submitter's workspace chat and open the report
  6. Hold 2 expenses from the report
  7. Click on the Approve button for the report1
  8. Choose to only approve the unheld expenses from the report
  9. Verify that you see the report action showing that the report1 was approved by approver1
  10. Verify that the report1 now has only the 4 expenses that are not held and is awaiting approval from approver2
  11. Go back to the submitter's workspace chat
  12. Verify that a new report (report2) was created and the 2 held expenses were moved to it
  13. Verify that the report2 with the held expenses is submitted and awaiting approval from approver1
  14. Verify that the SUBMITTED report action from the report1 is copied to the report2 (it has the same actor, submitter, and the same timestamp)
  15. Verify that a new report action is added to the report2 stating that it was created for the held expenses from the report1
  16. As approver2 go to the submitter's workspace chat and click on the report1
  17. Hold an expense and then click on the Approve button for the report1
  18. Choose to only approve the unheld expenses
  19. Verify that you see a report action for the approver2 approval and the report1 now only has the 3 unheld expenses, awaiting approval from approver3
  20. Go to the submitter's workspace chat and verify that a new report (report3) has been created and the held expense was moved to it
  21. Verify that the report3 has copies of the SUBMITTED and APPROVE report actions from the report1, with the same actors and timestamps
  22. Verify that a new report action is added to the report3 stating that it was created for the held expenses from the report1
  23. Verify that report3 is awaiting approval from approver2
  24. As approver3 go to the submitter's workspace chat and click on the report1
  25. Hold an expense and then click on the Approve button for the report1
  26. Choose to only approve the unheld expenses
  27. Verify that you see a report action for the approver3 approval and the report1 now only has the 2 unheld expenses, and is finally approved
  28. Go to the submitter's workspace chat and verify that a new report (report4) has been created and the held expense was moved to it
  29. Verify that the report4 has copies of the SUBMITTED and APPROVE report actions from the report1, with the same actors and timestamps
  30. Verify that a new report action is added to the report4 stating that it was created for the held expenses from the report1
  31. Verify that report4 is awaiting approval from approver3

@mohammadjafarinejad
Copy link
Contributor Author

mohammadjafarinejad commented Dec 26, 2025

@parasharrajat Thanks for the test steps.

@cristipaval I think we need a new parameter in PayMoneyRequestParams called optimisticDuplicatedReportActionIDs (similar to optimisticHoldReportExpenseActionIDs) to prevent duplicate workflow actions.

Currently, when workflow actions are copied to a new partial report, they appear duplicated because the backend generates new IDs instead of using the frontend's optimistic IDs.

/**
* Stringified JSON object with type of following structure:
* Array<{
* optimisticReportActionID: string;
* oldReportActionID: string;
* }>
*/
optimisticHoldReportExpenseActionIDs?: string;

@cristipaval
Copy link
Contributor

I'll work on this early next week

@parasharrajat
Copy link
Member

Gentle reminder for this @cristipaval.

@cristipaval cristipaval self-requested a review January 7, 2026 11:19
@cristipaval
Copy link
Contributor

Currently, when workflow actions are copied to a new partial report, they appear duplicated because the backend generates new IDs instead of using the frontend's optimistic IDs.

@mohammadjafarinejad @parasharrajat, could you please help me with the reproduction steps for this? 🙏

@parasharrajat
Copy link
Member

parasharrajat commented Jan 7, 2026

@cristipaval

  1. Create an expense report with multiple expenses in a workspace where approval workflow is disabled.
  2. Hold a few of them.
  3. Submit the report.
  4. Retract the report.
  5. Submit the report again.
  6. Set hold again if removed.
  7. Pay the report.
  8. Select pay only unheld expenses option.
  9. Open the new report.
  10. Check whether the submitted or retracted actions were copied properly.

@parasharrajat
Copy link
Member

@mohammadjafarinejad We shouldn't copy the actions for Pay Flow. Can you restrict it to approvals only?

Did you check whether backend creates copy of actions for pay flow as well?

@cristipaval
Copy link
Contributor

cristipaval commented Jan 7, 2026

@mohammadjafarinejad We shouldn't copy the actions for Pay Flow. Can you restrict it to approvals only?

Did you check whether backend creates copy of actions for pay flow as well?

yes, @parasharrajat and I chatted internally and I confirm this. I also tested and the backend doesn't create report action copies as part of the Pay flow

@parasharrajat
Copy link
Member

Any update @mohammadjafarinejad

@parasharrajat
Copy link
Member

Bump @mohammadjafarinejad

@cristipaval
Copy link
Contributor

Screenshot 2026-01-12 at 15 00 35

@parasharrajat
Copy link
Member

I see. thanks.

@dylanexpensify dylanexpensify requested review from hungvu193 and removed request for hungvu193 January 13, 2026 15:49
@hungvu193
Copy link
Contributor

Oh I can take over, but since the contributor was the author. I think I'll open a new PR based on these changes here?

@hungvu193
Copy link
Contributor

yes, @parasharrajat and I chatted internally and I confirm this. I also tested and the backend doesn't create report action copies as part of the Pay flow

@parasharrajat @cristipaval Quick question: Which action is related to the Pay flow?

@parasharrajat
Copy link
Member

parasharrajat commented Jan 13, 2026

when you say action? What do you mean @hungvu193?

Here are the test steps for pay flow #77960 (comment).

@hungvu193
Copy link
Contributor

when you say action? What do you mean @hungvu193?

Here are the test steps for pay flow #77960 (comment).

Oh I mean report action.

@parasharrajat
Copy link
Member

parasharrajat commented Jan 13, 2026

You will have to debug that. I am not sure about it currently. So you need to add if condition to make sure that changes are only only approveflow. I don't remember but we recently merged a PR that adds that filteration logic so you just need to use that.

https://github.com/Expensify/App/pull/78267/changes#diff-6fb87ca734958ef32027f3b720e56041d036618453094cf930d4d877e592b7ff

@hungvu193
Copy link
Contributor

I see. Thanks!

@hungvu193
Copy link
Contributor

I created a draft PR here: https://github.com/Expensify/App/pull/79524/changes

@cristipaval cristipaval closed this pull request by merging all changes into Expensify:main in 03484e9 Jan 19, 2026
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