Skip to content

Commit 1914b7f

Browse files
authored
Merge pull request Expensify#86908 from truph01/fix/66457-part-3
fix: Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.POLICY (part 3)
2 parents 827b444 + 34eb371 commit 1914b7f

16 files changed

Lines changed: 250 additions & 113 deletions

src/components/MoneyReportHeader.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
705705
}
706706
approveMoneyRequest({
707707
expenseReport: moneyRequestReport,
708+
expenseReportPolicy: policy,
708709
policy,
709710
currentUserAccountIDParam: accountID,
710711
currentUserEmailParam: email ?? '',
@@ -1917,6 +1918,7 @@ function MoneyReportHeaderContent({reportID: reportIDProp, shouldDisplayBackButt
19171918
event,
19181919
iouPaymentType,
19191920
triggerKYCFlow,
1921+
expenseReportPolicy: policy,
19201922
policy,
19211923
onPress: confirmPayment,
19221924
currentAccountID: accountID,

src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function useConfirmApproval(reportID: string | undefined, startApprovedAnimation
4343
startApprovedAnimation();
4444
approveMoneyRequest({
4545
expenseReport: moneyRequestReport,
46+
expenseReportPolicy: policy,
4647
policy,
4748
currentUserAccountIDParam: accountID,
4849
currentUserEmailParam: email ?? '',

src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function ApproveActionButton({iouReportID, startApprovedAnimation, onHoldMenuOpe
3232
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
3333
const activePolicy = usePolicy(activePolicyID);
3434
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`);
35+
const [expenseReportPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`);
3536
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
3637
const [iouReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReportID}`);
3738
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
@@ -51,6 +52,7 @@ function ApproveActionButton({iouReportID, startApprovedAnimation, onHoldMenuOpe
5152
} else {
5253
approveMoneyRequest({
5354
expenseReport: iouReport,
55+
expenseReportPolicy,
5456
policy: activePolicy,
5557
currentUserAccountIDParam: currentUserAccountID,
5658
currentUserEmailParam: currentUserEmail,

src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function PayActionButton({
116116
} else {
117117
approveMoneyRequest({
118118
expenseReport: iouReport,
119+
expenseReportPolicy: policy,
119120
policy: activePolicy,
120121
currentUserAccountIDParam: currentUserAccountID,
121122
currentUserEmailParam: currentUserEmail,

src/components/SettlementButton/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function SettlementButton({
106106
const {translate, localeCompare} = useLocalize();
107107
const {isOffline} = useNetwork();
108108
const policy = usePolicy(policyID);
109+
const expenseReportPolicy = usePolicy(iouReport?.policyID);
109110
const {accountID, email} = useCurrentUserPersonalDetails();
110111

111112
// The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
@@ -498,6 +499,7 @@ function SettlementButton({
498499
} else {
499500
approveMoneyRequest({
500501
expenseReport: iouReport,
502+
expenseReportPolicy,
501503
policy,
502504
currentUserAccountIDParam: accountID,
503505
currentUserEmailParam: email ?? '',

src/hooks/useHoldMenuSubmit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment
8282
ownerBillingGracePeriodEnd,
8383
full,
8484
onApproved: animationCallback,
85+
expenseReportPolicy: policy,
8586
delegateEmail,
8687
});
8788
} else if (chatReport && paymentType) {

src/hooks/useSelectionModeReportActions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ function useSelectionModeReportActions({
330330
ownerBillingGracePeriodEnd,
331331
delegateEmail,
332332
full: true,
333+
expenseReportPolicy: policy,
333334
});
334335
clearSelectedTransactions(true);
335336
turnOffMobileSelectionMode();
@@ -448,6 +449,7 @@ function useSelectionModeReportActions({
448449
amountOwed,
449450
ownerBillingGracePeriodEnd,
450451
delegateEmail,
452+
expenseReportPolicy: policy,
451453
});
452454
});
453455
};

src/libs/PaymentUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type SelectPaymentTypeParams = {
3333
event: KYCFlowEvent;
3434
iouPaymentType: PaymentMethodType;
3535
triggerKYCFlow: TriggerKYCFlow;
36+
/** The policy corresponding to iouReport.policyID. Used for billing restriction checks. */
37+
expenseReportPolicy: OnyxEntry<Policy>;
3638
policy: OnyxEntry<Policy>;
3739
onPress: (params: PaymentActionParams) => void;
3840
currentAccountID: number;
@@ -220,6 +222,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
220222
event,
221223
iouPaymentType,
222224
triggerKYCFlow,
225+
expenseReportPolicy,
223226
policy,
224227
onPress,
225228
currentAccountID,
@@ -236,7 +239,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
236239
ownerBillingGracePeriodEnd,
237240
delegateEmail,
238241
} = params;
239-
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
242+
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
240243
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
241244
return;
242245
}
@@ -256,6 +259,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
256259
} else {
257260
approveMoneyRequest({
258261
expenseReport: iouReport,
262+
expenseReportPolicy,
259263
policy,
260264
currentUserAccountIDParam: currentAccountID,
261265
currentUserEmailParam: currentEmail,

src/libs/ReportUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,7 +3022,7 @@ function getAddExpenseDropdownOptions({
30223022
if (
30233023
policy &&
30243024
policy.type !== CONST.POLICY.TYPE.PERSONAL &&
3025-
shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)
3025+
shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)
30263026
) {
30273027
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
30283028
return;
@@ -3039,7 +3039,7 @@ function getAddExpenseDropdownOptions({
30393039
if (!iouReportID) {
30403040
return;
30413041
}
3042-
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
3042+
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
30433043
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
30443044
return;
30453045
}
@@ -3052,7 +3052,7 @@ function getAddExpenseDropdownOptions({
30523052
icon: icons.ReceiptPlus,
30533053
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.ADD_EXPENSE_UNREPORTED,
30543054
onSelected: () => {
3055-
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
3055+
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
30563056
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
30573057
return;
30583058
}
@@ -11472,7 +11472,7 @@ function createDraftTransactionAndNavigateToParticipantSelector({
1147211472
}
1147311473

1147411474
if (actionName === CONST.IOU.ACTION.CATEGORIZE) {
11475-
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
11475+
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)) {
1147611476
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id));
1147711477
return;
1147811478
}

src/libs/actions/IOU/ReportWorkflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllTransactio
6767

6868
type ApproveMoneyRequestFunctionParams = {
6969
expenseReport: OnyxEntry<OnyxTypes.Report>;
70+
expenseReportPolicy: OnyxEntry<OnyxTypes.Policy>;
7071
policy: OnyxEntry<OnyxTypes.Policy>;
7172
currentUserAccountIDParam: number;
7273
currentUserEmailParam: string;
@@ -326,12 +327,13 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
326327
onApproved,
327328
ownerBillingGracePeriodEnd,
328329
delegateEmail,
330+
expenseReportPolicy,
329331
} = params;
330332
if (!expenseReport) {
331333
return;
332334
}
333335

334-
if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
336+
if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, expenseReportPolicy)) {
335337
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(expenseReport.policyID));
336338
return;
337339
}

0 commit comments

Comments
 (0)