1
0
mirror of https://github.com/bitwarden/web synced 2025-12-15 07:43:16 +00:00

move premium component to it's own route

This commit is contained in:
Kyle Spearrin
2018-07-03 09:27:59 -04:00
parent 16c3d4c253
commit 70dbca67e7
7 changed files with 77 additions and 17 deletions

View File

@@ -1,16 +1,18 @@
import {
Component,
EventEmitter,
Output,
OnInit,
ViewChild,
} from '@angular/core';
import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { TokenService } from 'jslib/abstractions/token.service';
import { PaymentComponent } from './payment.component';
@@ -18,9 +20,8 @@ import { PaymentComponent } from './payment.component';
selector: 'app-premium',
templateUrl: 'premium.component.html',
})
export class PremiumComponent {
export class PremiumComponent implements OnInit {
@ViewChild(PaymentComponent) paymentComponent: PaymentComponent;
@Output() onPremiumPurchased = new EventEmitter();
selfHosted = false;
premiumPrice = 10;
@@ -31,10 +32,19 @@ export class PremiumComponent {
constructor(private apiService: ApiService, private i18nService: I18nService,
private analytics: Angulartics2, private toasterService: ToasterService,
platformUtilsService: PlatformUtilsService) {
platformUtilsService: PlatformUtilsService, private tokenService: TokenService,
private router: Router, private messagingService: MessagingService) {
this.selfHosted = platformUtilsService.isSelfHost();
}
async ngOnInit() {
const premium = await this.tokenService.getPremium();
if (premium) {
this.router.navigate(['/settings/billing']);
return;
}
}
async submit() {
try {
this.formPromise = this.paymentComponent.createPaymentToken().then((token) => {
@@ -53,7 +63,8 @@ export class PremiumComponent {
await this.apiService.refreshIdentityToken();
this.analytics.eventTrack.next({ action: 'Signed Up Premium' });
this.toasterService.popAsync('success', null, this.i18nService.t('premiumUpdated'));
this.onPremiumPurchased.emit();
this.messagingService.send('purchasedPremium');
this.router.navigate(['/settings/billing']);
}
get additionalStorageTotal(): number {