import { AfterViewInit , Component , Injector , OnInit } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; import { accountModuleAnimation } from '@shared/animations/routerTransition' ; import { AppComponentBase } from '@shared/common/app-component-base' ; import { EditionSelectDto , PasswordComplexitySetting , ProfileServiceProxy , RegisterTenantOutput , TenantRegistrationServiceProxy , SubscriptionStartType , PaymentPeriodType , SubscriptionPaymentGatewayType } from '@shared/service-proxies/service-proxies' ; import { RegisterTenantModel } from './register-tenant.model' ; import { TenantRegistrationHelperService } from './tenant-registration-helper.service' ; import { finalize } from 'rxjs/operators' ; @ Component ( { templateUrl : './register-tenant.component.html' } ) export class RegisterTenantComponent extends AppComponentBase implements OnInit , AfterViewInit { model : RegisterTenantModel = new RegisterTenantModel ( ) ; passwordComplexitySetting : PasswordComplexitySetting = new PasswordComplexitySetting ( ) ; subscriptionStartType = SubscriptionStartType ; paymentPeriodType = PaymentPeriodType ; selectedPaymentPeriodType : PaymentPeriodType = PaymentPeriodType . Monthly ; subscriptionPaymentGateway = SubscriptionPaymentGatewayType ; paymentId = '' ; saving = false ; constructor ( injector , private _tenantRegistrationService , private _router , private _profileService , private _tenantRegistrationHelper , private _activatedRoute ) { super ( injector ) ; } ngOnInit ( ) { this . model . editionId = this . _activatedRoute . snapshot . queryParams [ 'editionId' ] ; if ( this . appSession . tenant != null ) { this . _router . navigate ( [ 'account/login' ] ) ; return ; } this . _profileService . getPasswordComplexitySetting ( ) . subscribe ( result => { this . passwordComplexitySetting = result . setting ; } ) ; } ngAfterViewInit ( ) { if ( this . model . editionId ) { this . _tenantRegistrationService . getEdition ( this . model . editionId ) . subscribe ( ( result ) => { this . model . edition = result ; } ) ; } } save ( ) { this . saving = true ; this . _tenantRegistrationService . registerTenant ( this . model ) . pipe ( finalize ( ( ) => { this . saving = false ; } ) ) . subscribe ( ( result ) => { this . notify . success ( this . l ( 'SuccessfullyRegistered' ) ) ; this . _tenantRegistrationHelper . registrationResult = result ; this . _router . navigate ( [ 'account/register-tenant-result' ] ) ; } ) ; } }