From 70dbca67e72d2011db720194eaa3cb2f2211bd23 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 3 Jul 2018 09:27:59 -0400 Subject: [PATCH] move premium component to it's own route --- src/app/app-routing.module.ts | 4 +- src/app/settings/premium.component.html | 5 ++- src/app/settings/premium.component.ts | 23 +++++++++--- src/app/settings/settings.component.html | 5 ++- src/app/settings/settings.component.ts | 39 +++++++++++++++++++- src/app/settings/user-billing.component.html | 5 +-- src/app/settings/user-billing.component.ts | 13 +++++-- 7 files changed, 77 insertions(+), 17 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a512963d1d..4d85e85855 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -18,6 +18,7 @@ import { AccountComponent } from './settings/account.component'; import { CreateOrganizationComponent } from './settings/create-organization.component'; import { DomainRulesComponent } from './settings/domain-rules.component'; import { OptionsComponent } from './settings/options.component'; +import { PremiumComponent } from './settings/premium.component'; import { SettingsComponent } from './settings/settings.component'; import { TwoFactorSetupComponent } from './settings/two-factor-setup.component'; import { UserBillingComponent } from './settings/user-billing.component'; @@ -60,10 +61,11 @@ const routes: Routes = [ { path: 'options', component: OptionsComponent, canActivate: [AuthGuardService] }, { path: 'domain-rules', component: DomainRulesComponent, canActivate: [AuthGuardService] }, { path: 'two-factor', component: TwoFactorSetupComponent, canActivate: [AuthGuardService] }, + { path: 'premium', component: PremiumComponent, canActivate: [AuthGuardService] }, { path: 'billing', component: UserBillingComponent, canActivate: [AuthGuardService] }, { path: 'create-organization', - component: CreateOrganizationComponent, + component: CreateOrganizationComponent, canActivate: [AuthGuardService], }, ], diff --git a/src/app/settings/premium.component.html b/src/app/settings/premium.component.html index 1cdd64dfc0..2c1ffc641e 100644 --- a/src/app/settings/premium.component.html +++ b/src/app/settings/premium.component.html @@ -1,4 +1,7 @@ - + +

{{'premiumSignUpAndGet' | i18n}}

  • diff --git a/src/app/settings/premium.component.ts b/src/app/settings/premium.component.ts index 966abbb46a..7a8cd0834a 100644 --- a/src/app/settings/premium.component.ts +++ b/src/app/settings/premium.component.ts @@ -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 { diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 6107194790..03c1943d84 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -13,9 +13,12 @@ Organizations - + {{'billingAndLicensing' | i18n}} + + {{'goPremium' | i18n}} + {{'twoStepLogin' | i18n}} diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index 3c4405ad4a..68b398f78b 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -1,9 +1,46 @@ import { Component, + NgZone, + OnDestroy, + OnInit, } from '@angular/core'; +import { TokenService } from 'jslib/abstractions/token.service'; + +import { BroadcasterService } from 'jslib/angular/services/broadcaster.service'; + +const BroadcasterSubscriptionId = 'SettingsComponent'; + @Component({ selector: 'app-settings', templateUrl: 'settings.component.html', }) -export class SettingsComponent { } +export class SettingsComponent implements OnInit, OnDestroy { + premium: boolean; + + constructor(private tokenService: TokenService, private broadcasterService: BroadcasterService, + private ngZone: NgZone) { } + + async ngOnInit() { + this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => { + this.ngZone.run(async () => { + switch (message.command) { + case 'purchasedPremium': + await this.load(); + break; + default: + } + }); + }); + + await this.load(); + } + + ngOnDestroy() { + this.broadcasterService.unsubscribe(BroadcasterSubscriptionId); + } + + async load() { + this.premium = await this.tokenService.getPremium(); + } +} diff --git a/src/app/settings/user-billing.component.html b/src/app/settings/user-billing.component.html index 601e8292e0..ad104f82a2 100644 --- a/src/app/settings/user-billing.component.html +++ b/src/app/settings/user-billing.component.html @@ -6,9 +6,8 @@ - - - + + {{'subscriptionCanceled' | i18n}}

    {{'subscriptionPendingCanceled' | i18n}}

    diff --git a/src/app/settings/user-billing.component.ts b/src/app/settings/user-billing.component.ts index 8f998c2133..09520516e9 100644 --- a/src/app/settings/user-billing.component.ts +++ b/src/app/settings/user-billing.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit, } from '@angular/core'; +import { Router } from '@angular/router'; import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; @@ -20,7 +21,6 @@ import { PaymentMethodType } from 'jslib/enums/paymentMethodType'; templateUrl: 'user-billing.component.html', }) export class UserBillingComponent implements OnInit { - premium = false; loading = false; firstLoaded = false; adjustStorageAdd = true; @@ -36,7 +36,8 @@ export class UserBillingComponent implements OnInit { constructor(private tokenService: TokenService, private apiService: ApiService, private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private analytics: Angulartics2, private toasterService: ToasterService) { + private analytics: Angulartics2, private toasterService: ToasterService, + private router: Router) { this.selfHosted = platformUtilsService.isSelfHost(); } @@ -50,11 +51,15 @@ export class UserBillingComponent implements OnInit { return; } - this.premium = this.tokenService.getPremium(); - if (this.premium) { + const premium = this.tokenService.getPremium(); + if (premium) { this.loading = true; this.billing = await this.apiService.getUserBilling(); + } else { + this.router.navigate(['/settings/premium']); + return; } + this.loading = false; }