|
1 | 1 | import { SubscriptionPlanId } from '../../constants.subscription';
|
2 | 2 | import type { Organization } from './account/organization';
|
3 | 3 | import type { Subscription } from './account/subscription';
|
4 |
| -import { getSubscriptionPlan, getSubscriptionPlanPriority } from './account/subscription'; |
| 4 | +import { |
| 5 | + computeSubscriptionState, |
| 6 | + getSubscriptionPlan, |
| 7 | + getSubscriptionPlanPriority, |
| 8 | + SubscriptionPlanId, |
| 9 | + SubscriptionState, |
| 10 | +} from './account/subscription'; |
5 | 11 |
|
6 | 12 | export type GKLicenses = Partial<Record<GKLicenseType, GKLicense>>;
|
7 | 13 |
|
@@ -69,9 +75,7 @@ export function getSubscriptionFromCheckIn(
|
69 | 75 |
|
70 | 76 | let effectiveLicenses = Object.entries(data.licenses.effectiveLicenses) as [GKLicenseType, GKLicense][];
|
71 | 77 | let paidLicenses = Object.entries(data.licenses.paidLicenses) as [GKLicenseType, GKLicense][];
|
72 |
| - paidLicenses = paidLicenses.filter( |
73 |
| - license => license[1].latestStatus !== 'expired' && license[1].latestStatus !== 'cancelled', |
74 |
| - ); |
| 78 | + paidLicenses = paidLicenses.filter(license => license[1].latestStatus !== 'cancelled'); |
75 | 79 | if (paidLicenses.length > 1) {
|
76 | 80 | paidLicenses.sort(
|
77 | 81 | (a, b) =>
|
@@ -179,7 +183,18 @@ export function getSubscriptionFromCheckIn(
|
179 | 183 | );
|
180 | 184 | }
|
181 | 185 |
|
182 |
| - if (effective == null || getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id)) { |
| 186 | + const isActualLicenseExpired = |
| 187 | + computeSubscriptionState({ |
| 188 | + plan: { |
| 189 | + actual: actual, |
| 190 | + effective: actual, |
| 191 | + }, |
| 192 | + account: account, |
| 193 | + }) === SubscriptionState.PaidExpired; |
| 194 | + if ( |
| 195 | + effective == null || |
| 196 | + (getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id) && !isActualLicenseExpired) |
| 197 | + ) { |
183 | 198 | effective = { ...actual };
|
184 | 199 | }
|
185 | 200 |
|
|
0 commit comments