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
4 changes: 2 additions & 2 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
};

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;
Expand All @@ -61,7 +61,7 @@
});

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 @@ -494,8 +494,8 @@
return false;
}

function shouldCalculateBillNewDot(canDowngrade: boolean | undefined, policies: OnyxCollection<Policy>): boolean {
return (canDowngrade ?? false) && getOwnedPaidPolicies(policies, deprecatedCurrentUserAccountID).length === 1;
function shouldCalculateBillNewDot(currentUserAccountID: number, canDowngrade: boolean | undefined, policies: OnyxCollection<Policy>): boolean {
return (canDowngrade ?? false) && getOwnedPaidPolicies(policies, currentUserAccountID).length === 1;
}

function getSubscriptionPrice(
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
return;
}

if (shouldCalculateBillNewDot(canDowngrade, policies)) {
if (shouldCalculateBillNewDot(currentUserPersonalDetails.accountID, canDowngrade, policies)) {
setIsDeletingPaidWorkspace(true);
calculateBillNewDot();
return;
Expand Down Expand Up @@ -460,7 +460,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
onSelected: onDeleteWorkspace,
disabled: isLoadingBill,
shouldShowLoadingSpinnerIcon: isLoadingBill,
shouldCloseModalOnSelect: !shouldCalculateBillNewDot(account?.canDowngrade, policies) || wouldBlockDeletion,
shouldCloseModalOnSelect: !shouldCalculateBillNewDot(currentUserPersonalDetails.accountID, account?.canDowngrade, policies) || wouldBlockDeletion,
});
}
const isCurrentUserAdmin = policy?.employeeList?.[currentUserPersonalDetails?.login ?? '']?.role === CONST.POLICY.ROLE.ADMIN;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function WorkspacesListPage() {
return translate('common.leaveWorkspaceConfirmation');
};

const shouldCalculateBillNewDot: boolean = shouldCalculateBillNewDotFn(account?.canDowngrade, policies);
const shouldCalculateBillNewDot: boolean = shouldCalculateBillNewDotFn(currentUserPersonalDetails.accountID, account?.canDowngrade, policies);

const resetLoadingSpinnerIconIndex = () => {
setLoadingSpinnerIconIndex(null);
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/SubscriptionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,9 @@ describe('SubscriptionUtils', () => {
},
};
// Test with canDowngrade as false (explicitly)
expect(shouldCalculateBillNewDot(false, policies)).toBeFalsy();
expect(shouldCalculateBillNewDot(testUserAccountID, false, policies)).toBeFalsy();
// Test with canDowngrade as undefined (defaults to false in the function signature)
expect(shouldCalculateBillNewDot(undefined, policies)).toBeFalsy();
expect(shouldCalculateBillNewDot(testUserAccountID, undefined, policies)).toBeFalsy();
});

it('should return false if the user owns zero paid policies', () => {
Expand All @@ -1291,7 +1291,7 @@ describe('SubscriptionUtils', () => {
type: CONST.POLICY.TYPE.PERSONAL,
},
};
expect(shouldCalculateBillNewDot(true, policies)).toBeFalsy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeFalsy();
});

it('should return false if the user owns more than one paid policy', () => {
Expand All @@ -1307,7 +1307,7 @@ describe('SubscriptionUtils', () => {
type: CONST.POLICY.TYPE.TEAM,
},
};
expect(shouldCalculateBillNewDot(true, policies)).toBeFalsy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeFalsy();
});

it('should return true if canDowngrade is true and the user owns exactly one paid policy', () => {
Expand All @@ -1324,7 +1324,7 @@ describe('SubscriptionUtils', () => {
type: CONST.POLICY.TYPE.PERSONAL,
},
};
expect(shouldCalculateBillNewDot(true, policies)).toBeTruthy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeTruthy();
});

it('should return false if the user owns exactly one paid policy but is not the owner', () => {
Expand All @@ -1337,7 +1337,7 @@ describe('SubscriptionUtils', () => {
type: CONST.POLICY.TYPE.CORPORATE,
},
};
expect(shouldCalculateBillNewDot(true, policies)).toBeFalsy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeFalsy();
});

it('should return true if canDowngrade is true and the single paid policy is a team policy', () => {
Expand All @@ -1348,7 +1348,7 @@ describe('SubscriptionUtils', () => {
type: CONST.POLICY.TYPE.TEAM,
},
};
expect(shouldCalculateBillNewDot(true, policies)).toBeTruthy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeTruthy();
});

it('should return true if canDowngrade is true and the single paid policy is a corporate policy', () => {
Expand All @@ -1359,11 +1359,11 @@ describe('SubscriptionUtils', () => {
type: CONST.POLICY.TYPE.CORPORATE,
},
};
expect(shouldCalculateBillNewDot(true, policies)).toBeTruthy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeTruthy();
});

it('should return false when empty policies collection is passed', () => {
expect(shouldCalculateBillNewDot(true, {})).toBeFalsy();
expect(shouldCalculateBillNewDot(testUserAccountID, true, {})).toBeFalsy();
});
});

Expand Down
Loading