aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/planSelection/containers/PlanSelectionScreen.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/planSelection/containers/PlanSelectionScreen.js')
-rw-r--r--src/features/planSelection/containers/PlanSelectionScreen.js123
1 files changed, 123 insertions, 0 deletions
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 @@
1import React, { Component } from 'react';
2import { observer, inject } from 'mobx-react';
3import PropTypes from 'prop-types';
4import { remote } from 'electron';
5import { defineMessages, intlShape } from 'react-intl';
6
7import FeaturesStore from '../../../stores/FeaturesStore';
8import UserStore from '../../../stores/UserStore';
9import PlanSelection from '../components/PlanSelection';
10import ErrorBoundary from '../../../components/util/ErrorBoundary';
11import { planSelectionStore } from '..';
12
13const { dialog, app } = remote;
14
15const 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
35class 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
104export default PlanSelectionScreen;
105
106PlanSelectionScreen.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};