aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/planSelection/store.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/planSelection/store.js')
-rw-r--r--src/features/planSelection/store.js113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/features/planSelection/store.js b/src/features/planSelection/store.js
new file mode 100644
index 000000000..50e46dfb3
--- /dev/null
+++ b/src/features/planSelection/store.js
@@ -0,0 +1,113 @@
1import {
2 action,
3 observable,
4 computed,
5} from 'mobx';
6import { remote } from 'electron';
7
8import { planSelectionActions } from './actions';
9import { FeatureStore } from '../utils/FeatureStore';
10// import { createReactions } from '../../stores/lib/Reaction';
11import { createActionBindings } from '../utils/ActionBinding';
12import { downgradeUserRequest } from './api';
13
14const debug = require('debug')('Franz:feature:planSelection:store');
15
16const { BrowserWindow } = remote;
17
18export default class PlanSelectionStore extends FeatureStore {
19 @observable isFeatureEnabled = false;
20
21 @observable isFeatureActive = false;
22
23 @observable hideOverlay = false;
24
25 @computed get showPlanSelectionOverlay() {
26 const { team } = this.stores.user;
27 if (team && !this.hideOverlay) {
28 return team.state === 'expired' && !team.userHasDowngraded;
29 }
30
31 return false;
32 }
33
34 // ========== PUBLIC API ========= //
35
36 @action start(stores, actions, api) {
37 debug('PlanSelectionStore::start');
38 this.stores = stores;
39 this.actions = actions;
40 this.api = api;
41
42 // ACTIONS
43
44 this._registerActions(createActionBindings([
45 [planSelectionActions.upgradeAccount, this._upgradeAccount],
46 [planSelectionActions.downgradeAccount, this._downgradeAccount],
47 [planSelectionActions.hideOverlay, this._hideOverlay],
48 ]));
49
50 // REACTIONS
51
52 // this._allReactions = createReactions([
53 // this._setFeatureEnabledReaction,
54 // this._updateTodosConfig,
55 // this._firstLaunchReaction,
56 // this._routeCheckReaction,
57 // ]);
58
59 // this._registerReactions(this._allReactions);
60
61 this.isFeatureActive = true;
62 }
63
64 @action stop() {
65 super.stop();
66 debug('PlanSelectionStore::stop');
67 this.reset();
68 this.isFeatureActive = false;
69 }
70
71 // ========== PRIVATE METHODS ========= //
72
73 // Actions
74
75 @action _upgradeAccount = ({ planId, onCloseWindow = () => null }) => {
76 let hostedPageURL = this.stores.features.features.subscribeURL;
77
78 const parsedUrl = new URL(hostedPageURL);
79 const params = new URLSearchParams(parsedUrl.search.slice(1));
80
81 params.set('plan', planId);
82
83 hostedPageURL = this.stores.user.getAuthURL(`${parsedUrl.origin}${parsedUrl.pathname}?${params.toString()}`);
84
85 const win = new BrowserWindow({
86 parent: remote.getCurrentWindow(),
87 modal: true,
88 title: '🔒 Upgrade Your Franz Account',
89 width: 800,
90 height: window.innerHeight - 100,
91 maxWidth: 800,
92 minWidth: 600,
93 webPreferences: {
94 nodeIntegration: true,
95 webviewTag: true,
96 },
97 });
98 win.loadURL(`file://${__dirname}/../../index.html#/payment/${encodeURIComponent(hostedPageURL)}`);
99
100 win.on('closed', () => {
101 onCloseWindow();
102 });
103 };
104
105 @action _downgradeAccount = () => {
106 console.log('downgrade to free', downgradeUserRequest);
107 downgradeUserRequest.execute();
108 }
109
110 @action _hideOverlay = () => {
111 this.hideOverlay = true;
112 }
113}