From 95cd9153c9ede6bbecc2b65634ef30505be67558 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 13 Apr 2018 13:19:14 -0400 Subject: [PATCH] move premium page to jslib --- src/angular/components/premium.component.ts | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/angular/components/premium.component.ts diff --git a/src/angular/components/premium.component.ts b/src/angular/components/premium.component.ts new file mode 100644 index 0000000000..fb90fa50f2 --- /dev/null +++ b/src/angular/components/premium.component.ts @@ -0,0 +1,50 @@ +import { OnInit } from '@angular/core'; + +import { ToasterService } from 'angular2-toaster'; +import { Angulartics2 } from 'angulartics2'; + +import { ApiService } from '../../abstractions/api.service'; +import { I18nService } from '../../abstractions/i18n.service'; +import { PlatformUtilsService } from '../../abstractions/platformUtils.service'; +import { TokenService } from '../../abstractions/token.service'; + +export class PremiumComponent implements OnInit { + isPremium: boolean = false; + price: string = '$10'; + refreshPromise: Promise; + + constructor(protected analytics: Angulartics2, protected toasterService: ToasterService, + protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, + protected tokenService: TokenService, protected apiService: ApiService) { } + + async ngOnInit() { + this.isPremium = this.tokenService.getPremium(); + } + + async refresh() { + try { + this.refreshPromise = this.apiService.refreshIdentityToken(); + await this.refreshPromise; + this.toasterService.popAsync('success', null, this.i18nService.t('refreshComplete')); + this.isPremium = this.tokenService.getPremium(); + } catch { } + } + + async purchase() { + const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('premiumPurchaseAlert'), + this.i18nService.t('premiumPurchase'), this.i18nService.t('yes'), this.i18nService.t('cancel')); + if (confirmed) { + this.analytics.eventTrack.next({ action: 'Clicked Purchase Premium' }); + this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=purchase'); + } + } + + async manage() { + const confirmed = await this.platformUtilsService.showDialog(this.i18nService.t('premiumManageAlert'), + this.i18nService.t('premiumManage'), this.i18nService.t('yes'), this.i18nService.t('cancel')); + if (confirmed) { + this.analytics.eventTrack.next({ action: 'Clicked Manage Membership' }); + this.platformUtilsService.launchUri('https://vault.bitwarden.com/#/?premium=manage'); + } + } +}