diff options
Diffstat (limited to 'src/components/ui/UpgradeButton/index.js')
-rw-r--r-- | src/components/ui/UpgradeButton/index.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/components/ui/UpgradeButton/index.js b/src/components/ui/UpgradeButton/index.js new file mode 100644 index 000000000..73762f0bf --- /dev/null +++ b/src/components/ui/UpgradeButton/index.js | |||
@@ -0,0 +1,89 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | import { defineMessages, intlShape } from 'react-intl'; | ||
5 | |||
6 | import { Button } from '@meetfranz/forms'; | ||
7 | import { gaEvent } from '../../../lib/analytics'; | ||
8 | |||
9 | import UserStore from '../../../stores/UserStore'; | ||
10 | import ActivateTrialButton from '../ActivateTrialButton'; | ||
11 | |||
12 | const messages = defineMessages({ | ||
13 | upgradeToPro: { | ||
14 | id: 'global.upgradeButton.upgradeToPro', | ||
15 | defaultMessage: '!!!Upgrade to Franz Professional', | ||
16 | }, | ||
17 | }); | ||
18 | |||
19 | @inject('stores', 'actions') @observer | ||
20 | class UpgradeButton extends Component { | ||
21 | static propTypes = { | ||
22 | // eslint-disable-next-line | ||
23 | classes: PropTypes.object.isRequired, | ||
24 | className: PropTypes.string, | ||
25 | gaEventInfo: PropTypes.shape({ | ||
26 | category: PropTypes.string.isRequired, | ||
27 | event: PropTypes.string.isRequired, | ||
28 | label: PropTypes.string, | ||
29 | }), | ||
30 | requiresPro: PropTypes.bool, | ||
31 | }; | ||
32 | |||
33 | static defaultProps = { | ||
34 | className: '', | ||
35 | gaEventInfo: null, | ||
36 | requiresPro: false, | ||
37 | } | ||
38 | |||
39 | static contextTypes = { | ||
40 | intl: intlShape, | ||
41 | }; | ||
42 | |||
43 | handleCTAClick() { | ||
44 | const { actions, gaEventInfo } = this.props; | ||
45 | |||
46 | actions.ui.openSettings({ path: 'user' }); | ||
47 | if (gaEventInfo) { | ||
48 | const { category, event } = gaEventInfo; | ||
49 | gaEvent(category, event, 'Upgrade Account'); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | render() { | ||
54 | const { stores, requiresPro } = this.props; | ||
55 | const { intl } = this.context; | ||
56 | |||
57 | const { isPremium, isPersonal } = stores.user; | ||
58 | |||
59 | if (isPremium && isPersonal && requiresPro) { | ||
60 | return ( | ||
61 | <Button | ||
62 | label={intl.formatMessage(messages.upgradeToPro)} | ||
63 | onClick={this.handleCTAClick.bind(this)} | ||
64 | className={this.props.className} | ||
65 | buttonType="inverted" | ||
66 | /> | ||
67 | ); | ||
68 | } | ||
69 | |||
70 | if (!isPremium) { | ||
71 | return <ActivateTrialButton {...this.props} />; | ||
72 | } | ||
73 | |||
74 | return null; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | export default UpgradeButton; | ||
79 | |||
80 | UpgradeButton.wrappedComponent.propTypes = { | ||
81 | stores: PropTypes.shape({ | ||
82 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
83 | }).isRequired, | ||
84 | actions: PropTypes.shape({ | ||
85 | ui: PropTypes.shape({ | ||
86 | openSettings: PropTypes.func.isRequired, | ||
87 | }).isRequired, | ||
88 | }).isRequired, | ||
89 | }; | ||