Skip to content

Fix report preview approval policy flow - #93876

Merged
carlosmiceli merged 12 commits into
Expensify:mainfrom
KJ21-ENG:KJ21-ENG/93067-raising-flow
Jun 25, 2026
Merged

Fix report preview approval policy flow#93876
carlosmiceli merged 12 commits into
Expensify:mainfrom
KJ21-ENG:KJ21-ENG/93067-raising-flow

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This fixes the report preview approval path so approval workflow decisions use the expense report's policy instead of the currently active workspace policy.

The preview approval callers now pass the expense report policy to approveMoneyRequest(). approveMoneyRequest() also defensively derives a workflow policy from expenseReportPolicy and uses it for DEW detection, optimistic next-step generation, duplicate checks, held-expense approval data, and parent report preview status mirroring.

This keeps DEW behavior backend-driven while allowing normal reports to optimistically update stateNum, statusNum, and managerID even if NVP_ACTIVE_POLICY_ID points at a DEW workspace.

Fixed Issues

$ #93067
PROPOSAL: #93067 (comment)

Tests

  1. In a local/dev environment, sign in as an approver/admin for a normal workspace.
  2. Open a workspace chat that contains an expense report preview for a report pending approval.
  3. If available, switch the active workspace context to a DEW workspace, then return to the normal workspace report preview.
  4. Click the Approve button on the report preview.
  5. Verify the clicked report preview transitions away from Approve once and does not briefly show Approve again after the approved animation clears.
  6. Verify the report preview reaches the expected approved/payable state.
  7. Open the report details and verify the report is approved.
  • Verify that no errors appear in the JS console

Validation run:

  1. python3 /Users/kushjariwla/.codex/skills/expensify-app-targeted-checks/scripts/touched_files.py --base upstream/main
  2. python3 /Users/kushjariwla/.codex/skills/expensify-app-targeted-checks/scripts/touched_files.py --kind format | xargs npx prettier --write
  3. python3 /Users/kushjariwla/.codex/skills/expensify-app-targeted-checks/scripts/touched_files.py --kind lint | xargs npx eslint --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --quiet --concurrency=auto --no-warn-ignored
  4. python3 /Users/kushjariwla/.codex/skills/expensify-app-targeted-checks/scripts/touched_files.py --kind react | xargs npm run react-compiler-compliance-check check
  5. git diff --check
  6. git diff --check upstream/main...HEAD
  7. npm test -- tests/actions/IOUTest/ReportWorkflowTest.ts --runInBand -t "uses the expense report policy for approval optimism when active policy is DEW" --moduleNameMapper='{"^@expensify/react-native-hybrid-app$":"<rootDir>/modules/hybrid-app/src/index.ts"}'

npm run typecheck-tsgo was not run because this PR does not change TypeScript signatures, exported helper types, or React component props.

Offline tests

N/A. This change fixes the online approval transition for an action that requires the backend approval request. It does not add or change offline behavior, offline copy, offline queueing, or offline error handling.

QA Steps

  1. On staging, sign in as an approver/admin for a normal workspace.
  2. Open a workspace chat that contains an expense report preview for a report pending approval.
  3. Click the Approve button on the report preview.
  4. Verify the clicked report preview transitions away from Approve once and does not briefly show Approve again after the approved animation clears.
  5. Verify the report preview reaches the expected approved/payable state.
  6. Open the report details and verify the report is approved.
  • 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 (N/A: approval requires the backend request and this PR does not add or change offline behavior)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (N/A: this single report-preview action change does not affect high-traffic list rendering or bulk-data paths)
  • 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 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
    • 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 (N/A: no new code pattern was added)
  • 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: (N/A: no new files were added)
    • 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: (N/A: no CSS styles were added)
    • 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: (N/A: no assets were added or modified)
    • 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. (N/A: this PR does not modify editing/sending message code)
  • 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 (N/A: this PR does not modify a generic component)
  • 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. (N/A: touched components do not have Storybook coverage affected by this change)
  • 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: (N/A: no visual styling, layout, or form input styles were changed)
    • 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. (N/A: no new page was added)
  • 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
VIDEO-2026-06-18-19-59-04.mp4
Android: mWeb Chrome
VIDEO-2026-06-18-18-47-45.mp4
iOS: Native
Screen.Recording.2026-06-18.at.8.39.01.PM.mov
iOS: mWeb Safari
Screen.Recording.2026-06-18.at.6.52.37.PM.mov
MacOS: Chrome / Safari
ezyZip.52.mp4

@KJ21-ENG
KJ21-ENG marked this pull request as ready for review June 18, 2026 15:25
@KJ21-ENG
KJ21-ENG requested review from a team as code owners June 18, 2026 15:25
@melvin-bot
melvin-bot Bot requested review from FitseTLT and heyjennahay and removed request for a team and heyjennahay June 18, 2026 15:25
@melvin-bot

melvin-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

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

@melvin-bot
melvin-bot Bot removed the request for review from a team June 18, 2026 15:25
@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@FitseTLT Kind ping here. Thanks!

Comment thread src/libs/actions/IOU/ReportWorkflow.ts Outdated
@FitseTLT

Copy link
Copy Markdown
Contributor

conflicts

@KJ21-ENG
KJ21-ENG requested a review from FitseTLT June 24, 2026 07:34
expect(updatedReport?.statusNum).toBe(CONST.REPORT.STATUS_NUM.APPROVED);
});

it('uses the expense report policy for approval optimism when active policy is DEW', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('uses the expense report policy for approval optimism when active policy is DEW', () => {
it('uses the expense report policy (not the activePolicy) to determine if it is a DEW approval', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the test name as suggested.

Comment thread src/libs/actions/IOU/ReportWorkflow.ts Outdated
// since some call sites pass `policy` as the active/personal policy rather than the report's workspace policy.
const policyToUpgrade = expenseReportPolicy ?? policy;
// IMPORTANT: gate by the workspace that owns the expense report.
const policyToUpgrade = expenseReportPolicy;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need this var and comment anymore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. Since approveMoneyRequest now only uses expenseReportPolicy, the extra variable/comment is no longer needed.

Comment thread src/libs/actions/IOU/ReportWorkflow.ts Outdated
Comment on lines +645 to +669

if (!isDEWPolicy && expenseReport.parentReportID && expenseReport.parentReportActionID) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`,
value: {
[expenseReport.parentReportActionID]: {
childStateNum: predictedNextState,
childStatusNum: predictedNextStatus,
...(nextApproverAccountID ? {childManagerAccountID: managerID} : {}),
},
},
});

failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`,
value: {
[expenseReport.parentReportActionID]: {
childStateNum: expenseReport.stateNum,
childStatusNum: expenseReport.statusNum,
...(nextApproverAccountID ? {childManagerAccountID: expenseReport.managerID} : {}),
},
},
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It mirrors the predicted approval state into the parent REPORT_PREVIEW action's childStateNum, childStatusNum, and childManagerAccountID, matching the existing reopen/retract/unapprove patterns. Without this, the parent preview can keep stale child state during optimistic approval.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

totally out of scope. It should be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, i got it, the confussion occured for me as i mentioned this "update parent preview childStateNum, childStatusNum, childManagerAccountID" in proposal and thought i have to add it inorder to keep pr scoprd to approved proposal. but i agree that i should have reconsidered it while applying in this pr. as the parent preview mirror was included as secondary consistency work, but it is not required for the approve-button flicker fix. Applogies


const reportAction = Object.values(reportActionsUpdate?.value as Record<string, ReportAction>).at(0);
expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID);
expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What are these unrelated changes you made in this test file? Pls avoid out of scope changes. You always need to confirm yourself changes made by AI platforms according to Expensify rules. Stop committing AI changes directly and expect the C+ reviewer to do the checking for you. This a formal warning @KJ21-ENG

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually the idea behind introducing the helper was to avoid repeated mock-call inspection while updating the approveMoneyRequest tests. But I reconsider it as applying that cleanup across unrelated delegate cases was broader than this pr needs.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@FitseTLT Can you please shade some light on for what 'formal warning' stands for ? i went through matt's this message on slack but i didnt get much clarity.

and one more humble request from my side that can you please wave off the 'formal warning' , my intensiion was not to breach any guidline and i will be more sharp for this kind of thing in future. Its humble request from my side and sincere applogy as well.

@FitseTLT

Copy link
Copy Markdown
Contributor

@KJ21-ENG Read https://github.com/Expensify/App/blob/main/contributingGuides/AI_ETIQUETTE.md You should always make sure to take responsibility and check before making or suggesting changes generated by AI. Random unrelated changes here and there made me suspect you are directly pushing AI changes. If it is you no problem everyone makes mistakes, but if it is not, you are violating the AI_ETIQUETTE rules that's what I am pointing to.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

@FitseTLT Thanks for refering this and i got your point as well that you were pointing to, the confussion that i have is regarding term 'formal warning' as i havent received anything like this till now. will i be prevented / stoped from contributing to the repo now onwards ?

@FitseTLT

Copy link
Copy Markdown
Contributor

@FitseTLT Thanks for refering this and i got your point as well that you were pointing to, the confussion that i have is regarding term 'formal warning' as i havent received anything like this till now. will i be prevented / stoped from contributing to the repo now onwards ?

No I meant my own formal warning. The proper warning you are seeing in the Matt message is the official company's warning. And you are not in that warning. I am just warning you before I report it officially. Now, as long as you follow the rules you are good.

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

Ah, got it. Now I understand Matt's message as well as yours. I will definitely keep note of this for future. Thanks!

@KJ21-ENG
KJ21-ENG requested a review from FitseTLT June 25, 2026 09:13
Comment on lines 2604 to 2618
it('gates upgrade by expenseReportPolicy even when the report policyID is Submit', () => {
const expenseReport = createSubmittedExpenseReport(submitPolicyID);

approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, submitPolicy, teamPolicy));
approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, teamPolicy));

expect(Navigation.navigate).toHaveBeenCalledTimes(1);
expect(Navigation.navigate).toHaveBeenCalledWith(expectedRoute);
expect(Navigation.navigate).not.toHaveBeenCalled();
});

it('falls back to policy when expenseReportPolicy is undefined', () => {
it('does not fall back to another policy when expenseReportPolicy is undefined', () => {
const expenseReport = createSubmittedExpenseReport(submitPolicyID);
const expectedRoute = ROUTES.WORKSPACE_UPGRADE.getRoute(submitPolicyID, upgradeFeatureAlias, ROUTES.REPORT_WITH_ID.getRoute(expenseReport.reportID), expenseReport.reportID);

approveMoneyRequest({
...createApproveMoneyRequestParams(expenseReport, submitPolicy),
expenseReportPolicy: undefined,
policy: submitPolicy,
});
approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, undefined));

expect(Navigation.navigate).toHaveBeenCalledTimes(1);
expect(Navigation.navigate).toHaveBeenCalledWith(expectedRoute);
expect(Navigation.navigate).not.toHaveBeenCalled();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these two tests are obsolete now that we don't have policy param

@FitseTLT

Copy link
Copy Markdown
Contributor

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
  • 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 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 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)
  • 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)
  • 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.
  • 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
2026-06-25.15-32-20.mp4
Android: mWeb Chrome
iOS: HybridApp
2026-06-25.15-49-46.mp4
iOS: mWeb Safari
2026-06-25.15-56-37.mp4
MacOS: Chrome / Safari
2026-06-25.15-54-53.mp4

@FitseTLT FitseTLT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@melvin-bot
melvin-bot Bot requested a review from carlosmiceli June 25, 2026 22:11
@carlosmiceli
carlosmiceli merged commit a9c2586 into Expensify:main Jun 25, 2026
34 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 carlosmiceli has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
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
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/carlosmiceli in version: 9.4.21-2 🚀

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.4.21-9 🚀

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

Bundle Size Analysis (Sentry):

@FitseTLT FitseTLT mentioned this pull request Jun 29, 2026
51 tasks
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