diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 22eb7007262f..434e15aa7fbf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4321,19 +4321,19 @@ function getReasonAndReportActionThatRequiresAttention( } const optionReportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${optionOrReport.reportID}`]; + // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 + // eslint-disable-next-line @typescript-eslint/no-deprecated + const policy = getPolicy(optionOrReport.policyID); const invoiceReceiverPolicyID = optionOrReport?.invoiceReceiver && 'policyID' in optionOrReport.invoiceReceiver ? optionOrReport.invoiceReceiver.policyID : undefined; // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 // eslint-disable-next-line @typescript-eslint/no-deprecated const invoiceReceiverPolicy = invoiceReceiverPolicyID ? getPolicy(invoiceReceiverPolicyID) : undefined; - const {reportAction: iouReportActionToApproveOrPay, actionBadge} = getIOUReportActionWithBadge(optionOrReport, undefined, optionReportMetadata, invoiceReceiverPolicy); + const {reportAction: iouReportActionToApproveOrPay, actionBadge} = getIOUReportActionWithBadge(optionOrReport, policy, optionReportMetadata, invoiceReceiverPolicy); const iouReportID = getIOUReportIDFromReportActionPreview(iouReportActionToApproveOrPay); const transactions = getReportTransactions(iouReportID); const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isExpensifyCardTransaction(t) && isPending(t)); // Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user - // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 - // eslint-disable-next-line @typescript-eslint/no-deprecated - const policy = getPolicy(optionOrReport.policyID); if ( (optionOrReport.hasOutstandingChildRequest === true || iouReportActionToApproveOrPay?.reportActionID) && (policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO || !hasOnlyPendingTransactions) diff --git a/src/libs/actions/IOU/index.ts b/src/libs/actions/IOU/index.ts index 99cd0f4e1871..87c662d01f94 100644 --- a/src/libs/actions/IOU/index.ts +++ b/src/libs/actions/IOU/index.ts @@ -76,7 +76,6 @@ import { arePaymentsEnabled, getDistanceRateCustomUnit, getMemberAccountIDsForWorkspace, - getPolicy, getSubmitToAccountID, hasDependentTags, hasDynamicExternalWorkflow, @@ -9775,7 +9774,7 @@ function canSubmitReport( function getIOUReportActionWithBadge( chatReport: OnyxEntry, - updatedIouReport: OnyxEntry, + policy: OnyxEntry, reportMetadata: OnyxEntry, invoiceReceiverPolicy: OnyxEntry, ): {reportAction: OnyxEntry; actionBadge?: ValueOf} { @@ -9786,10 +9785,7 @@ function getIOUReportActionWithBadge( if (!action || action.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW || isDeletedAction(action)) { return false; } - const iouReport = updatedIouReport?.reportID === action.childReportID ? updatedIouReport : getReportOrDraftReport(action.childReportID); - // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 - // eslint-disable-next-line @typescript-eslint/no-deprecated - const policy = getPolicy(iouReport?.policyID); + const iouReport = getReportOrDraftReport(action.childReportID); // Only show to the actual payer, exclude admins with bank account access if (canIOUBePaid(iouReport, chatReport, policy, undefined, undefined, undefined, undefined, invoiceReceiverPolicy)) { actionBadge = CONST.REPORT.ACTION_BADGE.PAY; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index b578ad549813..28233f01ea42 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -13389,7 +13389,7 @@ describe('actions/IOU', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${fakeReport.reportID}`, MOCK_REPORT_ACTIONS); - const result = getIOUReportActionWithBadge(fakeReport, undefined, {}, undefined); + const result = getIOUReportActionWithBadge(fakeReport, fakePolicy, {}, undefined); expect(result.reportAction).toMatchObject(MOCK_REPORT_ACTIONS[reportID]); expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.APPROVE); }); @@ -13447,7 +13447,7 @@ describe('actions/IOU', () => { }); await waitForBatchedUpdates(); - const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined); + const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined); expect(result.reportAction).toMatchObject(reportPreviewAction); expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.APPROVE); }); @@ -13510,7 +13510,7 @@ describe('actions/IOU', () => { }); await waitForBatchedUpdates(); - const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined); + const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined); expect(result.reportAction).toMatchObject(reportPreviewAction); expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.PAY); }); @@ -13574,7 +13574,7 @@ describe('actions/IOU', () => { }); await waitForBatchedUpdates(); - const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined); + const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined); expect(result.reportAction).toMatchObject(reportPreviewAction); expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.SUBMIT); }); @@ -13633,7 +13633,7 @@ describe('actions/IOU', () => { }); await waitForBatchedUpdates(); - const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined); + const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined); expect(result.reportAction).toBeUndefined(); expect(result.actionBadge).toBeUndefined(); });