aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/Subscription.js
blob: fe0925a26b5b7c43cf6e5541eb223aa9635d8cd4 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer, PropTypes as MobxPropTypes } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';

import Form from '../../lib/Form';
import Radio from '../ui/Radio';
import Button from '../ui/Button';
import Loader from '../ui/Loader';

import { required } from '../../helpers/validation-helpers';

const messages = defineMessages({
  submitButtonLabel: {
    id: 'subscription.submit.label',
    defaultMessage: '!!!Support the development of Franz',
  },
  paymentSessionError: {
    id: 'subscription.paymentSessionError',
    defaultMessage: '!!!Could not initialize payment form',
  },
  typeFree: {
    id: 'subscription.type.free',
    defaultMessage: '!!!free',
  },
  typeMonthly: {
    id: 'subscription.type.month',
    defaultMessage: '!!!month',
  },
  typeYearly: {
    id: 'subscription.type.year',
    defaultMessage: '!!!year',
  },
  typeMining: {
    id: 'subscription.type.mining',
    defaultMessage: '!!!Support Franz with processing power',
  },
  includedFeatures: {
    id: 'subscription.includedFeatures',
    defaultMessage: '!!!The Franz Premium Supporter Account includes',
  },
  features: {
    unlimitedServices: {
      id: 'subscription.features.unlimitedServices',
      defaultMessage: '!!!Add unlimited services',
    },
    onpremise: {
      id: 'subscription.features.onpremise',
      defaultMessage: '!!!Add on-premise/hosted services like HipChat',
    },
    customServices: {
      id: 'subscription.features.customServices',
      defaultMessage: '!!!Add your custom services',
    },
    encryptedSync: {
      id: 'subscription.features.encryptedSync',
      defaultMessage: '!!!Encrypted session synchronization',
    },
    vpn: {
      id: 'subscription.features.vpn',
      defaultMessage: '!!!Proxy & VPN support',
    },
    ads: {
      id: 'subscription.features.ads',
      defaultMessage: '!!!No ads, ever!',
    },
    comingSoon: {
      id: 'subscription.features.comingSoon',
      defaultMessage: '!!!coming soon',
    },
  },
  miningHeadline: {
    id: 'subscription.mining.headline',
    defaultMessage: '!!!How does this work?',
  },
  experimental: {
    id: 'subscription.mining.experimental',
    defaultMessage: '!!!experimental',
  },
  miningDetail1: {
    id: 'subscription.mining.line1',
    defaultMessage: '!!!By enabling "Support with processing power", Franz will use about 20-50% of your CPU to mine cryptocurrency Monero which equals approximately € 5/year.',
  },
  miningDetail2: {
    id: 'subscription.mining.line2',
    defaultMessage: '!!!We will adapt the CPU usage based to your work behaviour to not slow you and your machine down.',
  },
  miningDetail3: {
    id: 'subscription.mining.line3',
    defaultMessage: '!!!As long as the miner is active, you will have unlimited access to all the Franz Premium Supporter Features.',
  },
  miningMoreInfo: {
    id: 'subscription.mining.moreInformation',
    defaultMessage: '!!!Get more information about this plan',
  },
});

@observer
export default class SubscriptionForm extends Component {
  static propTypes = {
    plan: MobxPropTypes.objectOrObservableObject.isRequired,
    isLoading: PropTypes.bool.isRequired,
    handlePayment: PropTypes.func.isRequired,
    retryPlanRequest: PropTypes.func.isRequired,
    isCreatingHostedPage: PropTypes.bool.isRequired,
    error: PropTypes.bool.isRequired,
    showSkipOption: PropTypes.bool,
    skipAction: PropTypes.func,
    skipButtonLabel: PropTypes.string,
    hideInfo: PropTypes.bool.isRequired,
    openExternalUrl: PropTypes.func.isRequired,
  };

  static defaultProps ={
    content: '',
    showSkipOption: false,
    skipAction: () => null,
    skipButtonLabel: '',
  }

  static contextTypes = {
    intl: intlShape,
  };

  componentWillMount() {
    this.form = this.prepareForm();
  }

  prepareForm() {
    const { intl } = this.context;

    const form = {
      fields: {
        paymentTier: {
          value: 'year',
          validate: [required],
          options: [{
            value: 'month',
            label: `€ ${Object.hasOwnProperty.call(this.props.plan, 'month')
              ? `${this.props.plan.month.price} / ${intl.formatMessage(messages.typeMonthly)}`
              : 'monthly'}`,
          }, {
            value: 'year',
            label: `€ ${Object.hasOwnProperty.call(this.props.plan, 'year')
              ? `${this.props.plan.year.price} / ${intl.formatMessage(messages.typeYearly)}`
              : 'yearly'}`,
          }, {
            value: 'mining',
            label: intl.formatMessage(messages.typeMining),
          }],
        },
      },
    };

    if (this.props.showSkipOption) {
      form.fields.paymentTier.options.unshift({
        value: 'skip',
        label: `€ 0 / ${intl.formatMessage(messages.typeFree)}`,
      });
    }

    return new Form(form, this.context.intl);
  }

  render() {
    const {
      isLoading,
      isCreatingHostedPage,
      handlePayment,
      retryPlanRequest,
      error,
      showSkipOption,
      skipAction,
      skipButtonLabel,
      hideInfo,
      openExternalUrl,
    } = this.props;
    const { intl } = this.context;

    if (error) {
      return (
        <Button
          label="Reload"
          onClick={retryPlanRequest}
          isLoaded={!isLoading}
        />
      );
    }

    return (
      <Loader loaded={!isLoading}>
        <Radio field={this.form.$('paymentTier')} showLabel={false} className="paymentTiers" />
        {!hideInfo && (
          <div className="subscription__premium-info">
            {this.form.$('paymentTier').value !== 'mining' && (
              <div>
                <p>
                  <strong>{intl.formatMessage(messages.includedFeatures)}</strong>
                </p>
                <div className="subscription">
                  <ul className="subscription__premium-features">
                    <li>{intl.formatMessage(messages.features.onpremise)}</li>
                    <li>
                      {intl.formatMessage(messages.features.encryptedSync)}
                      <span className="badge">{intl.formatMessage(messages.features.comingSoon)}</span>
                    </li>
                    <li>
                      {intl.formatMessage(messages.features.customServices)}
                      <span className="badge">{intl.formatMessage(messages.features.comingSoon)}</span>
                    </li>
                    <li>
                      {intl.formatMessage(messages.features.vpn)}
                      <span className="badge">{intl.formatMessage(messages.features.comingSoon)}</span>
                    </li>
                    <li>
                      {intl.formatMessage(messages.features.ads)}
                    </li>
                  </ul>
                </div>
              </div>
            )}
            {this.form.$('paymentTier').value === 'mining' && (
              <div className="subscription mining-details">
                <p>
                  <strong>{intl.formatMessage(messages.miningHeadline)}</strong>
                  &nbsp;
                  <span className="badge">{intl.formatMessage(messages.experimental)}</span>
                </p>
                <p>{intl.formatMessage(messages.miningDetail1)}</p>
                <p>{intl.formatMessage(messages.miningDetail2)}</p>
                <p>{intl.formatMessage(messages.miningDetail3)}</p>
                <p>
                  <button
                    onClick={() => openExternalUrl({ url: 'http://meetfranz.com/mining' })}
                  >
                    {intl.formatMessage(messages.miningMoreInfo)}
                  </button>
                </p>
              </div>
            )}
          </div>
        )}
        <div>
          {error.code === 'no-payment-session' && (
            <p className="error-message center">{intl.formatMessage(messages.paymentSessionError)}</p>
          )}
        </div>
        {showSkipOption && this.form.$('paymentTier').value === 'skip' ? (
          <Button
            label={skipButtonLabel}
            className="auth__button"
            onClick={skipAction}
          />
        ) : (
          <Button
            label={intl.formatMessage(messages.submitButtonLabel)}
            className="auth__button"
            loaded={!isCreatingHostedPage}
            onClick={() => handlePayment(this.form.$('paymentTier').value)}
          />
        )}
      </Loader>
    );
  }
}