Skip to content

Fix/75109: When auto-reporting is disabled, user cannot submit expens…#75286

Merged
mollfpr merged 4 commits intoExpensify:mainfrom
IjaazA:fix/75109
Nov 18, 2025
Merged

Fix/75109: When auto-reporting is disabled, user cannot submit expens…#75286
mollfpr merged 4 commits intoExpensify:mainfrom
IjaazA:fix/75109

Conversation

@IjaazA
Copy link
Contributor

@IjaazA IjaazA commented Nov 17, 2025

Explanation of Change

When auto-reporting is disabled and a user selects a 1:1 DM participant (not a policy expense chat) on the expense confirmation page, the expense was still being created in the workspace chat instead of the selected 1:1 DM. This happened because requestMoney and createDistanceRequest functions were always using the report prop from the route parameters, which contained the workspace chat reportID, even when the user selected a different participant.

The fix ensures that when a user selects a 1:1 DM participant on the confirm page, we pass undefined for the report parameter to requestMoney and createDistanceRequest functions. This allows the underlying getMoneyRequestInformation function to:

  • Skip using the parentChatReport (since it's undefined)
  • Call getChatByParticipants([payerAccountID, payeeAccountID]) to find the existing 1:1 DM chat
  • If not found, create a new optimistic 1:1 DM chat report

Fixed Issues

$ #75109
PROPOSAL: #75109 (comment)

Tests

  1. Log in to the app with an account that has a workspace
  2. Navigate to Workspace settings and turn off the following:
    • Submission frequency
    • Add approvals
    • Make or track payments
  3. Open FAB (Floating Action Button) > Create expense > Manual
  4. Enter an amount and click Next
  5. On the confirm page, click the "To" field
  6. Select a user (not workspace chat) from the participant selection
  7. Click "Create expense"
  8. Verify that the expense is created in the 1:1 DM chat with the selected user (not in workspace chat)
  9. Verify that no error appears on the created expense
  10. Verify that no errors appear in the JS console

Additional test - Verify workspace chat still works:

  1. Follow steps 1-4 above
  2. On the confirm page, click the "To" field
  3. Select the workspace chat (not a user)
  4. Click "Create expense"
  5. Verify that the expense is created in the workspace chat as expected

Offline tests

  1. Follow the test steps above while offline
  2. Verify that the expense creation behavior matches the expected behavior when online
  3. Verify that the expense appears correctly once the connection is restored

QA Steps

  1. Log in to staging.new.expensify.com with an account that has a workspace
  2. Navigate to Workspace settings and turn off the following:
    • Submission frequency
    • Add approvals
    • Make or track payments
  3. Open FAB (Floating Action Button) > Create expense > Manual
  4. Enter an amount and click Next
  5. On the confirm page, click the "To" field
  6. Select a user (not workspace chat) from the participant selection
  7. Click "Create expense"
  8. Verify that the expense is created in the 1:1 DM chat with the selected user (not in workspace chat)
  9. Verify that no error appears on the created expense
  10. Verify that no errors appear in the JS console

Additional QA test - Verify workspace chat still works:

  1. Follow steps 1-4 above
  2. On the confirm page, click the "To" field
  3. Select the workspace chat (not a user)
  4. Click "Create expense"
  5. Verify that the expense is created in the workspace chat as expected

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
    • MacOS: Desktop
  • 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: mWeb Chrome
Recording_20251117_125655.mp4
iOS: mWeb Safari
Screen.Recording.2025-11-17.at.12.12.00.PM.mov
Android: mWeb Chrome
Screen.Recording.2025-11-18.at.12.58.58.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2025-11-17.at.4.36.47.PM.mov
MacOS: Desktop
Screen.Recording.2025-11-17.at.3.20.43.PM.mov

@github-actions
Copy link
Contributor

github-actions bot commented Nov 17, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@IjaazA
Copy link
Contributor Author

IjaazA commented Nov 17, 2025

I have read the CLA Document and I hereby sign the CLA

CLABotify added a commit to Expensify/CLA that referenced this pull request Nov 17, 2025
@IjaazA IjaazA marked this pull request as ready for review November 17, 2025 12:13
@IjaazA IjaazA requested review from a team as code owners November 17, 2025 12:13
@melvin-bot melvin-bot bot requested a review from ikevin127 November 17, 2025 12:13
@melvin-bot
Copy link

melvin-bot bot commented Nov 17, 2025

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

Copy link
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

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

Good from a product perspective 👍

@ikevin127
Copy link
Contributor

ikevin127 commented Nov 17, 2025

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 tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 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)
  • 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.js or at the top of the file that uses the constant) are defined as such
  • 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 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.
  • 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
android-hybrid.mp4
Android: mWeb Chrome
android-mweb.mp4
iOS: HybridApp
ios-hybrid.mov
iOS: mWeb Safari
ios-mweb.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov

@ikevin127
Copy link
Contributor

@IjaazA Good job on the detailed PR Explanation of Change and thorough manual tests! ⚠️ One thing I noticed is you did not attach proof of fix for all platforms as mentioned in the checklist:

Screenshots/Videos

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

☝️ These are all mandatory on every PR for both contributor and reviewer, without this we're blocked from proceeding.

🔄 Continuing with the code review...

Comment on lines +523 to +524
const shouldUseParentChatReport = participant.isPolicyExpenseChat;
const parentChatReport = shouldUseParentChatReport ? report : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Issue: Duplication of parentChatReport logic across three functions

The same two–three lines of logic are repeated in:

requestMoney
trackExpense
createDistanceRequest

While this is small, it couples three flows to the same business rule in a copy-pasted way. If a future bug fix tweaks the logic (for example, handling a new chat type, or a flag where we must ignore report even for certain policy chats), it’d be easy to update one call site and forget the others.

Why this matters / potential bug if left as-is

Imagine we later decide that, for certain policies, distance requests should never inherit the route report, even when isPolicyExpenseChat is true. If we only remember to update requestMoney and forget createDistanceRequest, we’d see:

• Expenses created correctly for manual receipts in the right chat.
• Distance expenses still created in the wrong workspace chat.

That would be a subtle behavior regression that’s hard to spot, because only some IOU types and request types would misbehave.

Suggested fix

Factor this into a small helper inside the component:

function getParentChatReportForParticipant(participant: Participant | undefined, report: Report | undefined) {
    if (!participant?.isPolicyExpenseChat) {
        return undefined;
    }
    return report;
}

Then reuse it in for all 3 scenarios:

const participant = selectedParticipants.at(0);
if (!participant) {
    return;
}
// new code
const parentChatReport = getParentChatReportForParticipant(participant, report);

requestMoneyIOUActions({
    report: parentChatReport,
    // ...
});

Copy link
Contributor

Choose a reason for hiding this comment

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

🟢 The suggested fix for this duplication will be resolved if the suggested fix from this comment is applied first.

if (!transaction) {
return;
}
const participant = selectedParticipants.at(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Issue: Missing defensive empty-participant guard in createDistanceRequest

Unlike requestMoney and trackExpense, this function does not early-return when participant is empty.

Today the UI likely always passes at least one participant, but this function is a critical backend boundary between UI and createDistanceRequestIOUActions. If a future regression allows confirming with no participant (e.g., a bug in MoneyRequestConfirmationList), selectedParticipants could be [].

createDistanceRequestIOUActions then calls participants.at(0) internally and passes a participant with no accountID to getMoneyRequestInformation which will:

• Set payerAccountID = Number(participant.accountID)0.
• Try getChatByParticipants([0, payeeAccountID]), possibly creating a bogus self / ghost chat.

Why this matters / potential bug if left as-is

If this edge case happens, you could end up with:

• Distance expenses linked to a chat that has no real participant (payer account ID 0)
• Confusing history/actions in some “ghost” conversation where nothing else lives
• Potential future crashes if other code assumes a chat’s participants always map to real account IDs

Suggested fix

Mirror the pattern in requestMoney / trackExpense:

const participant = selectedParticipants.at(0);
if (!participant) {
    return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

👉 This one is still valid even if the "🔴 Regression Alert" fix is applied.

@ikevin127
Copy link
Contributor

🔴 Regression Alert

@IjaazA When testing the flow while offline, optimistically the report still thinks it's being sent to a workspace therefore requiring category and getting the 🔴 Category missing. error on the report preview only, if opened, the expense doesn't even have the category field / error (expected since it was sent correctly to a 1:1 DM).

This is how it looks optimistically (while offline):

MacOS: Desktop Screenshot 2025-11-17 at 15 29 46

The issue can be seen even when online, briefly on mWeb & Native I noticed it for a split second, same reason:

iOS: Native
ios-hybrid.mov

🟢👇

See RCA + Solution

Here’s what’s going on and how I’d fix it:

1. Root cause: Violations still use the workspace policy for DM expenses
1.1 Where the “Missing category” message comes from

The “Missing category” text is the violations.missingCategory string, driven by this logic in ViolationsUtils.getViolationsOnyxData:

const policyRequiresCategories = !!policy.requiresCategory;
if (policyRequiresCategories) {
    const hasMissingCategoryViolation = transactionViolations.some((violation) => violation.name === 'missingCategory');
    const categoryKey = updatedTransaction.category;
    const isCategoryInPolicy = categoryKey ? policyCategories?.[categoryKey]?.enabled : false;

    // Remove 'missingCategory' violation if category is valid according to policy
    if (hasMissingCategoryViolation && (isCategoryInPolicy || isSelfDM)) {
        newTransactionViolations = reject(newTransactionViolations, {name: 'missingCategory'});
    }

    // Add 'missingCategory' violation if category is required and not set
    if (!hasMissingCategoryViolation && policyRequiresCategories && !categoryKey && !isSelfDM) {
        newTransactionViolations.push({name: 'missingCategory', type: CONST.VIOLATION_TYPES.VIOLATION, showInReview: true});
    }
}

The key pieces:

• It uses policy.requiresCategory to decide whether category is required.
• It only suppresses the violation if isSelfDM is true.
• If policy.requiresCategory is true, category is empty, and isSelfDM is falsy → you get a missingCategory violation.

1.2 Who calls this for newly created expenses

When you call requestMoneyIOUActions from IOURequestStepConfirmation, it eventually goes through:

• requestMoney() in src/libs/actions/IOU.ts →
• getMoneyRequestInformation() →
• buildOnyxDataForMoneyRequest() →
• and inside that:

// We don't need to compute violations unless we're on a paid policy
if (!policy || !isPaidGroupPolicy(policy) || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID) {
    return [optimisticData, successData, failureData];
}

const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
    transaction,
    [],
    policy,
    policyTagList ?? {},
    policyCategories ?? {},
    hasDependentTags(policy, policyTagList ?? {}),
    false, // <-- isInvoiceTransaction
    // NOTE: isSelfDM is *not* passed here, so it's implicitly undefined/false
)

Crucially:

• It passes your workspace policy into ViolationsUtils.
• It never passes isSelfDM, so the last argument is undefined → treated as not self DM.
• On a paid workspace with requiresCategory = true, any transaction without category will get a missingCategory violation, no matter whether it’s going to a workspace or a DM.

1.3 Why this shows up only now with DM flows

Before your change, for “Create expense from workspace”:

• You passed report (workspace chat) into requestMoneyIOUActions.
• getMoneyRequestInformation would build an expense report under that policy, and applying policy violations made sense.

After your change:

• For 1:1 DM selections, you correctly pass report: undefined so the IOU logic finds/creates the DM chat.
• But you still pass the workspace policy into requestMoneyIOUActions.

So:

• The chat/report is now correct (DM).
• The policy context used for violations is still the workspace, so the preview (“next step” / RBR banner) applies workspace rules to a non-workspace expense.
• Result: “Missing category” on an IOU in a DM, even though the category field isn’t required or even visible when you open the expense.

That matches exactly what you’re seeing: the expense is created in the DM correctly, but the optimistic preview is polluted by the workspace’s policy.

2. Concrete fix: Don’t pass workspace policy for non‑workspace participants
2.1 Adjust requestMoney to conditionally pass policyParams

We want to:

• Use workspace policy only when the destination is a policy expense chat.
• For 1:1 DMs, pass no policy so buildOnyxDataForMoneyRequest short-circuits and doesn’t compute policy violations.

Why this fixes the bug

• For policy expense chat selections:
◦ participant.isPolicyExpenseChat === true
◦ We pass the workspace policy into requestMoneyIOUActions.
◦ Violations (including “Missing category”) are still computed as before, which is what we want.
• For 1:1 DM selections:
◦ participant.isPolicyExpenseChat === false
◦ policyParams becomes {} → policy is undefined inside buildOnyxDataForMoneyRequest.
◦ The early-return if (!policy || !isPaidGroupPolicy(policy) || ...) triggers, so:
▪ No getViolationsOnyxData call.
▪ No missingCategory violation.
▪ No misleading “Missing category” preview on the DM expense.

If this isn’t done, DM expenses created from a paid workspace will continue to show false-positive policy violations (like missing category) in their optimistic previews, even though they aren’t governed by that workspace’s policy when you open them.

2.2 Mirror this approach for trackExpense and createDistanceRequest (recommended)

The same pattern exists in:

• trackExpense → getTrackExpenseInformation → its own buildOnyxDataForMoneyRequest call and violation computation.
• createDistanceRequest → getMoneyRequestInformation → buildOnyxDataForMoneyRequest.

To prevent the same class of bug for:

• Tracked expenses moved into DMs, and
• Distance expenses created into DMs,

you should apply the same conditional policyParams logic in those callbacks, then use policyParams in the respective trackExpenseIOUActions / createDistanceRequestIOUActions calls.

If you don’t do this, you’ll end up with the exact same type of issue for those flows: DM expenses that look like they still need to obey workspace policy in their previews, while the actual opened transaction doesn’t show the required fields.

Solution - Centralize in “workspace vs DM” context

To make this harder to regress later, you can:

  1. Extract a helper in IOURequestStepConfirmation:
function getMoneyRequestContextForParticipant(participant: Participant | undefined, report: Report | undefined) {
       const isWorkspaceTarget = !!participant?.isPolicyExpenseChat;
       return {
           parentChatReport: isWorkspaceTarget ? report : undefined,
           policyParams: isWorkspaceTarget
               ? {
                     policy,
                     policyTagList: policyTags,
                     policyCategories,
                     policyRecentlyUsedCategories,
                 }
               : {},
       };
   }
  1. Use it consistently in requestMoney, trackExpense, and createDistanceRequest:
Example DIFF
diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx
index 94c57d2ed80..17538f64c24 100644
--- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx
+++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx
@@ -510,6 +510,21 @@ function IOURequestStepConfirmation({
         });
     }, [requestType, iouType, initialTransactionID, reportID, action, report, transactions, participants]);
 
+    function getMoneyRequestContextForParticipant(participant: Participant | undefined, report: Report | undefined) {
+        const isWorkspaceTarget = !!participant?.isPolicyExpenseChat;
+        return {
+            parentChatReport: isWorkspaceTarget ? report : undefined,
+            policyParams: isWorkspaceTarget
+                ? {
+                        policy,
+                        policyTagList: policyTags,
+                        policyCategories,
+                        policyRecentlyUsedCategories,
+                    }
+                : {},
+        };
+    }
+
     const requestMoney = useCallback(
         (selectedParticipants: Participant[], gpsPoint?: GpsPoint) => {
             if (!transactions.length) {
@@ -520,9 +535,8 @@ function IOURequestStepConfirmation({
             if (!participant) {
                 return;
             }
-            const shouldUseParentChatReport = participant.isPolicyExpenseChat;
-            const parentChatReport = shouldUseParentChatReport ? report : undefined;
 
+            const {parentChatReport, policyParams} = getMoneyRequestContextForParticipant(participant, report);
             const optimisticChatReportID = generateReportID();
             const optimisticCreatedReportActionID = rand64();
             const optimisticReportPreviewActionID = rand64();
@@ -551,12 +565,7 @@ function IOURequestStepConfirmation({
                         payeeAccountID: currentUserPersonalDetails.accountID,
                         participant,
                     },
-                    policyParams: {
-                        policy,
-                        policyTagList: policyTags,
-                        policyCategories,
-                        policyRecentlyUsedCategories,
-                    },
+                    policyParams,
                     gpsPoint,
                     action,
                     transactionParams: {
@@ -677,8 +686,7 @@ function IOURequestStepConfirmation({
             if (!participant) {
                 return;
             }
-            const shouldUseParentChatReport = participant.isPolicyExpenseChat;
-            const parentChatReport = shouldUseParentChatReport ? report : undefined;
+            const {parentChatReport, policyParams} = getMoneyRequestContextForParticipant(participant, report);
             transactions.forEach((item, index) => {
                 const isLinkedTrackedExpenseReportArchived =
                     !!item.linkedTrackedExpenseReportID && archivedReportsIdSet.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${item.linkedTrackedExpenseReportID}`);
@@ -692,11 +700,7 @@ function IOURequestStepConfirmation({
                         payeeAccountID: currentUserPersonalDetails.accountID,
                         participant,
                     },
-                    policyParams: {
-                        policy,
-                        policyCategories,
-                        policyTagList: policyTags,
-                    },
+                    policyParams,
                     transactionParams: {
                         amount: item.amount,
                         distance: isManualDistanceRequest ? (item.comment?.customUnit?.quantity ?? undefined) : undefined,
@@ -754,8 +758,7 @@ function IOURequestStepConfirmation({
                 return;
             }
             const participant = selectedParticipants.at(0);
-            const shouldUseParentChatReport = participant?.isPolicyExpenseChat ?? false;
-            const parentChatReport = shouldUseParentChatReport ? report : undefined;
+            const {parentChatReport, policyParams} = getMoneyRequestContextForParticipant(participant, report);
             createDistanceRequestIOUActions({
                 report: parentChatReport,
                 participants: selectedParticipants,
@@ -763,12 +766,7 @@ function IOURequestStepConfirmation({
                 currentUserAccountID: currentUserPersonalDetails.accountID,
                 iouType,
                 existingTransaction: transaction,
-                policyParams: {
-                    policy,
-                    policyCategories,
-                    policyTagList: policyTags,
-                    policyRecentlyUsedCategories,
-                },
+                policyParams,
                 transactionParams: {
                     amount: transaction.amount,
                     comment: trimmedComment,

This ensures that chat routing and policy / violation behavior always stay in sync: if you’re not using the workspace report, you’re also not using the workspace policy.

  1. What bug this prevents

If this isn’t addressed:

• Any expense created from a paid workspace but sent to a 1:1 DM will:
◦ Be routed to the correct DM chat (thanks to your fix),
◦ But still show workspace policy violations in the preview, like “Missing category”.
• This is especially confusing offline:
◦ The user sees a red “Missing category” banner on the DM expense they can’t fix from that context.
◦ When they open the expense, the category field/error isn’t even present, eroding trust in the preview.
• For admins, these false “Missing category” violations can:
◦ Inflate counts of non-compliant expenses.
◦ Cause them to intervene unnecessarily in expenses that don’t actually violate any policy.

By conditioning the policyParams on participant.isPolicyExpenseChat, you keep:

• Workspace expenses fully policy-aware (including category violations),
• DM expenses free of irrelevant workspace policy noise, both online and offline.

@ikevin127
Copy link
Contributor

ikevin127 commented Nov 18, 2025

Reviewer checklist completed. Awaiting for the requested changes to be applied and conflicts to be resolved before I can review again and approve if all good.

Please make sure to run npm run prettier and npm run lint-changed before commiting your local changes, this to avoid doing them later when automated workflows fail if there are any formatting / eslint issues 👍

Copy link
Contributor

@ikevin127 ikevin127 left a comment

Choose a reason for hiding this comment

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

LGTM 🟢

Looks like there are gonna be some conflicts once you merge main, make sure not to lose the changes when resolving the conflicts.

@melvin-bot melvin-bot bot requested a review from mollfpr November 18, 2025 07:51
@mollfpr
Copy link
Contributor

mollfpr commented Nov 18, 2025

@IjaazA Could you resolve the conflict? Thank you!

@IjaazA
Copy link
Contributor Author

IjaazA commented Nov 18, 2025

@mollfpr conflicts were resolved.

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...es/iou/request/step/IOURequestStepConfirmation.tsx 47.85% <0.00%> (-1.38%) ⬇️
... and 5 files with indirect coverage changes

@OSBotify
Copy link
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
Contributor

🚀 Deployed to staging by https://github.com/mollfpr in version: 9.2.61-0 🚀

platform result
🖥 desktop 🖥 failure ❌
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/grgia in version: 9.2.61-5 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mollfpr in version: 9.2.62-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.2.62-5 🚀

platform result
🖥 desktop 🖥 success ✅
🕸 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.

5 participants