aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers/plan-helpers.js
blob: b474f8bbd67faaeedec1d15647fb51e5a53a255f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { defineMessages } from 'react-intl';
import { PLANS_MAPPING, PLANS } from '../config';

const messages = defineMessages({
  [PLANS.PRO]: {
    id: 'pricing.plan.pro',
    defaultMessage: '!!!Professional',
  },
  [PLANS.PERSONAL]: {
    id: 'pricing.plan.personal',
    defaultMessage: '!!!Personal',
  },
  [PLANS.FREE]: {
    id: 'pricing.plan.free',
    defaultMessage: '!!!Free',
  },
  [PLANS.LEGACY]: {
    id: 'pricing.plan.legacy',
    defaultMessage: '!!!Premium',
  },
});

export function cleanupPlanId(id) {
  return id.replace(/(.*)-x[0-9]/, '$1');
}

export function i18nPlanName(planId, intl) {
  if (!planId) {
    throw new Error('planId is required');
  }

  if (!intl) {
    throw new Error('intl context is required');
  }

  const id = cleanupPlanId(planId);

  const plan = PLANS_MAPPING[id];

  return intl.formatMessage(messages[plan]);
}

export function getPlan(planId) {
  if (!planId) {
    throw new Error('planId is required');
  }

  const id = cleanupPlanId(planId);

  const plan = PLANS_MAPPING[id];

  return plan;
}