Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ function BaseFloatingCameraButton({icon}: BaseFloatingCameraButtonProps) {

const onPress = () => {
interceptAnonymousUser(() => {
if (
policyChatForActivePolicy?.policyID &&
shouldRestrictUserBillableActions(policyChatForActivePolicy.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy, accountID)
) {
if (policyChatForActivePolicy?.policyID && shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policyChatForActivePolicy.policyID));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
if (!reportId) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -61,7 +61,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
if (!reportId) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -73,7 +73,7 @@ function SearchMoneyRequestReportEmptyState({report, policy, onLayout}: {report:
text: translate('iou.addUnreportedExpense'),
icon: icons.ReceiptPlus,
onSelected: () => {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, accountID)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down
20 changes: 2 additions & 18 deletions src/components/Navigation/QuickCreationActionsBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,30 +177,14 @@ function QuickCreationActionsBar() {

if (
!workspaceIDForReportCreation ||
(shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
defaultChatEnabledPolicy,
currentUserPersonalDetails.accountID,
) &&
(shouldRestrictUserBillableActions(defaultChatEnabledPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID) &&
groupPoliciesWithChatEnabled.length > 1)
) {
Navigation.navigate(ROUTES.NEW_REPORT_WORKSPACE_SELECTION.getRoute());
return;
}

if (
!shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
defaultChatEnabledPolicy,
currentUserPersonalDetails.accountID,
)
) {
if (!shouldRestrictUserBillableActions(defaultChatEnabledPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID)) {
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
openCreateReportConfirmation();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@ function SearchActionsBarCreateButton() {
if (
!workspaceIDForReportCreation ||
(shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
defaultChatEnabledPolicy,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
undefined,
currentUserPersonalDetails.accountID,
) &&
groupPoliciesWithChatEnabled.length > 1)
Expand All @@ -203,11 +202,10 @@ function SearchActionsBarCreateButton() {
// Default workspace is not restricted → create report directly
if (
!shouldRestrictUserBillableActions(
workspaceIDForReportCreation,
defaultChatEnabledPolicy,
ownerBillingGracePeriodEnd,
userBillingGracePeriodEnds,
amountOwed,
undefined,
currentUserPersonalDetails.accountID,
)
) {
Expand Down Expand Up @@ -240,6 +238,7 @@ function SearchActionsBarCreateButton() {
handleCreateWorkspaceReport,
amountOwed,
currentUserPersonalDetails.accountID,
defaultChatEnabledPolicy,
],
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function SettlementButton({
return true;
}

if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy, currentUserAccountID)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useExpenseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
if (!moneyRequestReport?.reportID) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReceiptScanDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function useReceiptScanDrop() {
if (
isPaidGroupPolicy(activePolicy) &&
activePolicy?.isPolicyExpenseChatEnabled &&
!shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy, currentUserPersonalDetails.accountID)
!shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID)
) {
const shouldAutoReport = !!activePolicy?.autoReporting || !!personalPolicy?.autoReporting;
const report = shouldAutoReport ? getPolicyExpenseChat(currentUserPersonalDetails.accountID, activePolicy?.id) : selfDMReport;
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ function getRestrictedPolicyID(
.map((item) => item.policyID)
.find(
(policyID): policyID is string =>
!!policyID &&
shouldRestrictUserBillableActions(policyID, ownerBillingGracePeriodEnd, billingGracePeriods, amountOwed, allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]),
!!policyID && shouldRestrictUserBillableActions(allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`], ownerBillingGracePeriodEnd, billingGracePeriods, amountOwed),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/PaymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
ownerBillingGracePeriodEnd,
delegateEmail,
} = params;
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down
12 changes: 4 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1040 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1045,7 +1045,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1048 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1063,7 +1063,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1066 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1075,7 +1075,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1078 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1083,7 +1083,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1086 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1093,7 +1093,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1096 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1101,7 +1101,7 @@

let deprecatedAllReports: OnyxCollection<Report>;
let deprecatedReportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1104 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1137,14 +1137,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1140 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1147 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -3019,11 +3019,7 @@
if (!iouReportID) {
return;
}
if (
policy &&
policy.type !== CONST.POLICY.TYPE.PERSONAL &&
shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)
) {
if (policy && policy.type !== CONST.POLICY.TYPE.PERSONAL && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -3039,7 +3035,7 @@
if (!iouReportID) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -3052,7 +3048,7 @@
icon: icons.ReceiptPlus,
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.ADD_EXPENSE_UNREPORTED,
onSelected: () => {
if (policy && shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down Expand Up @@ -11499,7 +11495,7 @@
}

if (actionName === CONST.IOU.ACTION.CATEGORIZE) {
if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, activePolicy)) {
if (activePolicy && shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ function doesUserHavePaymentCardAdded(userBillingFundID: number | undefined): bo
* Whether the user's billable actions should be restricted.
*/
function shouldRestrictUserBillableActions(
policyID: string,
policyIDOrPolicy: string | OnyxEntry<Policy>,
ownerBillingGracePeriodEnd: OnyxEntry<number>,
userBillingGracePeriodEnds: OnyxCollection<BillingGraceEndPeriod>,
amountOwed: OnyxEntry<number>,
policy: OnyxEntry<Policy> = deprecatedAllPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
currentUserAccountID: number = deprecatedCurrentUserAccountID,
): boolean {
const policy = typeof policyIDOrPolicy === 'string' ? deprecatedAllPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyIDOrPolicy}`] : policyIDOrPolicy;
const currentDate = new Date();

// This logic will be executed if the user is a workspace's non-owner (normal user or admin).
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/ReportWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
return;
}

if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, expenseReportPolicy)) {
if (expenseReport.policyID && shouldRestrictUserBillableActions(expenseReportPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Comment thread
truph01 marked this conversation as resolved.
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(expenseReport.policyID));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/shouldUseDefaultExpensePolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function shouldUseDefaultExpensePolicy(
iouType === CONST.IOU.TYPE.CREATE &&
isPaidGroupPolicy(defaultExpensePolicy) &&
defaultExpensePolicy?.isPolicyExpenseChatEnabled &&
!shouldRestrictUserBillableActions(defaultExpensePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultExpensePolicy)
!shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/AddUnreportedExpense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
{
buttonText: translate('iou.createExpense'),
buttonAction: () => {
if (report?.policyID && shouldRestrictUserBillableActions(report.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)) {
if (report?.policyID && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(report.policyID));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/PaymentUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('PaymentUtils', () => {

selectPaymentType(params);

expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicyID, 999, params.userBillingGracePeriodEnds, 42, testPolicy);
expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicy, 999, params.userBillingGracePeriodEnds, 42);
});

it('should trigger KYC flow for EXPENSIFY payment type when user is validated', () => {
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('PaymentUtils', () => {

selectPaymentType(params);

expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicyID, undefined, params.userBillingGracePeriodEnds, undefined, testPolicy);
expect(mockShouldRestrict).toHaveBeenCalledWith(testPolicy, undefined, params.userBillingGracePeriodEnds, undefined);
});
});

Expand Down
Loading
Loading