From 58cda9cc7fb79ca9df6746de7f9662bc08dc156a Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 13 Oct 2017 12:29:40 +0200 Subject: initial commit --- src/containers/ui/SubscriptionFormScreen.js | 126 +++++++++++++++++++++++++++ src/containers/ui/SubscriptionPopupScreen.js | 43 +++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/containers/ui/SubscriptionFormScreen.js create mode 100644 src/containers/ui/SubscriptionPopupScreen.js (limited to 'src/containers/ui') diff --git a/src/containers/ui/SubscriptionFormScreen.js b/src/containers/ui/SubscriptionFormScreen.js new file mode 100644 index 000000000..d08507809 --- /dev/null +++ b/src/containers/ui/SubscriptionFormScreen.js @@ -0,0 +1,126 @@ +import { remote } from 'electron'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { inject, observer } from 'mobx-react'; + +import PaymentStore from '../../stores/PaymentStore'; + +import SubscriptionForm from '../../components/ui/Subscription'; + +const { BrowserWindow } = remote; + +@inject('stores', 'actions') @observer +export default class SubscriptionFormScreen extends Component { + static propTypes = { + onCloseWindow: PropTypes.func, + content: PropTypes.oneOrManyChildElements, + showSkipOption: PropTypes.bool, + skipAction: PropTypes.func, + skipButtonLabel: PropTypes.string, + hideInfo: PropTypes.bool, + } + + static defaultProps = { + onCloseWindow: () => null, + content: '', + showSkipOption: false, + skipAction: () => null, + skipButtonLabel: '', + hideInfo: false, + } + + async handlePayment(plan) { + const { + actions, + stores, + onCloseWindow, + skipAction, + } = this.props; + + if (plan !== 'mining') { + const interval = plan; + + const { id } = stores.payment.plan[interval]; + actions.payment.createHostedPage({ + planId: id, + }); + + const hostedPage = await stores.payment.createHostedPageRequest; + const url = `file://${__dirname}/../../index.html#/payment/${encodeURIComponent(hostedPage.url)}`; + + if (hostedPage.url) { + const paymentWindow = new BrowserWindow({ + parent: remote.getCurrentWindow(), + modal: true, + title: '🔒 Franz Supporter License', + width: 600, + height: window.innerHeight - 100, + maxWidth: 600, + minWidth: 600, + webPreferences: { + nodeIntegration: true, + }, + }); + paymentWindow.loadURL(url); + + paymentWindow.on('closed', () => { + onCloseWindow(); + }); + } + } else { + actions.user.update({ + userData: { + isMiner: true, + }, + }); + + skipAction(); + } + } + + render() { + const { + content, + actions, + stores, + showSkipOption, + skipAction, + skipButtonLabel, + hideInfo, + } = this.props; + return ( + stores.payment.plansRequest.reload()} + isCreatingHostedPage={stores.payment.createHostedPageRequest.isExecuting} + handlePayment={price => this.handlePayment(price)} + content={content} + error={stores.payment.plansRequest.isError} + showSkipOption={showSkipOption} + skipAction={skipAction} + skipButtonLabel={skipButtonLabel} + hideInfo={hideInfo} + openExternalUrl={actions.app.openExternalUrl} + /> + ); + } +} + +SubscriptionFormScreen.wrappedComponent.propTypes = { + actions: PropTypes.shape({ + app: PropTypes.shape({ + openExternalUrl: PropTypes.func.isRequired, + }).isRequired, + payment: PropTypes.shape({ + createHostedPage: PropTypes.func.isRequired, + }).isRequired, + user: PropTypes.shape({ + update: PropTypes.func.isRequired, + }).isRequired, + }).isRequired, + stores: PropTypes.shape({ + payment: PropTypes.instanceOf(PaymentStore).isRequired, + }).isRequired, +}; diff --git a/src/containers/ui/SubscriptionPopupScreen.js b/src/containers/ui/SubscriptionPopupScreen.js new file mode 100644 index 000000000..d17477b1d --- /dev/null +++ b/src/containers/ui/SubscriptionPopupScreen.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { inject, observer } from 'mobx-react'; + +import SubscriptionPopup from '../../components/ui/SubscriptionPopup'; + + +@inject('stores', 'actions') @observer +export default class SubscriptionPopupScreen extends Component { + state = { + complete: false, + }; + + completeCheck(event) { + const { url } = event; + + if (url.includes('recurly') && url.includes('confirmation')) { + this.setState({ + complete: true, + }); + } + } + + render() { + return ( + window.close()} + completeCheck={e => this.completeCheck(e)} + isCompleted={this.state.complete} + /> + ); + } +} + + +SubscriptionPopupScreen.wrappedComponent.propTypes = { + router: PropTypes.shape({ + params: PropTypes.shape({ + url: PropTypes.string.isRequired, + }).isRequired, + }).isRequired, +}; -- cgit v1.2.3-70-g09d2