Skip to content

Fix incorrect first-submit next-step approver#90877

Merged
chuckdries merged 13 commits into
Expensify:mainfrom
emkhalid:fix/88788-next-step-approver
Jun 5, 2026
Merged

Fix incorrect first-submit next-step approver#90877
chuckdries merged 13 commits into
Expensify:mainfrom
emkhalid:fix/88788-next-step-approver

Conversation

@emkhalid

@emkhalid emkhalid commented May 16, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR fixes the incorrect approver shown in the first optimistic next-step message after submitting an expense report with an approval rule.

The submit flow already calculates the correct managerID, but the optimistic next-step builders receive the existing report before its managerID is updated. As a result, the first optimistic message can show the previous/default approver.

This change keeps getNextApproverAccountID() unchanged and passes the freshly calculated submit manager to the optimistic next-step builders through the existing bypassNextApproverID parameter.

This fixes the first-submit message without affecting approve, unapprove, or reapprove flows.

Fixed Issues

$ #88788
PROPOSAL: #88788 (comment)

Tests

  1. Login as workspace admin.
  2. Create/use a Control workspace.
  3. Enable Workflows, Categories, and Rules.
  4. Add User A and User C as workspace members.
  5. Configure approvals so User A submits to User B by default.
  6. Create/enable category Travel.
  7. Set category approver rule: Travel -> User C.
  8. Login as User A.
  9. Create an expense with category Travel.
  10. Submit the expense report.
  11. Verify the next-step approver is User C, not User B.
  12. Verify that no errors appear in the JS console.
  • Verify that no errors appear in the JS console

Offline tests

  1. Login as User A.
  2. Go offline.
  3. Create an expense with category Travel.
  4. Submit the expense report while offline.
  5. Verify the optimistic next-step message immediately shows User C as the approver.
  6. Verify it does not show the default approver User B.
  7. Verify that no errors appear in the JS console.

QA Steps

Same as tests and offline tests.

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • 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 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-native-approver-fix.mp4
Android: mWeb Chrome
android-web-approver-fix.mp4
iOS: Native
ios-native-approver-fix.mp4
iOS: mWeb Safari
ios-web-approver-fix.mp4
MacOS: Chrome / Safari
macos-approver-fix.mp4

@emkhalid emkhalid marked this pull request as ready for review May 16, 2026 14:05
@emkhalid emkhalid requested review from a team as code owners May 16, 2026 14:05
@melvin-bot melvin-bot Bot requested review from a team, JmillsExpensify and dmkt9 and removed request for a team and JmillsExpensify May 16, 2026 14:05
@melvin-bot

melvin-bot Bot commented May 16, 2026

Copy link
Copy Markdown

@dmkt9 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 requested review from joekaufmanexpensify and removed request for a team May 16, 2026 14:05

@joekaufmanexpensify joekaufmanexpensify 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.

Steps make sense to me

@dmkt9

dmkt9 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Sorry for the delay. I have some priority PRs to review. I will review this one tomorrow. Could you merge the latest main? @emkhalid

@dmkt9

dmkt9 commented May 22, 2026

Copy link
Copy Markdown
Contributor

@emkhalid please merge the latest main

@emkhalid

Copy link
Copy Markdown
Contributor Author

@dmkt9 sorry for the delay, I merged the main

@dmkt9

dmkt9 commented May 22, 2026

Copy link
Copy Markdown
Contributor

@dmkt9 sorry for the delay, I merged the main

@emkhalid Thanks. Taking a look now

@emkhalid

Copy link
Copy Markdown
Contributor Author

@dmkt9 gentle bump, thanks

@dmkt9

dmkt9 commented May 26, 2026

Copy link
Copy Markdown
Contributor

@dmkt9 gentle bump, thanks

@emkhalid Sorry for the delay.

I think we have corrected the submit and approve flow. However, our changes broke the unapprove flow.
Could you review all the unapprove flows corresponding to the cases mentioned in the OP to ensure we haven't broken anything?

Example:

2026-05-27.00-09-12.mp4

@emkhalid

Copy link
Copy Markdown
Contributor Author

checking this, thanks

@emkhalid

Copy link
Copy Markdown
Contributor Author

@dmkt9 Thanks for catching the regression.

I updated the fix to keep getNextApproverAccountID() unchanged and scope the correction to the first optimistic submit next step only.

I manually tested the relevant flows while offline and after reconnecting:

  • Category rule approver
  • Default approver fallback
  • Tag rule approver
  • Category-over-tag priority
  • Multiple expenses with different rule approvers
  • Self-approval fallback
  • Approve and unapprove flows for each case

All flows now work as expected. In particular, the first optimistic submit shows the rule approver correctly, while unapproving keeps the existing workflow approver.

Video demos:

User A: Create and submit expense

Submitter-side.mov

User B: Approve and unapprove expense

approver-side.mp4

Could you please take another look? Thanks!

@dmkt9

dmkt9 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@emkhalid

emkhalid commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@dmkt9 thanks for the review, Removed the unnecessary getNextApproverAccountID() tests since the updated solution no longer changes that helper. Thanks!

@emkhalid

emkhalid commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

The failing test is also not related to our PR, thanks.

@dmkt9

dmkt9 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@emkhalid The tests are failing. Could you merge the latest main branch into this PR and re-trigger them?

@emkhalid

emkhalid commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@emkhalid The tests are failing. Could you merge the latest main branch into this PR and re-trigger them?

Done, thanks

@dmkt9 dmkt9 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 chuckdries June 2, 2026 15:06

@chuckdries chuckdries 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.

Can you talk me through how we're computing optimisticNextStepApproverID? Basically, I'm wondering why we need to call isValidAccountRoute with DEFAULT_NUMBER_ID.

Comment thread src/libs/actions/IOU/ReportWorkflow.ts Outdated
const adminAccountID = policy?.role === CONST.POLICY.ROLE.ADMIN ? currentUserAccountIDParam : undefined;
const parentReport = getReportOrDraftReport(expenseReport.parentReportID);
const managerID = getSubmitReportManagerAccountID(policy, expenseReport);
const optimisticNextStepApproverID = !isSubmitAndClosePolicy && isValidAccountRoute(managerID ?? CONST.DEFAULT_NUMBER_ID) ? managerID : undefined;

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.

This is kind of awkward if I'm interpreting it correctly. Will isValidAccountRoute ever be true for CONST.DEFAULT_NUMBER_ID? If not, I think we can simplify to ...managerID !== undefined && isValidAccountRoute(managerID)... (and maybe ditch the ternary? I'm less sure whether false is equivalent to undefined here)

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.

(and maybe ditch the ternary? I'm less sure whether false is equivalent to undefined here)

We still need to keep undefined here because optimisticNextStepApproverID only accepts number | undefined.

@emkhalid Please update based on this

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.

Addressed

@dmkt9

dmkt9 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

@emkhalid ESLint and typecheck failed

@emkhalid

emkhalid commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@dmkt9 and @chuckdries thanks for the review, I addressed the comment.
The failing test is also not related to our changes

@chuckdries

Copy link
Copy Markdown
Contributor

@emkhalid I see that specific test job is passing in main, try merging main one more time 🙏

@dmkt9

dmkt9 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

@emkhalid bump

@emkhalid

emkhalid commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the delay. I merged the latest main, thanks.

@emkhalid

emkhalid commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@dmkt9 @chuckdries Thanks for the reviews. Everything looks good from my side, so I think we’re good to move forward with this.

@chuckdries chuckdries merged commit f63b744 into Expensify:main Jun 5, 2026
31 checks passed
@OSBotify

OSBotify commented Jun 5, 2026

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.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/chuckdries in version: 9.4.0-0 🚀

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

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Help site review: no changes required.

I reviewed the changes in this PR and no updates to the help site files under App/docs/articles are needed, so I did not create a draft docs PR.

Why

This is a backend bug fix, not a feature or behavior change. It only affects the first optimistic next-step message shown immediately after submitting an expense report that hits an approval (category approver) rule. Before this fix, that transient message could briefly show the previous/default approver; after the fix it shows the correct rule-based approver.

The diff is limited to:

  • src/libs/actions/IOU/ReportWorkflow.ts — passes the freshly calculated submit manager into the optimistic next-step builders via the existing bypassNextApproverID parameter.
  • tests/actions/IOUTest/ReportWorkflowTest.ts — a new unit test covering the stale-manager case.

There are no new or changed user-facing features, tab/setting labels, buttons, or workflows. The intended end-state behavior — approval rules (e.g. a category approver) route a report to the correct approver — is already accurately documented in articles like Add approval workflows and Set workspace rules. This PR simply makes the optimistic message match that already-documented behavior, so nothing in the docs is now inaccurate or incomplete.

@emkhalid — since no docs change is required, there is no linked help site PR to review. If you believe a specific article should still be updated, let me know which behavior you'd like documented and I'll create the draft PR.

@OSBotify

OSBotify commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.0-7 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 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