Skip to content

Commit b31aee2

Browse files
authored
Merge pull request Expensify#89401 from paulnjs/paulnjs-fix/88454
fix: Split action does not trigger paywall in expired workspace
2 parents 40a8a01 + 209fbc6 commit b31aee2

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/libs/actions/SplitExpenses.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTop
66
import Navigation from '@libs/Navigation/Navigation';
77
import {rand64} from '@libs/NumberUtils';
88
import {getTransactionDetails, isOpenReport} from '@libs/ReportUtils';
9+
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
910
import {buildOptimisticTransaction, getChildTransactions, getOriginalTransactionWithSplitInfo, isDistanceRequest} from '@libs/TransactionUtils';
1011
import CONST from '@src/CONST';
1112
import ONYXKEYS from '@src/ONYXKEYS';
1213
import ROUTES from '@src/ROUTES';
13-
import type {Policy, Report, Transaction} from '@src/types/onyx';
14+
import type {BillingGraceEndPeriod, Policy, Report, Transaction} from '@src/types/onyx';
1415
import type {Attendee} from '@src/types/onyx/IOU';
1516
import type {TransactionCustomUnit} from '@src/types/onyx/Transaction';
1617
import {initSplitExpenseItemData, updateSplitExpenseDistanceFromAmount} from './IOU/SplitExpenseItems';
@@ -35,14 +36,47 @@ Onyx.connectWithoutView({
3536
callback: (value) => (allReports = value),
3637
});
3738

39+
let ownerBillingGracePeriodEnd: OnyxEntry<number>;
40+
// We use connectWithoutView because `initSplitExpense` doesn't affect the UI rendering and
41+
// this avoids unnecessary re-rendering for components when owner billing grace period changes. This data should ONLY
42+
// be used for `initSplitExpense`
43+
Onyx.connectWithoutView({
44+
key: ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END,
45+
callback: (value) => (ownerBillingGracePeriodEnd = value),
46+
});
47+
48+
let userBillingGracePeriodEnds: OnyxCollection<BillingGraceEndPeriod>;
49+
// We use connectWithoutView because `initSplitExpense` doesn't affect the UI rendering and
50+
// this avoids unnecessary re-rendering for components when user billing grace periods change. This data should ONLY
51+
// be used for `initSplitExpense`
52+
Onyx.connectWithoutView({
53+
key: ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END,
54+
waitForCollectionCallback: true,
55+
callback: (value) => (userBillingGracePeriodEnds = value),
56+
});
57+
58+
let amountOwed: OnyxEntry<number>;
59+
// We use connectWithoutView because `initSplitExpense` doesn't affect the UI rendering and
60+
// this avoids unnecessary re-rendering for components when amount owed changes. This data should ONLY
61+
// be used for `initSplitExpense`
62+
Onyx.connectWithoutView({
63+
key: ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED,
64+
callback: (value) => (amountOwed = value),
65+
});
66+
3867
/**
3968
* Create a draft transaction to set up split expense details for the split expense flow
4069
*/
41-
function initSplitExpense(transaction: OnyxEntry<Transaction>, policy?: OnyxEntry<Policy>): void {
70+
function initSplitExpense(transaction: OnyxEntry<Transaction>, policy: OnyxEntry<Policy>): void {
4271
if (!transaction) {
4372
return;
4473
}
4574

75+
if (!!policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
76+
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
77+
return;
78+
}
79+
4680
const reportID = transaction.reportID ?? String(CONST.DEFAULT_NUMBER_ID);
4781
const originalTransactionID = transaction?.comment?.originalTransactionID;
4882
const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`];

tests/actions/IOUTest/SplitTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,7 +4770,7 @@ describe('initSplitExpense', () => {
47704770
reportID: '456',
47714771
};
47724772

4773-
initSplitExpense(transaction);
4773+
initSplitExpense(transaction, undefined);
47744774
await waitForBatchedUpdates();
47754775

47764776
const draftTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transaction.transactionID}`);
@@ -4795,7 +4795,7 @@ describe('initSplitExpense', () => {
47954795
});
47964796
it('should not initialize split expense for null transaction', async () => {
47974797
const transaction: Transaction | undefined = undefined;
4798-
initSplitExpense(transaction);
4798+
initSplitExpense(transaction, undefined);
47994799
await waitForBatchedUpdates();
48004800

48014801
expect(transaction).toBeFalsy();
@@ -4819,7 +4819,7 @@ describe('initSplitExpense', () => {
48194819
reportID: '456',
48204820
};
48214821

4822-
initSplitExpense(transaction);
4822+
initSplitExpense(transaction, undefined);
48234823
await waitForBatchedUpdates();
48244824

48254825
const draftTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transaction.transactionID}`);

0 commit comments

Comments
 (0)