@@ -6,11 +6,12 @@ import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTop
66import Navigation from '@libs/Navigation/Navigation' ;
77import { rand64 } from '@libs/NumberUtils' ;
88import { getTransactionDetails , isOpenReport } from '@libs/ReportUtils' ;
9+ import { shouldRestrictUserBillableActions } from '@libs/SubscriptionUtils' ;
910import { buildOptimisticTransaction , getChildTransactions , getOriginalTransactionWithSplitInfo , isDistanceRequest } from '@libs/TransactionUtils' ;
1011import CONST from '@src/CONST' ;
1112import ONYXKEYS from '@src/ONYXKEYS' ;
1213import 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' ;
1415import type { Attendee } from '@src/types/onyx/IOU' ;
1516import type { TransactionCustomUnit } from '@src/types/onyx/Transaction' ;
1617import { 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 } ` ] ;
0 commit comments