Skip to content

Commit 724f470

Browse files
Merge pull request Expensify#84486 from shubham1206agra/refactor-getPolicy-17
Refactor: Deprecate getPolicy (part 17)
2 parents 0b5c9ed + 0f5c69e commit 724f470

3 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,19 +4321,19 @@ function getReasonAndReportActionThatRequiresAttention(
43214321
}
43224322

43234323
const optionReportMetadata = allReportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${optionOrReport.reportID}`];
4324+
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
4325+
// eslint-disable-next-line @typescript-eslint/no-deprecated
4326+
const policy = getPolicy(optionOrReport.policyID);
43244327
const invoiceReceiverPolicyID = optionOrReport?.invoiceReceiver && 'policyID' in optionOrReport.invoiceReceiver ? optionOrReport.invoiceReceiver.policyID : undefined;
43254328
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
43264329
// eslint-disable-next-line @typescript-eslint/no-deprecated
43274330
const invoiceReceiverPolicy = invoiceReceiverPolicyID ? getPolicy(invoiceReceiverPolicyID) : undefined;
4328-
const {reportAction: iouReportActionToApproveOrPay, actionBadge} = getIOUReportActionWithBadge(optionOrReport, undefined, optionReportMetadata, invoiceReceiverPolicy);
4331+
const {reportAction: iouReportActionToApproveOrPay, actionBadge} = getIOUReportActionWithBadge(optionOrReport, policy, optionReportMetadata, invoiceReceiverPolicy);
43294332
const iouReportID = getIOUReportIDFromReportActionPreview(iouReportActionToApproveOrPay);
43304333
const transactions = getReportTransactions(iouReportID);
43314334
const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isExpensifyCardTransaction(t) && isPending(t));
43324335

43334336
// Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user
4334-
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
4335-
// eslint-disable-next-line @typescript-eslint/no-deprecated
4336-
const policy = getPolicy(optionOrReport.policyID);
43374337
if (
43384338
(optionOrReport.hasOutstandingChildRequest === true || iouReportActionToApproveOrPay?.reportActionID) &&
43394339
(policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO || !hasOnlyPendingTransactions)

src/libs/actions/IOU/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import {
7676
arePaymentsEnabled,
7777
getDistanceRateCustomUnit,
7878
getMemberAccountIDsForWorkspace,
79-
getPolicy,
8079
getSubmitToAccountID,
8180
hasDependentTags,
8281
hasDynamicExternalWorkflow,
@@ -9775,7 +9774,7 @@ function canSubmitReport(
97759774

97769775
function getIOUReportActionWithBadge(
97779776
chatReport: OnyxEntry<OnyxTypes.Report>,
9778-
updatedIouReport: OnyxEntry<OnyxTypes.Report>,
9777+
policy: OnyxEntry<OnyxTypes.Policy>,
97799778
reportMetadata: OnyxEntry<OnyxTypes.ReportMetadata>,
97809779
invoiceReceiverPolicy: OnyxEntry<OnyxTypes.Policy>,
97819780
): {reportAction: OnyxEntry<ReportAction>; actionBadge?: ValueOf<typeof CONST.REPORT.ACTION_BADGE>} {
@@ -9786,10 +9785,7 @@ function getIOUReportActionWithBadge(
97869785
if (!action || action.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW || isDeletedAction(action)) {
97879786
return false;
97889787
}
9789-
const iouReport = updatedIouReport?.reportID === action.childReportID ? updatedIouReport : getReportOrDraftReport(action.childReportID);
9790-
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
9791-
// eslint-disable-next-line @typescript-eslint/no-deprecated
9792-
const policy = getPolicy(iouReport?.policyID);
9788+
const iouReport = getReportOrDraftReport(action.childReportID);
97939789
// Only show to the actual payer, exclude admins with bank account access
97949790
if (canIOUBePaid(iouReport, chatReport, policy, undefined, undefined, undefined, undefined, invoiceReceiverPolicy)) {
97959791
actionBadge = CONST.REPORT.ACTION_BADGE.PAY;

tests/actions/IOUTest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13389,7 +13389,7 @@ describe('actions/IOU', () => {
1338913389

1339013390
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${fakeReport.reportID}`, MOCK_REPORT_ACTIONS);
1339113391

13392-
const result = getIOUReportActionWithBadge(fakeReport, undefined, {}, undefined);
13392+
const result = getIOUReportActionWithBadge(fakeReport, fakePolicy, {}, undefined);
1339313393
expect(result.reportAction).toMatchObject(MOCK_REPORT_ACTIONS[reportID]);
1339413394
expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.APPROVE);
1339513395
});
@@ -13447,7 +13447,7 @@ describe('actions/IOU', () => {
1344713447
});
1344813448
await waitForBatchedUpdates();
1344913449

13450-
const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined);
13450+
const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined);
1345113451
expect(result.reportAction).toMatchObject(reportPreviewAction);
1345213452
expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.APPROVE);
1345313453
});
@@ -13510,7 +13510,7 @@ describe('actions/IOU', () => {
1351013510
});
1351113511
await waitForBatchedUpdates();
1351213512

13513-
const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined);
13513+
const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined);
1351413514
expect(result.reportAction).toMatchObject(reportPreviewAction);
1351513515
expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.PAY);
1351613516
});
@@ -13574,7 +13574,7 @@ describe('actions/IOU', () => {
1357413574
});
1357513575
await waitForBatchedUpdates();
1357613576

13577-
const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined);
13577+
const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined);
1357813578
expect(result.reportAction).toMatchObject(reportPreviewAction);
1357913579
expect(result.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.SUBMIT);
1358013580
});
@@ -13633,7 +13633,7 @@ describe('actions/IOU', () => {
1363313633
});
1363413634
await waitForBatchedUpdates();
1363513635

13636-
const result = getIOUReportActionWithBadge(fakeChatReport, undefined, {}, undefined);
13636+
const result = getIOUReportActionWithBadge(fakeChatReport, fakePolicy, {}, undefined);
1363713637
expect(result.reportAction).toBeUndefined();
1363813638
expect(result.actionBadge).toBeUndefined();
1363913639
});

0 commit comments

Comments
 (0)