Skip to content

Add error handling for cases where the expense may have moved before rejection - #92860

Open
akinwale wants to merge 10 commits into
Expensify:mainfrom
akinwale:task-app-630101-webe
Open

Add error handling for cases where the expense may have moved before rejection#92860
akinwale wants to merge 10 commits into
Expensify:mainfrom
akinwale:task-app-630101-webe

Conversation

@akinwale

@akinwale akinwale commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

This handles cases where the expense may have been moved before rejection to be handled more gracefully.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/630131
PROPOSAL: https://github.com/Expensify/Expensify/issues/630131#issuecomment-4636539760

Tests

  1. Launch Expensify.
  2. Create a workspace as user A (owner / admin), and invite user B (employee).
  3. As user B (employee), create an expense report with 2 expenses ($12 and $14 for example) and submit the report.
  4. As user A (admin), open the submitted expense report.
  5. As user A, go offline.
  6. As user B, move the $14 expense to a different report.
  7. As user A, reject the $14 expense while offline.
  8. As user A, go back online.
  9. As user A, verify that an error message showing that the expense has already been moved or rejected is displayed.
  10. As user A, upon dismissing the error, verify that the failed expense row is no longer displayed in the report.
  • Verify that no errors appear in the JS console

Offline tests

Same as QA steps.

QA Steps

  1. Launch Expensify.
  2. Create a workspace as user A (owner / admin), and invite user B (employee).
  3. As user B (employee), create an expense report with 2 expenses ($12 and $14 for example) and submit the report.
  4. As user A (admin), open the submitted expense report.
  5. As user A, go offline.
  6. As user B, move the $14 expense to a different report.
  7. As user A, reject the $14 expense while offline.
  8. As user A, go back online.
  9. As user A, verify that an error message showing that the expense has already been moved or rejected is displayed.
  10. As user A, upon dismissing the error, verify that the failed expense row is no longer displayed in the report.

// 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
    • 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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-07-30.at.18.18.12.mp4

@melvin-bot

melvin-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@akinwale akinwale changed the title Add error handling for cases where the expense may have moved before rejection [HOLD Web-E 53502] Add error handling for cases where the expense may have moved before rejection Jun 11, 2026
@akinwale
akinwale marked this pull request as ready for review June 11, 2026 14:20
@akinwale
akinwale requested review from a team as code owners June 11, 2026 14:20
@melvin-bot
melvin-bot Bot requested review from gijoe0295 and joekaufmanexpensify and removed request for a team June 11, 2026 14:20
@melvin-bot

melvin-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 918e742e37

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +257 to +258
errorFields: {
partial: getMicroSecondOnyxErrorWithTranslationKey('iou.rejectReport.couldNotRejectExpense'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Surface the reject failure on a displayed error field

This writes the new failure message to transaction.errorFields.partial, but the transaction error consumers I found only render transaction.errorFields.route/waypoints or transaction.errors (for example ReportActionItem selects only transaction?.errorFields?.route, and MoneyRequestReceiptView merges route/waypoints/errors). In the offline move-then-reject failure path, the Onyx update is applied but no component reads partial, so the expected “expense could not be rejected” message is not shown. Please store this on a rendered report action/report error or wire partial into the transaction UI.

Useful? React with 👍 / 👎.

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.

@akinwale I think this is a valid concern. From my testing, we would only see the backend error message The expense has already been moved or rejected., not this client message.

@akinwale akinwale changed the title [HOLD Web-E 53502] Add error handling for cases where the expense may have moved before rejection Add error handling for cases where the expense may have moved before rejection Jun 21, 2026
@akinwale

Copy link
Copy Markdown
Contributor Author

@gijoe0295 This is ready for review.

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

Good for product 👍

@gijoe0295

gijoe0295 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Also, when opening the expense, it flickers from the expense view to not found page:

Screen.Recording.2026-06-25.at.00.14.31.mov

Should we remove the transaction completely, and show the error at report level/full-screen modal since this transaction no longer exists/is not accessible? cc @joekaufmanexpensify as this is product choice and I can't access the internal link above.

@gijoe0295

gijoe0295 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

An example of a full-screen error modal when deleting workspace:

Screenshot 2026-06-25 at 00 21 32

The error comes from backend so we can only know and show that modal depending on API response which seems similar to this case.

@akinwale

akinwale commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@joekaufmanexpensify bump on #92860 (comment) in case you missed it.

@joekaufmanexpensify

Copy link
Copy Markdown
Contributor

I'm not totally sold on showing the error at the report level. This would potentially be an error they see much later on, right? If they were offline for a while and then go back on later, it may not be immediately clear what the error relates to.

Don't we have a pattern where we show an expense on a report with lower opacity and make it dismissible with an error? I think we use it if you try and scan a receipt and the scan fails. Maybe that could work well here?

@aldo-expensify

Copy link
Copy Markdown
Contributor

friendly bump @akinwale

@gijoe0295

This comment was marked as outdated.

@gijoe0295

Copy link
Copy Markdown
Contributor

Oops sorry @akinwale turn

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
...stReportView/MoneyRequestReportTransactionItem.tsx 82.92% <100.00%> (+82.92%) ⬆️
src/libs/actions/IOU/RejectMoneyRequest.ts 84.13% <100.00%> (+6.95%) ⬆️
src/libs/actions/Transaction.ts 80.44% <100.00%> (ø)
... and 15 files with indirect coverage changes

@akinwale

Copy link
Copy Markdown
Contributor Author

@gijoe0295 I pushed a follow-up backend fix for this. Once that is deployed, I will ping you to let you know that the App changes are ready for review.

@akinwale

akinwale commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@gijoe0295 The Web-E PR was deployed to production. This is ready for review.

@gijoe0295

Copy link
Copy Markdown
Contributor

Bug: I need to close the report RHP then reopen for the error to show up:

Untitled.mov

@gijoe0295

gijoe0295 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Bug: The deleted expense RHP is automatically dismissed after opening. I think we should block opening it.

Screen.Recording.2026-08-17.at.16.28.11.mov

@gijoe0295

gijoe0295 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

We might need to add top padding/margin for the RBR:

Screenshot 2026-08-17 at 16 29 21

Comment thread src/languages/en.ts Outdated
rejectedNextStep: 'This report was rejected. Waiting on you to fix the issues and manually resubmit.',
selectMemberError: 'Select a member to reject this report back to.',
couldNotReject: 'The report could not be rejected. Please try again.',
couldNotRejectExpense: 'The expense could not be rejected.',

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.

The error message I received is The expense has already been moved or rejected. which is a backend error, not this.

Comment on lines +168 to +172
// `Transaction.errors` also carries receipt errors, which are objects rendered by their own save/delete UI, so
// keep only the plain message errors here.
const messageErrors: Errors = Object.fromEntries(
Object.entries(transaction.errors ?? {}).filter((entry): entry is [string, string | null] => typeof entry[1] === 'string' || entry[1] === null),
);

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 ErrorUtils.getLatestErrorMessageField already filters out receipt errors, no?

Comment on lines +179 to +180
// A failed action (e.g. rejecting an expense that has already moved) leaves the expense in place with no pending
// action, so opacity has to be forced — `OfflineWithFeedback` only dims on its own while a write is pending.

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
// A failed action (e.g. rejecting an expense that has already moved) leaves the expense in place with no pending
// action, so opacity has to be forced — `OfflineWithFeedback` only dims on its own while a write is pending.

@gijoe0295

This comment was marked as resolved.

@melvin-bot

melvin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx bun ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx bun ./scripts/generateTranslations.ts --compare-ref main

@akinwale

Copy link
Copy Markdown
Contributor Author

We might need to add top padding/margin for the RBR:

Screenshot 2026-08-17 at 16 29 21

Pinging @Expensify/design for thoughts on this.

@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

I expect the styling to follow all our other error rows where it's inside the row:

CleanShot 2026-08-18 at 13 26 58@2x

I know we wanna fade out the row because it's invalid, but I think we should still do that but have the error stand out like normal. cc @Expensify/design for gutcheck here

@akinwale
akinwale force-pushed the task-app-630101-webe branch from 8adab49 to d8115a3 Compare August 18, 2026 05:21
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.

5 participants