aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/UserStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/UserStore.js')
-rw-r--r--src/stores/UserStore.js47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js
index b5423af3b..e23106462 100644
--- a/src/stores/UserStore.js
+++ b/src/stores/UserStore.js
@@ -2,12 +2,14 @@ import { observable, computed, action } from 'mobx';
2import moment from 'moment'; 2import moment from 'moment';
3import jwt from 'jsonwebtoken'; 3import jwt from 'jsonwebtoken';
4import localStorage from 'mobx-localstorage'; 4import localStorage from 'mobx-localstorage';
5import ms from 'ms';
5 6
6import { isDevMode } from '../environment'; 7import { isDevMode, WEBSITE } from '../environment';
7import Store from './lib/Store'; 8import Store from './lib/Store';
8import Request from './lib/Request'; 9import Request from './lib/Request';
9import CachedRequest from './lib/CachedRequest'; 10import CachedRequest from './lib/CachedRequest';
10import { gaEvent } from '../lib/analytics'; 11import { gaEvent } from '../lib/analytics';
12import { sleep } from '../helpers/async-helpers';
11 13
12const debug = require('debug')('Franz:UserStore'); 14const 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,24 @@ 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 this.stores.features.featuresRequest.invalidate({ immediately: true });
222 this.stores.user.getUserInfoRequest.invalidate({ immediately: true });
223
224
225 gaEvent('User', 'activateTrial');
226 }
227
202 @action async _invite({ invites }) { 228 @action async _invite({ invites }) {
203 const data = invites.filter(invite => invite.email !== ''); 229 const data = invites.filter(invite => invite.email !== '');
204 230
@@ -318,6 +344,14 @@ export default class UserStore extends Store {
318 } 344 }
319 } 345 }
320 346
347 async _resetTrialActivationState() {
348 if (this.hasActivatedTrial) {
349 await sleep(ms('12s'));
350
351 this.hasActivatedTrial = false;
352 }
353 }
354
321 // Helpers 355 // Helpers
322 _parseToken(authToken) { 356 _parseToken(authToken) {
323 try { 357 try {
@@ -347,6 +381,15 @@ export default class UserStore extends Store {
347 } 381 }
348 } 382 }
349 383
384 getAuthURL(url) {
385 const parsedUrl = new URL(url);
386 const params = new URLSearchParams(parsedUrl.search.slice(1));
387
388 params.append('authToken', this.authToken);
389
390 return `${parsedUrl.origin}${parsedUrl.pathname}?${params.toString()}`;
391 }
392
350 async _migrateUserLocale() { 393 async _migrateUserLocale() {
351 await this.getUserInfoRequest._promise; 394 await this.getUserInfoRequest._promise;
352 395