index.ts
28 lines
| 1 | export const PLAN_TYPE_FREE = 'free'; |
| 2 | export const PLAN_TYPE_TIERED = 'tiered'; |
| 3 | export const PLAN_TYPE_UNLIMITED = 'unlimited'; |
| 4 | |
| 5 | export type PlanType = typeof PLAN_TYPE_FREE | typeof PLAN_TYPE_TIERED | typeof PLAN_TYPE_UNLIMITED; |
| 6 | |
| 7 | /** |
| 8 | * Simple hook to get the plan type from the current tier |
| 9 | * |
| 10 | * @param {object} currentTier - the current tier from the AI Feature data |
| 11 | * @returns {PlanType} the plan type |
| 12 | */ |
| 13 | export const usePlanType = ( currentTier ): PlanType => { |
| 14 | if ( ! currentTier ) { |
| 15 | return null; |
| 16 | } |
| 17 | |
| 18 | if ( currentTier?.value === 0 ) { |
| 19 | return PLAN_TYPE_FREE; |
| 20 | } |
| 21 | |
| 22 | if ( currentTier?.value === 1 ) { |
| 23 | return PLAN_TYPE_UNLIMITED; |
| 24 | } |
| 25 | |
| 26 | return PLAN_TYPE_TIERED; |
| 27 | }; |
| 28 |