Skip to content

Commit f094ea5

Browse files
authored
Merge pull request #87660 from hungvu193/fix-664420-part3
2 parents 42ea881 + a48f2a0 commit f094ea5

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/libs/SubscriptionUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ function shouldRestrictUserBillableActions(
529529
return false;
530530
}
531531

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

536536
function getSubscriptionPrice(

src/pages/workspace/WorkspaceOverviewPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
340340
return;
341341
}
342342

343-
if (shouldCalculateBillNewDot(canDowngrade, policies)) {
343+
if (shouldCalculateBillNewDot(currentUserPersonalDetails.accountID, canDowngrade, policies)) {
344344
setIsDeletingPaidWorkspace(true);
345345
calculateBillNewDot();
346346
return;
@@ -460,7 +460,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
460460
onSelected: onDeleteWorkspace,
461461
disabled: isLoadingBill,
462462
shouldShowLoadingSpinnerIcon: isLoadingBill,
463-
shouldCloseModalOnSelect: !shouldCalculateBillNewDot(account?.canDowngrade, policies) || wouldBlockDeletion,
463+
shouldCloseModalOnSelect: !shouldCalculateBillNewDot(currentUserPersonalDetails.accountID, account?.canDowngrade, policies) || wouldBlockDeletion,
464464
});
465465
}
466466
const isCurrentUserAdmin = policy?.employeeList?.[currentUserPersonalDetails?.login ?? '']?.role === CONST.POLICY.ROLE.ADMIN;

src/pages/workspace/WorkspacesListPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ function WorkspacesListPage() {
307307
return translate('common.leaveWorkspaceConfirmation');
308308
};
309309

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

312312
const resetLoadingSpinnerIconIndex = () => {
313313
setLoadingSpinnerIconIndex(null);

tests/unit/SubscriptionUtilsTest.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,9 @@ describe('SubscriptionUtils', () => {
13481348
},
13491349
};
13501350
// Test with canDowngrade as false (explicitly)
1351-
expect(shouldCalculateBillNewDot(false, policies)).toBeFalsy();
1351+
expect(shouldCalculateBillNewDot(testUserAccountID, false, policies)).toBeFalsy();
13521352
// Test with canDowngrade as undefined (defaults to false in the function signature)
1353-
expect(shouldCalculateBillNewDot(undefined, policies)).toBeFalsy();
1353+
expect(shouldCalculateBillNewDot(testUserAccountID, undefined, policies)).toBeFalsy();
13541354
});
13551355

13561356
it('should return false if the user owns zero paid policies', () => {
@@ -1362,7 +1362,7 @@ describe('SubscriptionUtils', () => {
13621362
type: CONST.POLICY.TYPE.PERSONAL,
13631363
},
13641364
};
1365-
expect(shouldCalculateBillNewDot(true, policies)).toBeFalsy();
1365+
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeFalsy();
13661366
});
13671367

13681368
it('should return false if the user owns more than one paid policy', () => {
@@ -1378,7 +1378,7 @@ describe('SubscriptionUtils', () => {
13781378
type: CONST.POLICY.TYPE.TEAM,
13791379
},
13801380
};
1381-
expect(shouldCalculateBillNewDot(true, policies)).toBeFalsy();
1381+
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeFalsy();
13821382
});
13831383

13841384
it('should return true if canDowngrade is true and the user owns exactly one paid policy', () => {
@@ -1395,7 +1395,7 @@ describe('SubscriptionUtils', () => {
13951395
type: CONST.POLICY.TYPE.PERSONAL,
13961396
},
13971397
};
1398-
expect(shouldCalculateBillNewDot(true, policies)).toBeTruthy();
1398+
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeTruthy();
13991399
});
14001400

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

14141414
it('should return true if canDowngrade is true and the single paid policy is a team policy', () => {
@@ -1419,7 +1419,7 @@ describe('SubscriptionUtils', () => {
14191419
type: CONST.POLICY.TYPE.TEAM,
14201420
},
14211421
};
1422-
expect(shouldCalculateBillNewDot(true, policies)).toBeTruthy();
1422+
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeTruthy();
14231423
});
14241424

14251425
it('should return true if canDowngrade is true and the single paid policy is a corporate policy', () => {
@@ -1430,11 +1430,11 @@ describe('SubscriptionUtils', () => {
14301430
type: CONST.POLICY.TYPE.CORPORATE,
14311431
},
14321432
};
1433-
expect(shouldCalculateBillNewDot(true, policies)).toBeTruthy();
1433+
expect(shouldCalculateBillNewDot(testUserAccountID, true, policies)).toBeTruthy();
14341434
});
14351435

14361436
it('should return false when empty policies collection is passed', () => {
1437-
expect(shouldCalculateBillNewDot(true, {})).toBeFalsy();
1437+
expect(shouldCalculateBillNewDot(testUserAccountID, true, {})).toBeFalsy();
14381438
});
14391439
});
14401440

0 commit comments

Comments
 (0)