1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { inject, observer } from 'mobx-react';
import { RouterStore } from 'mobx-react-router';
import Pricing from '../../components/auth/Pricing';
import UserStore from '../../stores/UserStore';
import { globalError as globalErrorPropType } from '../../prop-types';
export default @inject('stores', 'actions') @observer class PricingScreen extends Component {
static propTypes = {
error: globalErrorPropType.isRequired,
};
async submit() {
const {
actions,
stores,
} = this.props;
const { activateTrialRequest } = stores.user;
const { defaultTrialPlan, canSkipTrial } = stores.features.anonymousFeatures;
if (!canSkipTrial) {
stores.router.push('/');
stores.user.hasCompletedSignup = true;
} else {
actions.user.activateTrial({ planId: defaultTrialPlan });
await activateTrialRequest._promise;
if (!activateTrialRequest.isError) {
stores.router.push('/');
stores.user.hasCompletedSignup = true;
}
}
}
render() {
const {
error,
stores,
} = this.props;
const { getUserInfoRequest, activateTrialRequest, data } = stores.user;
const { featuresRequest, features } = stores.features;
const { pricingConfig } = features;
let currency = '$';
let price = 5.99;
if (pricingConfig) {
({ currency } = pricingConfig);
({ price } = pricingConfig.plans.pro.yearly);
}
return (
<Pricing
onSubmit={this.submit.bind(this)}
isLoadingRequiredData={(getUserInfoRequest.isExecuting || !getUserInfoRequest.wasExecuted) || (featuresRequest.isExecuting || !featuresRequest.wasExecuted)}
isActivatingTrial={activateTrialRequest.isExecuting}
trialActivationError={activateTrialRequest.isError}
canSkipTrial={features.canSkipTrial}
error={error}
currency={currency}
price={price}
name={data.firstname}
/>
);
}
}
PricingScreen.wrappedComponent.propTypes = {
actions: PropTypes.shape({
user: PropTypes.shape({
activateTrial: PropTypes.func.isRequired,
}).isRequired,
}).isRequired,
stores: PropTypes.shape({
user: PropTypes.instanceOf(UserStore).isRequired,
router: PropTypes.instanceOf(RouterStore).isRequired,
}).isRequired,
};
|