diff options
Diffstat (limited to 'src/features/planSelection')
-rw-r--r-- | src/features/planSelection/actions.js | 9 | ||||
-rw-r--r-- | src/features/planSelection/api.js | 26 | ||||
-rw-r--r-- | src/features/planSelection/components/PlanItem.js | 207 | ||||
-rw-r--r-- | src/features/planSelection/components/PlanSelection.js | 279 | ||||
-rw-r--r-- | src/features/planSelection/containers/PlanSelectionScreen.js | 123 | ||||
-rw-r--r-- | src/features/planSelection/index.js | 28 | ||||
-rw-r--r-- | src/features/planSelection/store.js | 68 |
7 files changed, 740 insertions, 0 deletions
diff --git a/src/features/planSelection/actions.js b/src/features/planSelection/actions.js new file mode 100644 index 000000000..83f58bfd7 --- /dev/null +++ b/src/features/planSelection/actions.js | |||
@@ -0,0 +1,9 @@ | |||
1 | import PropTypes from 'prop-types'; | ||
2 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; | ||
3 | |||
4 | export const planSelectionActions = createActionsFromDefinitions({ | ||
5 | downgradeAccount: {}, | ||
6 | hideOverlay: {}, | ||
7 | }, PropTypes.checkPropTypes); | ||
8 | |||
9 | export default planSelectionActions; | ||
diff --git a/src/features/planSelection/api.js b/src/features/planSelection/api.js new file mode 100644 index 000000000..734643f10 --- /dev/null +++ b/src/features/planSelection/api.js | |||
@@ -0,0 +1,26 @@ | |||
1 | import { sendAuthRequest } from '../../api/utils/auth'; | ||
2 | import { API, API_VERSION } from '../../environment'; | ||
3 | import Request from '../../stores/lib/Request'; | ||
4 | |||
5 | const debug = require('debug')('Franz:feature:planSelection:api'); | ||
6 | |||
7 | export const planSelectionApi = { | ||
8 | downgrade: async () => { | ||
9 | const url = `${API}/${API_VERSION}/payment/downgrade`; | ||
10 | const options = { | ||
11 | method: 'PUT', | ||
12 | }; | ||
13 | debug('downgrade UPDATE', url, options); | ||
14 | const result = await sendAuthRequest(url, options); | ||
15 | debug('downgrade RESULT', result); | ||
16 | if (!result.ok) throw result; | ||
17 | |||
18 | return result.ok; | ||
19 | }, | ||
20 | }; | ||
21 | |||
22 | export const downgradeUserRequest = new Request(planSelectionApi, 'downgrade'); | ||
23 | |||
24 | export const resetApiRequests = () => { | ||
25 | downgradeUserRequest.reset(); | ||
26 | }; | ||
diff --git a/src/features/planSelection/components/PlanItem.js b/src/features/planSelection/components/PlanItem.js new file mode 100644 index 000000000..ec061377b --- /dev/null +++ b/src/features/planSelection/components/PlanItem.js | |||
@@ -0,0 +1,207 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { defineMessages, intlShape } from 'react-intl'; | ||
5 | import injectSheet from 'react-jss'; | ||
6 | import classnames from 'classnames'; | ||
7 | import color from 'color'; | ||
8 | |||
9 | import { H2 } from '@meetfranz/ui'; | ||
10 | |||
11 | import { Button } from '@meetfranz/forms'; | ||
12 | import { mdiArrowRight } from '@mdi/js'; | ||
13 | |||
14 | const messages = defineMessages({ | ||
15 | perMonth: { | ||
16 | id: 'subscription.interval.perMonth', | ||
17 | defaultMessage: '!!!per month', | ||
18 | }, | ||
19 | perMonthPerUser: { | ||
20 | id: 'subscription.interval.perMonthPerUser', | ||
21 | defaultMessage: '!!!per month & user', | ||
22 | }, | ||
23 | bestValue: { | ||
24 | id: 'subscription.bestValue', | ||
25 | defaultMessage: '!!!Best value', | ||
26 | }, | ||
27 | }); | ||
28 | |||
29 | const styles = theme => ({ | ||
30 | root: { | ||
31 | display: 'flex', | ||
32 | flexDirection: 'column', | ||
33 | borderRadius: theme.borderRadius, | ||
34 | flex: 1, | ||
35 | color: theme.styleTypes.primary.accent, | ||
36 | overflow: 'hidden', | ||
37 | textAlign: 'center', | ||
38 | |||
39 | '& h2': { | ||
40 | textAlign: 'center', | ||
41 | marginBottom: 10, | ||
42 | fontSize: 30, | ||
43 | color: theme.styleTypes.primary.contrast, | ||
44 | }, | ||
45 | }, | ||
46 | currency: { | ||
47 | fontSize: 35, | ||
48 | }, | ||
49 | priceWrapper: { | ||
50 | height: 50, | ||
51 | marginBottom: 0, | ||
52 | }, | ||
53 | price: { | ||
54 | fontSize: 50, | ||
55 | |||
56 | '& sup': { | ||
57 | fontSize: 20, | ||
58 | verticalAlign: 20, | ||
59 | }, | ||
60 | }, | ||
61 | text: { | ||
62 | marginBottom: 'auto', | ||
63 | }, | ||
64 | cta: { | ||
65 | background: theme.styleTypes.primary.accent, | ||
66 | color: theme.styleTypes.primary.contrast, | ||
67 | margin: [40, 'auto', 0, 'auto'], | ||
68 | }, | ||
69 | divider: { | ||
70 | width: 40, | ||
71 | border: 0, | ||
72 | borderTop: [1, 'solid', theme.styleTypes.primary.contrast], | ||
73 | margin: [15, 'auto', 20], | ||
74 | }, | ||
75 | header: { | ||
76 | padding: 20, | ||
77 | background: color(theme.styleTypes.primary.accent).darken(0.25).hex(), | ||
78 | color: theme.styleTypes.primary.contrast, | ||
79 | position: 'relative', | ||
80 | }, | ||
81 | content: { | ||
82 | padding: [10, 20, 20], | ||
83 | background: '#EFEFEF', | ||
84 | }, | ||
85 | simpleCTA: { | ||
86 | background: 'none', | ||
87 | color: theme.styleTypes.primary.accent, | ||
88 | |||
89 | '& svg': { | ||
90 | fill: theme.styleTypes.primary.accent, | ||
91 | }, | ||
92 | }, | ||
93 | bestValue: { | ||
94 | background: theme.styleTypes.success.accent, | ||
95 | color: theme.styleTypes.success.contrast, | ||
96 | right: -66, | ||
97 | top: -40, | ||
98 | height: 'auto', | ||
99 | position: 'absolute', | ||
100 | transform: 'rotateZ(45deg)', | ||
101 | textAlign: 'center', | ||
102 | padding: [5, 50], | ||
103 | transformOrigin: 'left bottom', | ||
104 | fontSize: 12, | ||
105 | boxShadow: '0 2px 6px rgba(0,0,0,0.15)', | ||
106 | }, | ||
107 | }); | ||
108 | |||
109 | |||
110 | export default @observer @injectSheet(styles) class PlanItem extends Component { | ||
111 | static propTypes = { | ||
112 | name: PropTypes.string.isRequired, | ||
113 | text: PropTypes.string.isRequired, | ||
114 | price: PropTypes.number.isRequired, | ||
115 | currency: PropTypes.string.isRequired, | ||
116 | upgrade: PropTypes.func.isRequired, | ||
117 | ctaLabel: PropTypes.string.isRequired, | ||
118 | simpleCTA: PropTypes.bool, | ||
119 | perUser: PropTypes.bool, | ||
120 | classes: PropTypes.object.isRequired, | ||
121 | bestValue: PropTypes.bool, | ||
122 | className: PropTypes.string, | ||
123 | children: PropTypes.element, | ||
124 | }; | ||
125 | |||
126 | static defaultProps = { | ||
127 | simpleCTA: false, | ||
128 | perUser: false, | ||
129 | children: null, | ||
130 | bestValue: false, | ||
131 | className: '', | ||
132 | } | ||
133 | |||
134 | static contextTypes = { | ||
135 | intl: intlShape, | ||
136 | }; | ||
137 | |||
138 | render() { | ||
139 | const { | ||
140 | name, | ||
141 | text, | ||
142 | price, | ||
143 | currency, | ||
144 | classes, | ||
145 | upgrade, | ||
146 | ctaLabel, | ||
147 | simpleCTA, | ||
148 | perUser, | ||
149 | bestValue, | ||
150 | className, | ||
151 | children, | ||
152 | } = this.props; | ||
153 | const { intl } = this.context; | ||
154 | |||
155 | const priceParts = `${price}`.split('.'); | ||
156 | |||
157 | return ( | ||
158 | <div className={classnames({ | ||
159 | [classes.root]: true, | ||
160 | [className]: className, | ||
161 | })} | ||
162 | > | ||
163 | <div className={classes.header}> | ||
164 | {bestValue && ( | ||
165 | <div className={classes.bestValue}> | ||
166 | {intl.formatMessage(messages.bestValue)} | ||
167 | </div> | ||
168 | )} | ||
169 | <H2 className={classes.planName}>{name}</H2> | ||
170 | <p className={classes.text}> | ||
171 | {text} | ||
172 | </p> | ||
173 | <hr className={classes.divider} /> | ||
174 | <p className={classes.priceWrapper}> | ||
175 | <span className={classes.currency}>{currency}</span> | ||
176 | <span className={classes.price}> | ||
177 | {priceParts[0]} | ||
178 | <sup>{priceParts[1]}</sup> | ||
179 | </span> | ||
180 | </p> | ||
181 | <p className={classes.interval}> | ||
182 | {intl.formatMessage(perUser ? messages.perMonthPerUser : messages.perMonth)} | ||
183 | </p> | ||
184 | </div> | ||
185 | |||
186 | <div className={classes.content}> | ||
187 | {children} | ||
188 | |||
189 | <Button | ||
190 | className={classnames({ | ||
191 | [classes.cta]: true, | ||
192 | [classes.simpleCTA]: simpleCTA, | ||
193 | })} | ||
194 | icon={simpleCTA ? mdiArrowRight : null} | ||
195 | label={( | ||
196 | <> | ||
197 | {ctaLabel} | ||
198 | </> | ||
199 | )} | ||
200 | onClick={upgrade} | ||
201 | /> | ||
202 | </div> | ||
203 | |||
204 | </div> | ||
205 | ); | ||
206 | } | ||
207 | } | ||
diff --git a/src/features/planSelection/components/PlanSelection.js b/src/features/planSelection/components/PlanSelection.js new file mode 100644 index 000000000..4bf5238dd --- /dev/null +++ b/src/features/planSelection/components/PlanSelection.js | |||
@@ -0,0 +1,279 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import injectSheet from 'react-jss'; | ||
5 | import { defineMessages, intlShape } from 'react-intl'; | ||
6 | import { H1, H2, Icon } from '@meetfranz/ui'; | ||
7 | import color from 'color'; | ||
8 | |||
9 | import { mdiRocket, mdiArrowRight } from '@mdi/js'; | ||
10 | import PlanItem from './PlanItem'; | ||
11 | import { i18nPlanName } from '../../../helpers/plan-helpers'; | ||
12 | import { PLANS } from '../../../config'; | ||
13 | import { FeatureList } from '../../../components/ui/FeatureList'; | ||
14 | import Appear from '../../../components/ui/effects/Appear'; | ||
15 | |||
16 | const messages = defineMessages({ | ||
17 | welcome: { | ||
18 | id: 'feature.planSelection.fullscreen.welcome', | ||
19 | defaultMessage: '!!!Are you ready to choose, {name}', | ||
20 | }, | ||
21 | subheadline: { | ||
22 | id: 'feature.planSelection.fullscreen.subheadline', | ||
23 | defaultMessage: '!!!It\'s time to make a choice. Franz works best on our Personal and Professional plans. Please have a look and choose the best one for you.', | ||
24 | }, | ||
25 | textFree: { | ||
26 | id: 'feature.planSelection.free.text', | ||
27 | defaultMessage: '!!!Basic functionality', | ||
28 | }, | ||
29 | textPersonal: { | ||
30 | id: 'feature.planSelection.personal.text', | ||
31 | defaultMessage: '!!!More services, no waiting - ideal for personal use.', | ||
32 | }, | ||
33 | textProfessional: { | ||
34 | id: 'feature.planSelection.pro.text', | ||
35 | defaultMessage: '!!!Unlimited services and professional features for you - and your team.', | ||
36 | }, | ||
37 | ctaStayOnFree: { | ||
38 | id: 'feature.planSelection.cta.stayOnFree', | ||
39 | defaultMessage: '!!!Stay on Free', | ||
40 | }, | ||
41 | ctaDowngradeFree: { | ||
42 | id: 'feature.planSelection.cta.ctaDowngradeFree', | ||
43 | defaultMessage: '!!!Downgrade to Free', | ||
44 | }, | ||
45 | actionTrial: { | ||
46 | id: 'feature.planSelection.cta.trial', | ||
47 | defaultMessage: '!!!Start my free 14-days Trial', | ||
48 | }, | ||
49 | shortActionPersonal: { | ||
50 | id: 'feature.planSelection.cta.upgradePersonal', | ||
51 | defaultMessage: '!!!Choose Personal', | ||
52 | }, | ||
53 | shortActionPro: { | ||
54 | id: 'feature.planSelection.cta.upgradePro', | ||
55 | defaultMessage: '!!!Choose Professional', | ||
56 | }, | ||
57 | fullFeatureList: { | ||
58 | id: 'feature.planSelection.fullFeatureList', | ||
59 | defaultMessage: '!!!Complete comparison of all plans', | ||
60 | }, | ||
61 | pricesBasedOnAnnualPayment: { | ||
62 | id: 'feature.planSelection.pricesBasedOnAnnualPayment', | ||
63 | defaultMessage: '!!!All prices based on yearly payment', | ||
64 | }, | ||
65 | }); | ||
66 | |||
67 | const styles = theme => ({ | ||
68 | root: { | ||
69 | background: theme.colorModalOverlayBackground, | ||
70 | width: '100%', | ||
71 | height: '100%', | ||
72 | position: 'absolute', | ||
73 | top: 0, | ||
74 | left: 0, | ||
75 | display: 'flex', | ||
76 | justifyContent: 'center', | ||
77 | alignItems: 'center', | ||
78 | zIndex: 999999, | ||
79 | overflowY: 'scroll', | ||
80 | }, | ||
81 | container: { | ||
82 | width: '80%', | ||
83 | height: 'auto', | ||
84 | background: theme.styleTypes.primary.accent, | ||
85 | padding: 40, | ||
86 | borderRadius: theme.borderRadius, | ||
87 | maxWidth: 1000, | ||
88 | |||
89 | '& h1, & h2': { | ||
90 | textAlign: 'center', | ||
91 | color: theme.styleTypes.primary.contrast, | ||
92 | }, | ||
93 | }, | ||
94 | plans: { | ||
95 | display: 'flex', | ||
96 | margin: [40, 0, 0], | ||
97 | height: 'auto', | ||
98 | |||
99 | '& > div': { | ||
100 | margin: [0, 15], | ||
101 | flex: 1, | ||
102 | height: 'auto', | ||
103 | background: theme.styleTypes.primary.contrast, | ||
104 | boxShadow: [0, 2, 30, color('#000').alpha(0.1).rgb().string()], | ||
105 | }, | ||
106 | }, | ||
107 | bigIcon: { | ||
108 | background: theme.styleTypes.danger.accent, | ||
109 | width: 120, | ||
110 | height: 120, | ||
111 | display: 'flex', | ||
112 | alignItems: 'center', | ||
113 | borderRadius: '100%', | ||
114 | justifyContent: 'center', | ||
115 | margin: [-100, 'auto', 20], | ||
116 | |||
117 | '& svg': { | ||
118 | width: '80px !important', | ||
119 | height: '80px !important', | ||
120 | filter: 'drop-shadow( 0px 2px 3px rgba(0, 0, 0, 0.3))', | ||
121 | fill: theme.styleTypes.danger.contrast, | ||
122 | }, | ||
123 | }, | ||
124 | headline: { | ||
125 | fontSize: 40, | ||
126 | }, | ||
127 | subheadline: { | ||
128 | maxWidth: 660, | ||
129 | fontSize: 22, | ||
130 | lineHeight: 1.1, | ||
131 | margin: [0, 'auto'], | ||
132 | }, | ||
133 | featureList: { | ||
134 | '& li': { | ||
135 | borderBottom: [1, 'solid', '#CECECE'], | ||
136 | }, | ||
137 | }, | ||
138 | footer: { | ||
139 | display: 'flex', | ||
140 | color: theme.styleTypes.primary.contrast, | ||
141 | marginTop: 20, | ||
142 | padding: [0, 15], | ||
143 | }, | ||
144 | fullFeatureList: { | ||
145 | marginRight: 'auto', | ||
146 | textAlign: 'center', | ||
147 | display: 'flex', | ||
148 | justifyContent: 'center', | ||
149 | alignItems: 'center', | ||
150 | color: `${theme.styleTypes.primary.contrast} !important`, | ||
151 | |||
152 | '& svg': { | ||
153 | marginRight: 5, | ||
154 | }, | ||
155 | }, | ||
156 | scrollContainer: { | ||
157 | border: '1px solid red', | ||
158 | overflow: 'scroll-x', | ||
159 | }, | ||
160 | featuredPlan: { | ||
161 | transform: 'scale(1.05)', | ||
162 | }, | ||
163 | disclaimer: { | ||
164 | textAlign: 'right', | ||
165 | margin: [10, 15, 0, 0], | ||
166 | }, | ||
167 | }); | ||
168 | |||
169 | @injectSheet(styles) @observer | ||
170 | class PlanSelection extends Component { | ||
171 | static propTypes = { | ||
172 | classes: PropTypes.object.isRequired, | ||
173 | firstname: PropTypes.string.isRequired, | ||
174 | plans: PropTypes.object.isRequired, | ||
175 | currency: PropTypes.string.isRequired, | ||
176 | subscriptionExpired: PropTypes.bool.isRequired, | ||
177 | upgradeAccount: PropTypes.func.isRequired, | ||
178 | stayOnFree: PropTypes.func.isRequired, | ||
179 | hadSubscription: PropTypes.bool.isRequired, | ||
180 | }; | ||
181 | |||
182 | static contextTypes = { | ||
183 | intl: intlShape, | ||
184 | }; | ||
185 | |||
186 | componentDidMount() { | ||
187 | } | ||
188 | |||
189 | render() { | ||
190 | const { | ||
191 | classes, | ||
192 | firstname, | ||
193 | plans, | ||
194 | currency, | ||
195 | subscriptionExpired, | ||
196 | upgradeAccount, | ||
197 | stayOnFree, | ||
198 | hadSubscription, | ||
199 | } = this.props; | ||
200 | |||
201 | const { intl } = this.context; | ||
202 | |||
203 | return ( | ||
204 | <Appear> | ||
205 | <div | ||
206 | className={classes.root} | ||
207 | > | ||
208 | <div className={classes.container}> | ||
209 | <div className={classes.bigIcon}> | ||
210 | <Icon icon={mdiRocket} /> | ||
211 | </div> | ||
212 | <H1 className={classes.headline}>{intl.formatMessage(messages.welcome, { name: firstname })}</H1> | ||
213 | <H2 className={classes.subheadline}>{intl.formatMessage(messages.subheadline)}</H2> | ||
214 | <div className={classes.plans}> | ||
215 | <PlanItem | ||
216 | name={i18nPlanName(PLANS.FREE, intl)} | ||
217 | text={intl.formatMessage(messages.textFree)} | ||
218 | price={0} | ||
219 | currency={currency} | ||
220 | ctaLabel={intl.formatMessage(subscriptionExpired ? messages.ctaDowngradeFree : messages.ctaStayOnFree)} | ||
221 | upgrade={() => stayOnFree()} | ||
222 | simpleCTA | ||
223 | > | ||
224 | <FeatureList | ||
225 | plan={PLANS.FREE} | ||
226 | className={classes.featureList} | ||
227 | /> | ||
228 | </PlanItem> | ||
229 | <PlanItem | ||
230 | name={i18nPlanName(plans.pro.yearly.id, intl)} | ||
231 | text={intl.formatMessage(messages.textProfessional)} | ||
232 | price={plans.pro.yearly.price} | ||
233 | currency={currency} | ||
234 | ctaLabel={intl.formatMessage(hadSubscription ? messages.shortActionPro : messages.actionTrial)} | ||
235 | upgrade={() => upgradeAccount(plans.pro.yearly.id)} | ||
236 | className={classes.featuredPlan} | ||
237 | perUser | ||
238 | bestValue | ||
239 | > | ||
240 | <FeatureList | ||
241 | plan={PLANS.PRO} | ||
242 | className={classes.featureList} | ||
243 | /> | ||
244 | </PlanItem> | ||
245 | <PlanItem | ||
246 | name={i18nPlanName(plans.personal.yearly.id, intl)} | ||
247 | text={intl.formatMessage(messages.textPersonal)} | ||
248 | price={plans.personal.yearly.price} | ||
249 | currency={currency} | ||
250 | ctaLabel={intl.formatMessage(hadSubscription ? messages.shortActionPersonal : messages.actionTrial)} | ||
251 | upgrade={() => upgradeAccount(plans.personal.yearly.id)} | ||
252 | > | ||
253 | <FeatureList | ||
254 | plan={PLANS.PERSONAL} | ||
255 | className={classes.featureList} | ||
256 | /> | ||
257 | </PlanItem> | ||
258 | </div> | ||
259 | <div className={classes.footer}> | ||
260 | <a | ||
261 | href="https://meetfranz.com/pricing" | ||
262 | target="_blank" | ||
263 | className={classes.fullFeatureList} | ||
264 | > | ||
265 | <Icon icon={mdiArrowRight} /> | ||
266 | {intl.formatMessage(messages.fullFeatureList)} | ||
267 | </a> | ||
268 | {/* <p className={classes.disclaimer}> */} | ||
269 | {intl.formatMessage(messages.pricesBasedOnAnnualPayment)} | ||
270 | {/* </p> */} | ||
271 | </div> | ||
272 | </div> | ||
273 | </div> | ||
274 | </Appear> | ||
275 | ); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | export default PlanSelection; | ||
diff --git a/src/features/planSelection/containers/PlanSelectionScreen.js b/src/features/planSelection/containers/PlanSelectionScreen.js new file mode 100644 index 000000000..d202c924e --- /dev/null +++ b/src/features/planSelection/containers/PlanSelectionScreen.js | |||
@@ -0,0 +1,123 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import { observer, inject } from 'mobx-react'; | ||
3 | import PropTypes from 'prop-types'; | ||
4 | import { remote } from 'electron'; | ||
5 | import { defineMessages, intlShape } from 'react-intl'; | ||
6 | |||
7 | import FeaturesStore from '../../../stores/FeaturesStore'; | ||
8 | import UserStore from '../../../stores/UserStore'; | ||
9 | import PlanSelection from '../components/PlanSelection'; | ||
10 | import ErrorBoundary from '../../../components/util/ErrorBoundary'; | ||
11 | import { planSelectionStore } from '..'; | ||
12 | |||
13 | const { dialog, app } = remote; | ||
14 | |||
15 | const messages = defineMessages({ | ||
16 | dialogTitle: { | ||
17 | id: 'feature.planSelection.fullscreen.dialog.title', | ||
18 | defaultMessage: '!!!Downgrade your Franz Plan', | ||
19 | }, | ||
20 | dialogMessage: { | ||
21 | id: 'feature.planSelection.fullscreen.dialog.message', | ||
22 | defaultMessage: '!!!You\'re about to downgrade to our Free account. Are you sure? Click here instead to get more services and functionality for just {currency}{price} a month.', | ||
23 | }, | ||
24 | dialogCTADowngrade: { | ||
25 | id: 'feature.planSelection.fullscreen.dialog.cta.downgrade', | ||
26 | defaultMessage: '!!!Downgrade to Free', | ||
27 | }, | ||
28 | dialogCTAUpgrade: { | ||
29 | id: 'feature.planSelection.fullscreen.dialog.cta.upgrade', | ||
30 | defaultMessage: '!!!Choose Personal', | ||
31 | }, | ||
32 | }); | ||
33 | |||
34 | @inject('stores', 'actions') @observer | ||
35 | class PlanSelectionScreen extends Component { | ||
36 | static contextTypes = { | ||
37 | intl: intlShape, | ||
38 | }; | ||
39 | |||
40 | upgradeAccount(planId) { | ||
41 | const { upgradeAccount } = this.props.actions.payment; | ||
42 | |||
43 | upgradeAccount({ | ||
44 | planId, | ||
45 | }); | ||
46 | } | ||
47 | |||
48 | render() { | ||
49 | if (!planSelectionStore || !planSelectionStore.isFeatureActive || !planSelectionStore.showPlanSelectionOverlay) { | ||
50 | return null; | ||
51 | } | ||
52 | |||
53 | const { intl } = this.context; | ||
54 | |||
55 | const { user, features } = this.props.stores; | ||
56 | const { plans, currency } = features.features.pricingConfig; | ||
57 | const { activateTrial } = this.props.actions.user; | ||
58 | const { downgradeAccount, hideOverlay } = this.props.actions.planSelection; | ||
59 | |||
60 | return ( | ||
61 | <ErrorBoundary> | ||
62 | <PlanSelection | ||
63 | firstname={user.data.firstname} | ||
64 | plans={plans} | ||
65 | currency={currency} | ||
66 | upgradeAccount={(planId) => { | ||
67 | if (user.data.hadSubscription) { | ||
68 | this.upgradeAccount(planId); | ||
69 | } else { | ||
70 | activateTrial({ | ||
71 | planId, | ||
72 | }); | ||
73 | } | ||
74 | }} | ||
75 | stayOnFree={() => { | ||
76 | const selection = dialog.showMessageBoxSync(app.mainWindow, { | ||
77 | type: 'question', | ||
78 | message: intl.formatMessage(messages.dialogTitle), | ||
79 | detail: intl.formatMessage(messages.dialogMessage, { | ||
80 | currency, | ||
81 | price: plans.personal.yearly.price, | ||
82 | }), | ||
83 | buttons: [ | ||
84 | intl.formatMessage(messages.dialogCTADowngrade), | ||
85 | intl.formatMessage(messages.dialogCTAUpgrade), | ||
86 | ], | ||
87 | }); | ||
88 | |||
89 | if (selection === 0) { | ||
90 | downgradeAccount(); | ||
91 | hideOverlay(); | ||
92 | } else { | ||
93 | this.upgradeAccount(plans.personal.yearly.id); | ||
94 | } | ||
95 | }} | ||
96 | subscriptionExpired={user.team && user.team.state === 'expired' && !user.team.userHasDowngraded} | ||
97 | hadSubscription={user.data.hadSubscription} | ||
98 | /> | ||
99 | </ErrorBoundary> | ||
100 | ); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | export default PlanSelectionScreen; | ||
105 | |||
106 | PlanSelectionScreen.wrappedComponent.propTypes = { | ||
107 | stores: PropTypes.shape({ | ||
108 | features: PropTypes.instanceOf(FeaturesStore).isRequired, | ||
109 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
110 | }).isRequired, | ||
111 | actions: PropTypes.shape({ | ||
112 | payment: PropTypes.shape({ | ||
113 | upgradeAccount: PropTypes.func.isRequired, | ||
114 | }), | ||
115 | planSelection: PropTypes.shape({ | ||
116 | downgradeAccount: PropTypes.func.isRequired, | ||
117 | hideOverlay: PropTypes.func.isRequired, | ||
118 | }), | ||
119 | user: PropTypes.shape({ | ||
120 | activateTrial: PropTypes.func.isRequired, | ||
121 | }), | ||
122 | }).isRequired, | ||
123 | }; | ||
diff --git a/src/features/planSelection/index.js b/src/features/planSelection/index.js new file mode 100644 index 000000000..890be8871 --- /dev/null +++ b/src/features/planSelection/index.js | |||
@@ -0,0 +1,28 @@ | |||
1 | import { reaction } from 'mobx'; | ||
2 | import PlanSelectionStore from './store'; | ||
3 | |||
4 | const debug = require('debug')('Franz:feature:planSelection'); | ||
5 | |||
6 | export const planSelectionStore = new PlanSelectionStore(); | ||
7 | |||
8 | export default function initPlanSelection(stores, actions) { | ||
9 | stores.planSelection = planSelectionStore; | ||
10 | const { features } = stores; | ||
11 | |||
12 | // Toggle planSelection feature | ||
13 | reaction( | ||
14 | () => features.features.isPlanSelectionEnabled, | ||
15 | (isEnabled) => { | ||
16 | if (isEnabled) { | ||
17 | debug('Initializing `planSelection` feature'); | ||
18 | planSelectionStore.start(stores, actions); | ||
19 | } else if (planSelectionStore.isFeatureActive) { | ||
20 | debug('Disabling `planSelection` feature'); | ||
21 | planSelectionStore.stop(); | ||
22 | } | ||
23 | }, | ||
24 | { | ||
25 | fireImmediately: true, | ||
26 | }, | ||
27 | ); | ||
28 | } | ||
diff --git a/src/features/planSelection/store.js b/src/features/planSelection/store.js new file mode 100644 index 000000000..448e323ff --- /dev/null +++ b/src/features/planSelection/store.js | |||
@@ -0,0 +1,68 @@ | |||
1 | import { | ||
2 | action, | ||
3 | observable, | ||
4 | computed, | ||
5 | } from 'mobx'; | ||
6 | |||
7 | import { planSelectionActions } from './actions'; | ||
8 | import { FeatureStore } from '../utils/FeatureStore'; | ||
9 | import { createActionBindings } from '../utils/ActionBinding'; | ||
10 | import { downgradeUserRequest } from './api'; | ||
11 | |||
12 | const debug = require('debug')('Franz:feature:planSelection:store'); | ||
13 | |||
14 | export default class PlanSelectionStore extends FeatureStore { | ||
15 | @observable isFeatureEnabled = false; | ||
16 | |||
17 | @observable isFeatureActive = false; | ||
18 | |||
19 | @observable hideOverlay = false; | ||
20 | |||
21 | @computed get showPlanSelectionOverlay() { | ||
22 | const { team, isPremium } = this.stores.user; | ||
23 | if (team && !this.hideOverlay && !isPremium) { | ||
24 | return team.state === 'expired' && !team.userHasDowngraded; | ||
25 | } | ||
26 | |||
27 | return false; | ||
28 | } | ||
29 | |||
30 | // ========== PUBLIC API ========= // | ||
31 | |||
32 | @action start(stores, actions, api) { | ||
33 | debug('PlanSelectionStore::start'); | ||
34 | this.stores = stores; | ||
35 | this.actions = actions; | ||
36 | this.api = api; | ||
37 | |||
38 | // ACTIONS | ||
39 | |||
40 | this._registerActions(createActionBindings([ | ||
41 | [planSelectionActions.downgradeAccount, this._downgradeAccount], | ||
42 | [planSelectionActions.hideOverlay, this._hideOverlay], | ||
43 | ])); | ||
44 | |||
45 | this.isFeatureActive = true; | ||
46 | } | ||
47 | |||
48 | @action stop() { | ||
49 | super.stop(); | ||
50 | debug('PlanSelectionStore::stop'); | ||
51 | this.isFeatureActive = false; | ||
52 | } | ||
53 | |||
54 | // ========== PRIVATE METHODS ========= // | ||
55 | |||
56 | // Actions | ||
57 | @action _downgradeAccount = () => { | ||
58 | downgradeUserRequest.execute(); | ||
59 | } | ||
60 | |||
61 | @action _hideOverlay = () => { | ||
62 | this.hideOverlay = true; | ||
63 | } | ||
64 | |||
65 | @action _showOverlay = () => { | ||
66 | this.hideOverlay = false; | ||
67 | } | ||
68 | } | ||