Skip to content

[No QA] Report managed card transactions to employee's default policy#94768

Open
s77rt wants to merge 11 commits into
Expensify:mainfrom
s77rt:policy-and-report-list-admin-submit
Open

[No QA] Report managed card transactions to employee's default policy#94768
s77rt wants to merge 11 commits into
Expensify:mainfrom
s77rt:policy-and-report-list-admin-submit

Conversation

@s77rt

@s77rt s77rt commented Jun 27, 2026

Copy link
Copy Markdown
Member

Explanation of Change

Modified the usePolicyForMovingExpenses hook that we use to select the target policyID when moving expenses, if we are moving an unreported managed card transaction then it should be moved to the employee's default policy (and not ours) and since we don't know that info, we will return undefined and this will omit sending the policyID to the backend.

In the backend, when no explicit policyID is provided, it will automatically find and use the preferred policy.

Fixed Issues

#87954
PROPOSAL:

Tests

  • Requires 2 accounts, an admin and an employee
  • Employee have assigned an E-Card.
  • Admin and Employee have different default workspaces
  1. Employee: Have an unreported card expense
  2. Admin: Go to Spend > Expenses and look for the unreported expense
  3. Admin: When reporting the unreported expense verify the Create report option does not display any workspace name under it i.e. no supporting text
  4. Admin: Report the unreported expense
  5. Admin: Verify it was reported with success
  6. Employee: Verify the expense is on a new report that was created on your default workspace
Screen.Recording.2026-06-27.at.11.46.24.AM.mov
  • Verify that no errors appear in the JS console

Offline tests

n/a

QA Steps

n/a

  • 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 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 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)
  • 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.
  • 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

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

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 Δ
...firmationListFooter/hooks/useFooterDerivedFlags.ts 100.00% <100.00%> (ø)
...nents/Navigation/QuickCreationActionsBar/index.tsx 85.36% <100.00%> (-0.18%) ⬇️
...c/components/ReportActionItem/MoneyRequestView.tsx 73.22% <100.00%> (-0.07%) ⬇️
.../SearchPageHeader/SearchActionsBarCreateButton.tsx 96.05% <100.00%> (-0.06%) ⬇️
...es/iou/request/step/IOURequestEditReportCommon.tsx 79.83% <100.00%> (+1.78%) ⬆️
.../components/MoneyRequestHeaderSecondaryActions.tsx 0.51% <0.00%> (+<0.01%) ⬆️
src/pages/iou/SplitExpenseEditPage.tsx 0.00% <0.00%> (ø)
...rc/pages/iou/request/step/IOURequestEditReport.tsx 0.00% <0.00%> (ø)
src/hooks/usePolicyForMovingExpenses.ts 88.23% <71.42%> (+6.60%) ⬆️
...rc/pages/iou/request/step/IOURequestStepReport.tsx 75.32% <71.42%> (+1.00%) ⬆️
... and 1 more
... and 44 files with indirect coverage changes

@s77rt s77rt marked this pull request as ready for review June 27, 2026 10:56
@s77rt s77rt requested review from a team as code owners June 27, 2026 10:56
@melvin-bot melvin-bot Bot requested review from flaviadefaria and marcochavezf and removed request for a team June 27, 2026 10:56
@melvin-bot

melvin-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

@marcochavezf 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 27, 2026 10:57
@s77rt s77rt requested review from luacmartins and removed request for marcochavezf June 27, 2026 10:57
@s77rt

s77rt commented Jun 27, 2026

Copy link
Copy Markdown
Member Author

Does this need C+ review?

const [betas] = useOnyx(ONYXKEYS.BETAS);
const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
const hasPerDiemTransactions = useHasPerDiemTransactions(selectedTransactionsKeys);
const hasUnreportedManagedCardTransactions = transactions.some((transaction) => isExpenseUnreported(transaction) && isManagedCardTransaction(transaction));

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.

❌ CONSISTENCY-3 (docs)

The predicate isExpenseUnreported(transaction) && isManagedCardTransaction(transaction) is duplicated verbatim across three files in this PR (SearchTransactionsChangeReport.tsx, IOURequestEditReport.tsx, and IOURequestStepReport.tsx). It expresses a single named concept ("unreported managed card transaction") that is now spread across the codebase, so any change to the definition has to be made in multiple places.

Extract a reusable helper in TransactionUtils and call it from each site:

// src/libs/TransactionUtils/index.ts
function isUnreportedManagedCardTransaction(transaction?: OnyxEntry<Transaction>): boolean {
    return isExpenseUnreported(transaction) && isManagedCardTransaction(transaction);
}
// callers
const hasUnreportedManagedCardTransactions = transactions.some(isUnreportedManagedCardTransaction);

Reviewed at: e280d03 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined;
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [transactions] = useTransactionsByID(transactionIDs);
const hasUnreportedManagedCardTransactions = transactions.some((transaction) => isExpenseUnreported(transaction) && isManagedCardTransaction(transaction));

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.

❌ CONSISTENCY-3 (docs)

The predicate isExpenseUnreported(transaction) && isManagedCardTransaction(transaction) is duplicated here and in SearchTransactionsChangeReport.tsx and IOURequestStepReport.tsx. Consolidate this single concept into one util so it stays consistent.

Add isUnreportedManagedCardTransaction(transaction) to TransactionUtils and reuse it:

const hasUnreportedManagedCardTransactions = transactions.some(isUnreportedManagedCardTransaction);

Reviewed at: e280d03 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

: selectedReport?.ownerAccountID;
const ownerPersonalDetails = getPersonalDetailsForAccountID(ownerAccountID, personalDetails) as PersonalDetails;
const isPerDiemTransaction = isPerDiemRequest(transaction);
const isUnreportedManagedCardTransaction = isExpenseUnreported(transaction) && isManagedCardTransaction(transaction);

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.

❌ CONSISTENCY-3 (docs)

The predicate isExpenseUnreported(transaction) && isManagedCardTransaction(transaction) is duplicated here and in SearchTransactionsChangeReport.tsx and IOURequestEditReport.tsx. Extract it into a single TransactionUtils helper and call that helper here:

const isUnreportedManagedCardTransaction = isUnreportedManagedCardTransactionUtil(transaction);

Reviewed at: e280d03 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@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: e280d034aa

ℹ️ 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".

const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined;
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [transactions] = useTransactionsByID(transactionIDs);
const hasUnreportedManagedCardTransactions = transactions.some((transaction) => isExpenseUnreported(transaction) && isManagedCardTransaction(transaction));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Pass managed-card flag into the parent policy lookup

When this edit-report page is used for an unreported managed-card transaction, this flag is only passed to IOURequestEditReportCommon for display; the usePolicyForMovingExpenses(...) call above still runs without it, and createReportForPolicy uses that resolved policy in createNewReport. If the admin has an active/default workspace, pressing “Create report” from this flow still sends the admin's policyID instead of omitting policyID so the backend can choose the employee's default policy.

Useful? React with 👍 / 👎.

// If this is an employee's card transaction that we manage, then we should report it to their default policy
// which we don't know. Sending an empty `policyID` instructs the backend to auto-select the preferred policy.
if (isUnreportedManagedCardTransaction) {
return {policyForMovingExpensesID: undefined, policyForMovingExpenses: undefined, shouldSelectPolicy: false, shouldNavigateToUpgradePath: false};

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 Skip no-policy optimistic updates when omitting policyID

This managed-card branch intentionally returns no policy, but the create-report callers still pass that undefined policy into createNewReport. That function builds optimistic data through getPolicyExpenseChat(accountID, policy?.id) and then merges into keys based on parentReport?.reportID, so this path writes partial report_undefined/reportActions_undefined entries and an optimistic report with no policy/parent until the server responds. The backend can auto-select the policy, but the frontend should not build policy-chat optimistic updates when policyID is omitted.

Useful? React with 👍 / 👎.

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.

1 participant