aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/ActivateTrialButton/index.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-09-04 15:37:56 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-09-04 15:37:56 +0200
commitc6dda35baf7eb9a7d89bf224c38973a1b6171c14 (patch)
tree98f562911fcccc356a0594427f6891ce0e12f22a /src/components/ui/ActivateTrialButton/index.js
parentFix icons & button color (diff)
downloadferdium-app-c6dda35baf7eb9a7d89bf224c38973a1b6171c14.tar.gz
ferdium-app-c6dda35baf7eb9a7d89bf224c38973a1b6171c14.tar.zst
ferdium-app-c6dda35baf7eb9a7d89bf224c38973a1b6171c14.zip
bugfixing & polishing
Diffstat (limited to 'src/components/ui/ActivateTrialButton/index.js')
-rw-r--r--src/components/ui/ActivateTrialButton/index.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/components/ui/ActivateTrialButton/index.js b/src/components/ui/ActivateTrialButton/index.js
new file mode 100644
index 000000000..c3e5f4a6f
--- /dev/null
+++ b/src/components/ui/ActivateTrialButton/index.js
@@ -0,0 +1,115 @@
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import { inject, observer } from 'mobx-react';
4import { defineMessages, intlShape } from 'react-intl';
5import classnames from 'classnames';
6
7import { Button } from '@meetfranz/forms';
8import { gaEvent } from '../../../lib/analytics';
9
10import UserStore from '../../../stores/UserStore';
11
12const messages = defineMessages({
13 action: {
14 id: 'feature.delayApp.upgrade.action',
15 defaultMessage: '!!!Get a Franz Supporter License',
16 },
17 actionTrial: {
18 id: 'feature.delayApp.trial.action',
19 defaultMessage: '!!!Yes, I want the free 14 day trial of Franz Professional',
20 },
21 shortAction: {
22 id: 'feature.delayApp.upgrade.actionShort',
23 defaultMessage: '!!!Upgrade account',
24 },
25 shortActionTrial: {
26 id: 'feature.delayApp.trial.actionShort',
27 defaultMessage: '!!!Activate the free Franz Professional trial',
28 },
29});
30
31@inject('stores', 'actions') @observer
32class ActivateTrialButton extends Component {
33 static propTypes = {
34 // eslint-disable-next-line
35 classes: PropTypes.object.isRequired,
36 className: PropTypes.string,
37 short: PropTypes.bool,
38 gaEventInfo: PropTypes.shape({
39 category: PropTypes.string.isRequired,
40 event: PropTypes.string.isRequired,
41 label: PropTypes.string,
42 }),
43 };
44
45 static defaultProps = {
46 className: '',
47 short: false,
48 gaEventInfo: null,
49 }
50
51 static contextTypes = {
52 intl: intlShape,
53 };
54
55 handleCTAClick() {
56 const { actions, stores, gaEventInfo } = this.props;
57 const { hadSubscription } = stores.user.data;
58 const { defaultTrialPlan } = stores.features.features;
59
60 let label = '';
61 if (!hadSubscription) {
62 actions.user.activateTrial({ planId: defaultTrialPlan });
63
64 label = 'Start Trial';
65 } else {
66 actions.ui.openSettings({ path: 'user' });
67
68 label = 'Upgrade Account';
69 }
70
71 if (gaEventInfo) {
72 const { category, event } = gaEventInfo;
73 gaEvent(category, event, label);
74 }
75 }
76
77 render() {
78 const { stores, className, short } = this.props;
79 const { intl } = this.context;
80
81 const { hadSubscription } = stores.user.data;
82
83 let label;
84 if (hadSubscription) {
85 label = short ? messages.shortAction : messages.action;
86 } else {
87 label = short ? messages.shortActionTrial : messages.actionTrial;
88 }
89
90 return (
91 <Button
92 label={intl.formatMessage(label)}
93 className={classnames({
94 [className]: className,
95 })}
96 buttonType="inverted"
97 onClick={this.handleCTAClick.bind(this)}
98 busy={stores.user.activateTrialRequest.isExecuting}
99 />
100 );
101 }
102}
103
104export default ActivateTrialButton;
105
106ActivateTrialButton.wrappedComponent.propTypes = {
107 stores: PropTypes.shape({
108 user: PropTypes.instanceOf(UserStore).isRequired,
109 }).isRequired,
110 actions: PropTypes.shape({
111 ui: PropTypes.shape({
112 openSettings: PropTypes.func.isRequired,
113 }).isRequired,
114 }).isRequired,
115};