|
| 1 | +import { SubscriptionState } from './subscription'; |
| 2 | + |
| 3 | +export interface Promo { |
| 4 | + readonly key: string; |
| 5 | + readonly states?: SubscriptionState[]; |
| 6 | + readonly expiresOn?: number; |
| 7 | + readonly startsOn?: number; |
| 8 | + |
| 9 | + readonly code?: string; |
| 10 | + readonly title?: string; |
| 11 | + readonly description?: string; |
| 12 | + readonly descriptionCTA?: string; |
| 13 | + readonly descriptionIntro?: string; |
| 14 | + readonly url?: string; |
| 15 | + readonly command?: string; |
| 16 | +} |
| 17 | + |
| 18 | +// Must be ordered by applicable order |
| 19 | +const promos: Promo[] = [ |
| 20 | + { |
| 21 | + key: 'devex-days', |
| 22 | + expiresOn: new Date('2024-09-05T06:59:00.000Z').getTime(), |
| 23 | + states: [ |
| 24 | + SubscriptionState.FreePlusInTrial, |
| 25 | + SubscriptionState.FreePlusTrialExpired, |
| 26 | + SubscriptionState.FreePlusTrialReactivationEligible, |
| 27 | + ], |
| 28 | + code: 'DEVEXDAYS24', |
| 29 | + description: 'Save up to 80% on GitLens Pro - lowest price of the year!', |
| 30 | + descriptionIntro: 'Sale', |
| 31 | + }, |
| 32 | + |
| 33 | + { |
| 34 | + key: 'pro50', |
| 35 | + states: [ |
| 36 | + SubscriptionState.Free, |
| 37 | + SubscriptionState.FreeInPreviewTrial, |
| 38 | + SubscriptionState.FreePlusInTrial, |
| 39 | + SubscriptionState.FreePlusTrialExpired, |
| 40 | + SubscriptionState.FreePlusTrialReactivationEligible, |
| 41 | + ], |
| 42 | + description: '1st seat of Pro is now 50%+ off.', |
| 43 | + descriptionCTA: 'See your special price.', |
| 44 | + }, |
| 45 | +]; |
| 46 | + |
| 47 | +export function getApplicablePromo(state: number): Promo | undefined { |
| 48 | + const now = Date.now(); |
| 49 | + for (const promo of promos) { |
| 50 | + if ( |
| 51 | + (promo.states == null || promo.states.includes(state)) && |
| 52 | + (promo.expiresOn == null || promo.expiresOn > now) && |
| 53 | + (promo.startsOn == null || promo.startsOn < now) |
| 54 | + ) { |
| 55 | + return promo; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + return undefined; |
| 60 | +} |
0 commit comments