diff options
author | Stefan Malzner <stefan@adlk.io> | 2019-04-30 15:23:38 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2019-04-30 15:23:38 +0200 |
commit | 1bae1dfcbc4a5f590c51103635006198ae6a91d6 (patch) | |
tree | c838e9e7e18342c01e3c3b46c8e9ca4b74895e3b /src/features/serviceLimit/store.js | |
parent | Update CHANGELOG.md (diff) | |
download | ferdium-app-1bae1dfcbc4a5f590c51103635006198ae6a91d6.tar.gz ferdium-app-1bae1dfcbc4a5f590c51103635006198ae6a91d6.tar.zst ferdium-app-1bae1dfcbc4a5f590c51103635006198ae6a91d6.zip |
Enforce service limit
Diffstat (limited to 'src/features/serviceLimit/store.js')
-rw-r--r-- | src/features/serviceLimit/store.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/features/serviceLimit/store.js b/src/features/serviceLimit/store.js new file mode 100644 index 000000000..752f71371 --- /dev/null +++ b/src/features/serviceLimit/store.js | |||
@@ -0,0 +1,41 @@ | |||
1 | import { computed, observable } from 'mobx'; | ||
2 | import { FeatureStore } from '../utils/FeatureStore'; | ||
3 | import { DEFAULT_SERVICE_LIMIT } from '.'; | ||
4 | |||
5 | const debug = require('debug')('Franz:feature:serviceLimit:store'); | ||
6 | |||
7 | export class ServiceLimitStore extends FeatureStore { | ||
8 | @observable isServiceLimitEnabled = false; | ||
9 | |||
10 | start(stores, actions) { | ||
11 | debug('start'); | ||
12 | this.stores = stores; | ||
13 | this.actions = actions; | ||
14 | |||
15 | this.isServiceLimitEnabled = true; | ||
16 | } | ||
17 | |||
18 | stop() { | ||
19 | super.stop(); | ||
20 | |||
21 | this.isServiceLimitEnabled = false; | ||
22 | } | ||
23 | |||
24 | @computed get userHasReachedServiceLimit() { | ||
25 | if (!this.isServiceLimitEnabled) return false; | ||
26 | |||
27 | const { user } = this.stores; | ||
28 | |||
29 | return !user.isPremium && this.serviceCount >= this.serviceLimit; | ||
30 | } | ||
31 | |||
32 | @computed get serviceLimit() { | ||
33 | return this.stores.features.features.serviceLimitCount || DEFAULT_SERVICE_LIMIT; | ||
34 | } | ||
35 | |||
36 | @computed get serviceCount() { | ||
37 | return this.stores.services.all.length; | ||
38 | } | ||
39 | } | ||
40 | |||
41 | export default ServiceLimitStore; | ||