diff options
Diffstat (limited to 'src/containers/subscription/SubscriptionFormScreen.js')
-rw-r--r-- | src/containers/subscription/SubscriptionFormScreen.js | 99 |
1 files changed, 26 insertions, 73 deletions
diff --git a/src/containers/subscription/SubscriptionFormScreen.js b/src/containers/subscription/SubscriptionFormScreen.js index 3d153b8e8..726b10628 100644 --- a/src/containers/subscription/SubscriptionFormScreen.js +++ b/src/containers/subscription/SubscriptionFormScreen.js | |||
@@ -1,4 +1,3 @@ | |||
1 | import { remote } from 'electron'; | ||
2 | import React, { Component } from 'react'; | 1 | import React, { Component } from 'react'; |
3 | import PropTypes from 'prop-types'; | 2 | import PropTypes from 'prop-types'; |
4 | import { inject, observer } from 'mobx-react'; | 3 | import { inject, observer } from 'mobx-react'; |
@@ -6,96 +5,50 @@ import { inject, observer } from 'mobx-react'; | |||
6 | import PaymentStore from '../../stores/PaymentStore'; | 5 | import PaymentStore from '../../stores/PaymentStore'; |
7 | 6 | ||
8 | import SubscriptionForm from '../../components/subscription/SubscriptionForm'; | 7 | import SubscriptionForm from '../../components/subscription/SubscriptionForm'; |
9 | 8 | import TrialForm from '../../components/subscription/TrialForm'; | |
10 | const { BrowserWindow } = remote; | ||
11 | 9 | ||
12 | export default @inject('stores', 'actions') @observer class SubscriptionFormScreen extends Component { | 10 | export default @inject('stores', 'actions') @observer class SubscriptionFormScreen extends Component { |
13 | static propTypes = { | 11 | async openBrowser() { |
14 | onCloseWindow: PropTypes.func, | ||
15 | content: PropTypes.node, | ||
16 | showSkipOption: PropTypes.bool, | ||
17 | skipAction: PropTypes.func, | ||
18 | skipButtonLabel: PropTypes.string, | ||
19 | hideInfo: PropTypes.bool, | ||
20 | } | ||
21 | |||
22 | static defaultProps = { | ||
23 | onCloseWindow: () => null, | ||
24 | content: '', | ||
25 | showSkipOption: false, | ||
26 | skipAction: () => null, | ||
27 | skipButtonLabel: '', | ||
28 | hideInfo: false, | ||
29 | } | ||
30 | |||
31 | async handlePayment(plan) { | ||
32 | const { | 12 | const { |
33 | actions, | 13 | actions, |
34 | stores, | 14 | stores, |
35 | onCloseWindow, | ||
36 | } = this.props; | 15 | } = this.props; |
37 | 16 | ||
38 | const interval = plan; | 17 | const { |
39 | 18 | user, | |
40 | const { id } = stores.payment.plan[interval]; | 19 | features, |
41 | actions.payment.createHostedPage({ | 20 | } = stores; |
42 | planId: id, | ||
43 | }); | ||
44 | |||
45 | const hostedPage = await stores.payment.createHostedPageRequest; | ||
46 | 21 | ||
47 | if (hostedPage.url) { | 22 | let hostedPageURL = features.features.planSelectionURL; |
48 | if (hostedPage.legacyCheckoutFlow) { | 23 | hostedPageURL = user.getAuthURL(hostedPageURL); |
49 | const paymentWindow = new BrowserWindow({ | ||
50 | parent: remote.getCurrentWindow(), | ||
51 | modal: true, | ||
52 | title: '🔒 Ferdi Supporter License', | ||
53 | width: 600, | ||
54 | height: window.innerHeight - 100, | ||
55 | maxWidth: 600, | ||
56 | minWidth: 600, | ||
57 | webPreferences: { | ||
58 | nodeIntegration: true, | ||
59 | webviewTag: true, | ||
60 | }, | ||
61 | }); | ||
62 | paymentWindow.loadURL(`file://${__dirname}/../../index.html#/payment/${encodeURIComponent(hostedPage.url)}`); | ||
63 | 24 | ||
64 | paymentWindow.on('closed', () => { | 25 | actions.app.openExternalUrl({ url: hostedPageURL }); |
65 | onCloseWindow(); | ||
66 | }); | ||
67 | } else { | ||
68 | actions.app.openExternalUrl({ | ||
69 | url: hostedPage.url, | ||
70 | }); | ||
71 | } | ||
72 | } | ||
73 | } | 26 | } |
74 | 27 | ||
75 | render() { | 28 | render() { |
76 | const { | 29 | const { |
77 | content, | ||
78 | actions, | 30 | actions, |
79 | stores, | 31 | stores, |
80 | showSkipOption, | ||
81 | skipAction, | ||
82 | skipButtonLabel, | ||
83 | hideInfo, | ||
84 | } = this.props; | 32 | } = this.props; |
33 | |||
34 | const { data: user } = stores.user; | ||
35 | |||
36 | if (user.hadSubscription) { | ||
37 | return ( | ||
38 | <SubscriptionForm | ||
39 | plan={stores.payment.plan} | ||
40 | selectPlan={() => this.openBrowser()} | ||
41 | isActivatingTrial={stores.user.activateTrialRequest.isExecuting || stores.user.getUserInfoRequest.isExecuting} | ||
42 | /> | ||
43 | ); | ||
44 | } | ||
45 | |||
85 | return ( | 46 | return ( |
86 | <SubscriptionForm | 47 | <TrialForm |
87 | plan={stores.payment.plan} | 48 | plan={stores.payment.plan} |
88 | isLoading={stores.payment.plansRequest.isExecuting} | 49 | activateTrial={() => actions.user.activateTrial({ planId: stores.features.features.defaultTrialPlan })} |
89 | retryPlanRequest={() => stores.payment.plansRequest.reload()} | 50 | showAllOptions={() => this.openBrowser()} |
90 | isCreatingHostedPage={stores.payment.createHostedPageRequest.isExecuting} | 51 | isActivatingTrial={stores.user.activateTrialRequest.isExecuting || stores.user.getUserInfoRequest.isExecuting} |
91 | handlePayment={price => this.handlePayment(price)} | ||
92 | content={content} | ||
93 | error={stores.payment.plansRequest.isError} | ||
94 | showSkipOption={showSkipOption} | ||
95 | skipAction={skipAction} | ||
96 | skipButtonLabel={skipButtonLabel} | ||
97 | hideInfo={hideInfo} | ||
98 | openExternalUrl={actions.app.openExternalUrl} | ||
99 | /> | 52 | /> |
100 | ); | 53 | ); |
101 | } | 54 | } |