aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/trialStatusBar/components/TrialStatusBar.js
blob: b8fe4acc9986c6f3e987294b6bb72f38e2597b31 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import injectSheet from 'react-jss';
import { defineMessages, intlShape } from 'react-intl';
import { Icon } from '@meetfranz/ui';
import { mdiArrowRight, mdiWindowClose } from '@mdi/js';
import classnames from 'classnames';

import ProgressBar from './ProgressBar';

const messages = defineMessages({
  restTime: {
    id: 'feature.trialStatusBar.restTime',
    defaultMessage: '!!!Your Free Franz {plan} Trial ends in {time}.',
  },
  expired: {
    id: 'feature.trialStatusBar.expired',
    defaultMessage: '!!!Your free Franz {plan} Trial has expired, please upgrade your account.',
  },
  cta: {
    id: 'feature.trialStatusBar.cta',
    defaultMessage: '!!!Upgrade now',
  },
});

const styles = theme => ({
  root: {
    background: theme.trialStatusBar.bar.background,
    width: '100%',
    height: 25,
    order: 10,
    display: 'flex',
    alignItems: 'center',
    fontSize: 12,
    padding: [0, 10],
    justifyContent: 'flex-end',
  },
  ended: {
    background: theme.styleTypes.warning.accent,
    color: theme.styleTypes.warning.contrast,
  },
  message: {
    marginLeft: 20,
  },
  action: {
    marginLeft: 20,
    fontSize: 12,
    color: theme.colorText,
    textDecoration: 'underline',
    display: 'flex',

    '& svg': {
      margin: [1, 2, 0, 0],
    },
  },
});

@injectSheet(styles) @observer
class TrialStatusBar extends Component {
  static propTypes = {
    planName: PropTypes.string.isRequired,
    percent: PropTypes.number.isRequired,
    upgradeAccount: PropTypes.func.isRequired,
    hideOverlay: PropTypes.func.isRequired,
    trialEnd: PropTypes.string.isRequired,
    hasEnded: PropTypes.bool.isRequired,
    classes: PropTypes.object.isRequired,
  };

  static contextTypes = {
    intl: intlShape,
  };

  render() {
    const {
      planName,
      percent,
      upgradeAccount,
      hideOverlay,
      trialEnd,
      hasEnded,
      classes,
    } = this.props;

    const { intl } = this.context;

    return (
      <div
        className={classnames({
          [classes.root]: true,
          [classes.ended]: hasEnded,
        })}
      >
        <ProgressBar
          percent={percent}
        />
        {' '}
        <span className={classes.message}>
          {!hasEnded ? (
            intl.formatMessage(messages.restTime, {
              plan: planName,
              time: trialEnd,
            })
          ) : (
            intl.formatMessage(messages.expired, {
              plan: planName,
            })
          )}
        </span>
        <button
          className={classes.action}
          type="button"
          onClick={() => {
            upgradeAccount();
          }}
        >
          <Icon icon={mdiArrowRight} />
          {intl.formatMessage(messages.cta)}
        </button>
        <button
          className={classes.action}
          type="button"
          onClick={() => {
            hideOverlay();
          }}
        >
          <Icon icon={mdiWindowClose} />
        </button>
      </div>
    );
  }
}

export default TrialStatusBar;