import { Component } from '@angular/core' ; import { BehaviorSubject , combineLatest , Observable } from 'rxjs' ; import { map , take } from 'rxjs/operators' ; import { AbstractSubscriberComponent } from '../../../../../common/components/abstract-subscriber/abstract-subscriber.component' ; import { FormToastService } from '../../../../../common/services/form-toast.service' ; import { SettingsTwoFactorV2Service } from '../two-factor-v2.service' ; /**
 * Root component - allows a user to see their currently enabled 2FA methods
 * And enable new ones.
 */ @ Component ( { selector : 'm-settings__twoFactorRoot' , templateUrl : './root.component.html' , styleUrls : [ './root.component.ng.scss' ] , } ) export class SettingsTwoFactorV2RootComponent extends AbstractSubscriberComponent { constructor ( private service , private toast ) { super ( ) ; } returns { Observable < boolean > } get totpEnabled$ ( ) : Observable < boolean > { return combineLatest ( [ this . service . totpEnabled$ , this . service . activePanel$ , ] ) . pipe ( map ( ( [ enabled , panel ] ) => { return ( ( enabled && panel . intent !== 'disabled-totp' ) || panel . intent === 'enabled-totp' ) ; } ) ) ; } returns { Observable < boolean > } get smsEnabled$ ( ) : Observable < boolean > { return combineLatest ( [ this . service . smsEnabled$ , this . service . activePanel$ , ] ) . pipe ( map ( ( [ enabled , panel ] ) => { return ( ( enabled && panel . intent !== 'disabled-sms' ) || panel . intent === 'enabled-sms' ) ; } ) ) ; } returns { BehaviorSubject < boolean > } get inProgress$ ( ) : BehaviorSubject < boolean > { return this . service . inProgress$ ; } returns { void } public onSMSClick ( ) { this . subscriptions . push ( combineLatest ( [ this . totpEnabled$ , this . smsEnabled$ ] ) . pipe ( take ( 1 ) , map ( ( [ totpEnabled , smsEnabled ] ) => { if ( totpEnabled ) { this . toast . warn ( 'You cannot currently enable both TOTP and SMS' ) ; return ; } this . service . activePanel$ . next ( smsEnabled ? { panel : 'sms' , intent : 'disable' , } : { panel : 'password' , intent : 'sms' , } ) ; } ) ) . subscribe ( ) ) ; } returns { void } public onDisableIntegrationClick ( ) { this . service . activePanel$ . next ( { panel : 'password' , intent : 'disable' , } ) ; } returns { void } public onSetupAppClick ( ) { this . subscriptions . push ( this . smsEnabled$ . pipe ( take ( 1 ) ) . subscribe ( smsEnabled => { if ( smsEnabled ) { this . toast . warn ( 'You cannot currently enable both TOTP and SMS' ) ; return ; } this . service . activePanel$ . next ( { panel : 'password' , intent : 'setup-app' , } ) ; } ) ) ; } }