diff options
Diffstat (limited to 'src/stores/UserStore.js')
-rw-r--r-- | src/stores/UserStore.js | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index b5423af3b..e7516e6e6 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -2,12 +2,14 @@ import { observable, computed, action } from 'mobx'; | |||
2 | import moment from 'moment'; | 2 | import moment from 'moment'; |
3 | import jwt from 'jsonwebtoken'; | 3 | import jwt from 'jsonwebtoken'; |
4 | import localStorage from 'mobx-localstorage'; | 4 | import localStorage from 'mobx-localstorage'; |
5 | import ms from 'ms'; | ||
5 | 6 | ||
6 | import { isDevMode } from '../environment'; | 7 | import { isDevMode } from '../environment'; |
7 | import Store from './lib/Store'; | 8 | import Store from './lib/Store'; |
8 | import Request from './lib/Request'; | 9 | import Request from './lib/Request'; |
9 | import CachedRequest from './lib/CachedRequest'; | 10 | import CachedRequest from './lib/CachedRequest'; |
10 | import { gaEvent } from '../lib/analytics'; | 11 | import { gaEvent } from '../lib/analytics'; |
12 | import { sleep } from '../helpers/async-helpers'; | ||
11 | 13 | ||
12 | const debug = require('debug')('Franz:UserStore'); | 14 | const debug = require('debug')('Franz:UserStore'); |
13 | 15 | ||
@@ -37,6 +39,8 @@ export default class UserStore extends Store { | |||
37 | 39 | ||
38 | @observable passwordRequest = new Request(this.api.user, 'password'); | 40 | @observable passwordRequest = new Request(this.api.user, 'password'); |
39 | 41 | ||
42 | @observable activateTrialRequest = new Request(this.api.user, 'activateTrial'); | ||
43 | |||
40 | @observable inviteRequest = new Request(this.api.user, 'invite'); | 44 | @observable inviteRequest = new Request(this.api.user, 'invite'); |
41 | 45 | ||
42 | @observable getUserInfoRequest = new CachedRequest(this.api.user, 'getInfo'); | 46 | @observable getUserInfoRequest = new CachedRequest(this.api.user, 'getInfo'); |
@@ -57,7 +61,9 @@ export default class UserStore extends Store { | |||
57 | 61 | ||
58 | @observable accountType; | 62 | @observable accountType; |
59 | 63 | ||
60 | @observable hasCompletedSignup = null; | 64 | @observable hasCompletedSignup = false; |
65 | |||
66 | @observable hasActivatedTrial = false; | ||
61 | 67 | ||
62 | @observable userData = {}; | 68 | @observable userData = {}; |
63 | 69 | ||
@@ -77,6 +83,7 @@ export default class UserStore extends Store { | |||
77 | this.actions.user.retrievePassword.listen(this._retrievePassword.bind(this)); | 83 | this.actions.user.retrievePassword.listen(this._retrievePassword.bind(this)); |
78 | this.actions.user.logout.listen(this._logout.bind(this)); | 84 | this.actions.user.logout.listen(this._logout.bind(this)); |
79 | this.actions.user.signup.listen(this._signup.bind(this)); | 85 | this.actions.user.signup.listen(this._signup.bind(this)); |
86 | this.actions.user.activateTrial.listen(this._activateTrial.bind(this)); | ||
80 | this.actions.user.invite.listen(this._invite.bind(this)); | 87 | this.actions.user.invite.listen(this._invite.bind(this)); |
81 | this.actions.user.update.listen(this._update.bind(this)); | 88 | this.actions.user.update.listen(this._update.bind(this)); |
82 | this.actions.user.resetStatus.listen(this._resetStatus.bind(this)); | 89 | this.actions.user.resetStatus.listen(this._resetStatus.bind(this)); |
@@ -87,6 +94,7 @@ export default class UserStore extends Store { | |||
87 | this.registerReactions([ | 94 | this.registerReactions([ |
88 | this._requireAuthenticatedUser, | 95 | this._requireAuthenticatedUser, |
89 | this._getUserData.bind(this), | 96 | this._getUserData.bind(this), |
97 | this._resetTrialActivationState.bind(this), | ||
90 | ]); | 98 | ]); |
91 | } | 99 | } |
92 | 100 | ||
@@ -199,6 +207,26 @@ export default class UserStore extends Store { | |||
199 | gaEvent('User', 'retrievePassword'); | 207 | gaEvent('User', 'retrievePassword'); |
200 | } | 208 | } |
201 | 209 | ||
210 | @action async _activateTrial({ planId }) { | ||
211 | debug('activate trial', planId); | ||
212 | |||
213 | this.activateTrialRequest.execute({ | ||
214 | plan: planId, | ||
215 | }); | ||
216 | |||
217 | await this.activateTrialRequest._promise; | ||
218 | |||
219 | this.hasActivatedTrial = true; | ||
220 | |||
221 | console.log('hasActivatedTrial', this.hasActivatedTrial); | ||
222 | |||
223 | this.stores.features.featuresRequest.invalidate({ immediately: true }); | ||
224 | this.stores.user.getUserInfoRequest.invalidate({ immediately: true }); | ||
225 | |||
226 | |||
227 | gaEvent('User', 'activateTrial'); | ||
228 | } | ||
229 | |||
202 | @action async _invite({ invites }) { | 230 | @action async _invite({ invites }) { |
203 | const data = invites.filter(invite => invite.email !== ''); | 231 | const data = invites.filter(invite => invite.email !== ''); |
204 | 232 | ||
@@ -318,6 +346,16 @@ export default class UserStore extends Store { | |||
318 | } | 346 | } |
319 | } | 347 | } |
320 | 348 | ||
349 | async _resetTrialActivationState() { | ||
350 | if (this.hasActivatedTrial) { | ||
351 | await sleep(ms('12s')); | ||
352 | |||
353 | console.log('resetting this.hasActivatedTrial', this.hasActivatedTrial); | ||
354 | |||
355 | this.hasActivatedTrial = false; | ||
356 | } | ||
357 | } | ||
358 | |||
321 | // Helpers | 359 | // Helpers |
322 | _parseToken(authToken) { | 360 | _parseToken(authToken) { |
323 | try { | 361 | try { |