diff options
author | 2021-08-13 00:45:01 +0530 | |
---|---|---|
committer | 2021-08-13 00:45:01 +0530 | |
commit | 2d27d5e66649d4f5baf127a53ee5ae524eae3a59 (patch) | |
tree | c592ea219ac8cd987fc367f57b54034c450ab2ab /src/features/trialStatusBar/containers/TrialStatusBarScreen.js | |
parent | Ferdi v5.6.0 (diff) | |
parent | 5.6.1-nightly.24 [skip ci] (diff) | |
download | ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.gz ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.zst ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.zip |
chore: merge from nightly branch into release branch in prep for next beta
Diffstat (limited to 'src/features/trialStatusBar/containers/TrialStatusBarScreen.js')
-rw-r--r-- | src/features/trialStatusBar/containers/TrialStatusBarScreen.js | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/src/features/trialStatusBar/containers/TrialStatusBarScreen.js b/src/features/trialStatusBar/containers/TrialStatusBarScreen.js deleted file mode 100644 index e0f5ab5f2..000000000 --- a/src/features/trialStatusBar/containers/TrialStatusBarScreen.js +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import { observer, inject } from 'mobx-react'; | ||
3 | import PropTypes from 'prop-types'; | ||
4 | import ms from 'ms'; | ||
5 | import { intlShape } from 'react-intl'; | ||
6 | |||
7 | import FeaturesStore from '../../../stores/FeaturesStore'; | ||
8 | import UserStore from '../../../stores/UserStore'; | ||
9 | import TrialStatusBar from '../components/TrialStatusBar'; | ||
10 | import ErrorBoundary from '../../../components/util/ErrorBoundary'; | ||
11 | import { trialStatusBarStore } from '..'; | ||
12 | import { i18nPlanName } from '../../../helpers/plan-helpers'; | ||
13 | import PaymentStore from '../../../stores/PaymentStore'; | ||
14 | |||
15 | @inject('stores', 'actions') | ||
16 | @observer | ||
17 | class TrialStatusBarScreen extends Component { | ||
18 | static contextTypes = { | ||
19 | intl: intlShape, | ||
20 | }; | ||
21 | |||
22 | state = { | ||
23 | showOverlay: true, | ||
24 | percent: 0, | ||
25 | restTime: '', | ||
26 | hasEnded: false, | ||
27 | }; | ||
28 | |||
29 | percentInterval = null; | ||
30 | |||
31 | componentDidMount() { | ||
32 | this.percentInterval = setInterval(() => { | ||
33 | this.calculateRestTime(); | ||
34 | }, ms('1m')); | ||
35 | |||
36 | this.calculateRestTime(); | ||
37 | } | ||
38 | |||
39 | componentWillUnmount() { | ||
40 | clearInterval(this.percentInterval); | ||
41 | } | ||
42 | |||
43 | calculateRestTime() { | ||
44 | const { trialEndTime } = trialStatusBarStore; | ||
45 | const percent = ( | ||
46 | Math.abs(100 - Math.abs(trialEndTime.asMilliseconds()) * 100) / ms('14d') | ||
47 | ).toFixed(2); | ||
48 | const restTime = trialEndTime.humanize(); | ||
49 | const hasEnded = trialEndTime.asMilliseconds() > 0; | ||
50 | |||
51 | this.setState({ | ||
52 | percent, | ||
53 | restTime, | ||
54 | hasEnded, | ||
55 | }); | ||
56 | } | ||
57 | |||
58 | hideOverlay() { | ||
59 | this.setState({ | ||
60 | showOverlay: false, | ||
61 | }); | ||
62 | } | ||
63 | |||
64 | render() { | ||
65 | const { intl } = this.context; | ||
66 | |||
67 | const { | ||
68 | showOverlay, percent, restTime, hasEnded, | ||
69 | } = this.state; | ||
70 | |||
71 | if ( | ||
72 | !trialStatusBarStore | ||
73 | || !trialStatusBarStore.isFeatureActive | ||
74 | || !showOverlay | ||
75 | || !trialStatusBarStore.showTrialStatusBarOverlay | ||
76 | ) { | ||
77 | return null; | ||
78 | } | ||
79 | |||
80 | const { user } = this.props.stores; | ||
81 | const { upgradeAccount } = this.props.actions.payment; | ||
82 | |||
83 | const planName = i18nPlanName(user.team.plan, intl); | ||
84 | |||
85 | return ( | ||
86 | <ErrorBoundary> | ||
87 | <TrialStatusBar | ||
88 | planName={planName} | ||
89 | percent={parseFloat(percent < 5 ? 5 : percent)} | ||
90 | trialEnd={restTime} | ||
91 | upgradeAccount={() => upgradeAccount({ | ||
92 | planId: user.team.plan, | ||
93 | })} | ||
94 | hideOverlay={() => this.hideOverlay()} | ||
95 | hasEnded={hasEnded} | ||
96 | /> | ||
97 | </ErrorBoundary> | ||
98 | ); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | export default TrialStatusBarScreen; | ||
103 | |||
104 | TrialStatusBarScreen.wrappedComponent.propTypes = { | ||
105 | stores: PropTypes.shape({ | ||
106 | features: PropTypes.instanceOf(FeaturesStore).isRequired, | ||
107 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
108 | }).isRequired, | ||
109 | actions: PropTypes.shape({ | ||
110 | payment: PropTypes.instanceOf(PaymentStore), | ||
111 | }).isRequired, | ||
112 | }; | ||