Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"typecheck-tsgo": "tsgo --project tsconfig.tsgo.json",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=314 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=313 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"lint-watch": "npx eslint-watch --watch --changed",
"shellcheck": "./scripts/shellCheck.sh",
Expand Down
6 changes: 4 additions & 2 deletions src/components/Navigation/QuickCreationActionsBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function QuickCreationActionsBar() {
const [activePolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const [primaryLogin] = useOnyx(ONYXKEYS.ACCOUNT, {selector: primaryLoginSelector});
const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS);

Expand Down Expand Up @@ -176,14 +177,14 @@ function QuickCreationActionsBar() {

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

if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, undefined, defaultChatEnabledPolicy)) {
if (!shouldRestrictUserBillableActions(workspaceIDForReportCreation, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultChatEnabledPolicy)) {
if (shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy) {
openCreateReportConfirmation();
} else {
Expand All @@ -201,6 +202,7 @@ function QuickCreationActionsBar() {
defaultChatEnabledPolicyID,
userBillingGracePeriodEnds,
ownerBillingGracePeriodEnd,
amountOwed,
defaultChatEnabledPolicy,
groupPoliciesWithChatEnabled.length,
shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function ExpenseReportListItem<TItem extends ListItem>({

const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);

const handleOnButtonPress = useCallback(() => {
handleActionButtonPress({
Expand All @@ -144,6 +145,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
ownerBillingGracePeriodEnd,
amountOwed,
});
}, [
currentSearchHash,
Expand All @@ -158,6 +160,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
isDelegateAccessRestricted,
showDelegateNoAccessModal,
ownerBillingGracePeriodEnd,
amountOwed,
]);

const handleCheckboxPress = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ function ReportListItemHeader<TItem extends ListItem>({
}, [snapshot, reportItem.policyID]);
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const avatarBorderColor =
StyleUtils.getItemBackgroundColorStyle(!!reportItem.isSelected, !!isFocused || !!isHovered, !!isDisabled, theme.activeComponentBG, theme.hoverComponentBG)?.backgroundColor ??
theme.highlightBG;
Expand All @@ -239,6 +240,7 @@ function ReportListItemHeader<TItem extends ListItem>({
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
ownerBillingGracePeriodEnd,
amountOwed,
});
};
return !isLargeScreenWidth ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function TransactionListItem<TItem extends ListItem>({
// Use active policy (user's current workspace) as fallback for self DM tracking expenses
// This matches MoneyRequestView's approach via usePolicyForMovingExpenses()
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);

// Use report's policyID as fallback when transaction doesn't have policyID directly
// Use active policy as final fallback for SelfDM (tracking expenses)
Expand Down Expand Up @@ -181,6 +182,7 @@ function TransactionListItem<TItem extends ListItem>({
onDelegateAccessRestricted: showDelegateNoAccessModal,
personalPolicyID,
ownerBillingGracePeriodEnd,
amountOwed,
onUndelete: () => onUndelete?.(transactionItem),
});
};
Expand Down
8 changes: 1 addition & 7 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,15 @@
};

let deprecatedCurrentUserAccountID = -1;
Onyx.connect({

Check warning on line 56 in src/libs/SubscriptionUtils.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) => {
deprecatedCurrentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
},
});

let privateAmountOwed: OnyxEntry<number>;
Onyx.connect({
key: ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED,
callback: (value) => (privateAmountOwed = value),
});

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

Check warning on line 64 in src/libs/SubscriptionUtils.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,
callback: (value) => (deprecatedAllPolicies = value),
waitForCollectionCallback: true,
Expand Down Expand Up @@ -463,7 +457,7 @@
policyID: string,
ownerBillingGracePeriodEnd: OnyxEntry<number>,
userBillingGracePeriodEnds: OnyxCollection<BillingGraceEndPeriod>,
amountOwed: OnyxEntry<number> = privateAmountOwed,
amountOwed: OnyxEntry<number>,
policy: OnyxEntry<Policy> = deprecatedAllPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
): boolean {
const currentDate = new Date();
Expand Down
8 changes: 5 additions & 3 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type HandleActionButtonPressParams = {
onDelegateAccessRestricted?: () => void;
personalPolicyID: string | undefined;
ownerBillingGracePeriodEnd: OnyxEntry<number>;
amountOwed: OnyxEntry<number>;
onUndelete?: () => void;
};

Expand Down Expand Up @@ -143,6 +144,7 @@ function handleActionButtonPress({
onDelegateAccessRestricted,
personalPolicyID,
ownerBillingGracePeriodEnd,
amountOwed,
onUndelete,
}: HandleActionButtonPressParams) {
// The transactionIDList is needed to handle actions taken on `status:""` where transactions on single expense reports can be approved/paid.
Expand All @@ -161,7 +163,7 @@ function handleActionButtonPress({
onDelegateAccessRestricted?.();
return;
}
if (snapshotReport.policyID && shouldRestrictUserBillableActions(snapshotReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds)) {
if (snapshotReport.policyID && shouldRestrictUserBillableActions(snapshotReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(snapshotReport.policyID));
return;
}
Expand All @@ -172,14 +174,14 @@ function handleActionButtonPress({
onDelegateAccessRestricted?.();
return;
}
if (snapshotReport.policyID && shouldRestrictUserBillableActions(snapshotReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds)) {
if (snapshotReport.policyID && shouldRestrictUserBillableActions(snapshotReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(snapshotReport.policyID));
return;
}
approveMoneyRequestOnSearch(hash, item.reportID ? [item.reportID] : [], currentSearchKey);
return;
case CONST.SEARCH.ACTION_TYPES.SUBMIT: {
if (snapshotReport.policyID && shouldRestrictUserBillableActions(snapshotReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds)) {
if (snapshotReport.policyID && shouldRestrictUserBillableActions(snapshotReport.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(snapshotReport.policyID));
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/AddUnreportedExpense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const shouldShowUnreportedTransactionsSkeletons = isLoadingUnreportedTransactions && hasMoreUnreportedTransactionsResults && !isOffline;
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const isInLandscapeMode = useIsInLandscapeMode();
Expand Down Expand Up @@ -303,7 +304,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
if (
report &&
report.policyID &&
shouldRestrictUserBillableActions(report.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, undefined, policy)
shouldRestrictUserBillableActions(report.policyID, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, policy)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(report.policyID));
return;
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ReportChangeWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro
const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [userBillingGracePeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const filteredReportActions = useAllPolicyExpenseChatReportActions();

const selectPolicy = useCallback(
Expand All @@ -84,7 +85,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro
if (!policyID || !policy) {
return;
}
if (shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriods)) {
if (shouldRestrictUserBillableActions(policy.id, ownerBillingGracePeriodEnd, userBillingGracePeriods, amountOwed)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down Expand Up @@ -131,6 +132,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro
policies,
userBillingGracePeriods,
ownerBillingGracePeriodEnd,
amountOwed,
route.params,
reportID,
report,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15901,7 +15901,7 @@ describe('ReportUtils', () => {
policy: testPolicy,
userBillingGracePeriodEnds: undefined,
draftTransactionIDs: undefined,
amountOwed: undefined,
amountOwed: 100,
ownerBillingGracePeriodEnd: gracePeriodEnd,
});
options.at(2)?.onSelected?.();
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Search/handleActionButtonPressTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ describe('handleActionButtonPress', () => {
lastPaymentMethod: mockLastPaymentMethod,
personalPolicyID: undefined,
ownerBillingGracePeriodEnd: undefined,
amountOwed: undefined,
userBillingGracePeriodEnds: undefined,
});
expect(goToItem).toHaveBeenCalledTimes(1);
Expand All @@ -342,6 +343,7 @@ describe('handleActionButtonPress', () => {
lastPaymentMethod: mockLastPaymentMethod,
personalPolicyID: undefined,
ownerBillingGracePeriodEnd: undefined,
amountOwed: undefined,
userBillingGracePeriodEnds: undefined,
});
expect(goToItem).toHaveBeenCalledTimes(0);
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/SubscriptionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ describe('SubscriptionUtils', () => {
});

it("should return false if the user isn't a workspace's owner or isn't a member of any past due billing workspace", () => {
expect(shouldRestrictUserBillableActions('1', undefined, undefined)).toBeFalsy();
expect(shouldRestrictUserBillableActions('1', undefined, undefined, undefined)).toBeFalsy();
});

it('should return false if the user is a non-owner of a workspace that is not in the shared NVP collection', () => {
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 0, policy)).toBeFalsy();
});

it("should return true if the user is the workspace's owner that is past due billing and is owning some amount", async () => {
Expand All @@ -367,7 +367,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeTruthy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy();
});

it("should return false if the user is past due billing but is not the workspace's owner", async () => {
Expand All @@ -380,7 +380,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy();
});

it('should restrict when ownerBillingGracePeriodEnd is passed directly as 3rd param and is past due', async () => {
Expand All @@ -393,7 +393,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeTruthy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy();
});

it("should return false if the user is past due billing but is not the workspace's owner (2nd check)", async () => {
Expand All @@ -406,7 +406,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy();
});

it('should restrict when ownerBillingGracePeriodEnd is passed directly as 4th param and is past due', async () => {
Expand All @@ -419,7 +419,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeTruthy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy();
});

it('should not restrict when ownerBillingGracePeriodEnd is passed directly as 4th param but is not past due', async () => {
Expand All @@ -432,7 +432,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy();
});

it('should not restrict when ownerBillingGracePeriodEnd is passed directly as 4th param but amount owed is 0', async () => {
Expand All @@ -445,7 +445,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 0, policy)).toBeFalsy();
});

it('should restrict when amountOwed is passed directly and is greater than 0', async () => {
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, policy)).toBeTruthy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, policy)).toBeTruthy();
});

it('should not restrict when policy is passed directly but owner is not past due', async () => {
Expand All @@ -525,7 +525,7 @@ describe('SubscriptionUtils', () => {
[ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 8010,
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, undefined, policy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(addDays(new Date(), 3)), undefined, 8010, policy)).toBeFalsy();
});

it('should not restrict when policy is passed as undefined', () => {
Expand Down Expand Up @@ -597,7 +597,7 @@ describe('SubscriptionUtils', () => {
},
});

expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, undefined, differentOwnerPolicy)).toBeFalsy();
expect(shouldRestrictUserBillableActions(policyID, getUnixTime(subDays(new Date(), 3)), undefined, 8010, differentOwnerPolicy)).toBeFalsy();
});
});

Expand Down
Loading