File

src/app/components/popups/account-recovery-id/account-recovery-id-popup.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(profileService: ProfileService, telemetryGeneratorService: TelemetryGeneratorService, appGlobalService: AppGlobalService, commonUtilService: CommonUtilService, popOverCtrl: PopoverController, platform: Platform, menuCtrl: MenuController)
Parameters :
Name Type Optional
profileService ProfileService No
telemetryGeneratorService TelemetryGeneratorService No
appGlobalService AppGlobalService No
commonUtilService CommonUtilService No
popOverCtrl PopoverController No
platform Platform No
menuCtrl MenuController No

Inputs

recoveryEmail
Type : string
recoveryPhone
Type : string

Methods

Async cancel
cancel()
Returns : any
Private generateRecoveryImpression
generateRecoveryImpression()
Returns : void
Private generateRecoveryTelemetry
generateRecoveryTelemetry(type: string)
Parameters :
Name Type Optional
type string No
Returns : void
Private getReqPayload
getReqPayload(type: string)
Parameters :
Name Type Optional
type string No
Returns : UpdateServerProfileInfoRequest
Private initializeFormFields
initializeFormFields()
Returns : void
ionViewWillEnter
ionViewWillEnter()
Returns : void
ionViewWillLeave
ionViewWillLeave()
Returns : void
ngOnInit
ngOnInit()
Returns : void
removeSameRecoveryIdErr
removeSameRecoveryIdErr(type: string)
Parameters :
Name Type Optional
type string No
Returns : void
Async submitRecoveryId
submitRecoveryId(type: RecoveryType)
Parameters :
Name Type Optional
type RecoveryType No
Returns : any

Properties

Public platform
Type : Platform
Private profile
Type : Profile
recoveryEmailForm
Type : FormGroup
recoveryIdType
Type : string
recoveryPhoneForm
Type : FormGroup
RecoveryType
Default value : RecoveryType
sameEmailErr
Default value : false
samePhoneErr
Default value : false
Private unregisterBackButton
Type : Subscription
import { Component, OnInit, Inject, Input } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { TelemetryGeneratorService } from '@app/services/telemetry-generator.service';
import { ImpressionType, Environment, PageId, InteractType } from '@app/services/telemetry-constants';
import { Profile, ProfileService, UpdateServerProfileInfoRequest } from 'sunbird-sdk';
import { AppGlobalService } from '@app/services/app-global-service.service';
import { CommonUtilService } from '@app/services/common-util.service';
import { PopoverController, Platform, MenuController } from '@ionic/angular';
import { Subscription } from 'rxjs';
import { finalize } from 'rxjs/operators';

enum RecoveryType {
  PHONE = 'phone',
  EMAIL = 'email'
}

@Component({
  selector: 'app-account-recovery-id-popup',
  templateUrl: './account-recovery-id-popup.component.html',
  styleUrls: ['./account-recovery-id-popup.component.scss']
})
export class AccountRecoveryInfoComponent implements OnInit {

  RecoveryType = RecoveryType;

  // Data passed in by componentProps
  @Input() recoveryPhone: string;
  @Input() recoveryEmail: string;

  recoveryIdType: string;
  recoveryEmailForm: FormGroup;
  recoveryPhoneForm: FormGroup;
  private profile: Profile;
  private unregisterBackButton: Subscription;
  sameEmailErr = false;
  samePhoneErr = false;

  constructor(@Inject('PROFILE_SERVICE') private profileService: ProfileService,
              private telemetryGeneratorService: TelemetryGeneratorService,
              private appGlobalService: AppGlobalService,
              private commonUtilService: CommonUtilService,
              private popOverCtrl: PopoverController,
              public  platform: Platform,
              private menuCtrl: MenuController) { }

  ngOnInit() {
    this.recoveryIdType = (this.recoveryPhone.length > 0) ? RecoveryType.PHONE : RecoveryType.EMAIL;
    this.initializeFormFields();
    this.profile = this.appGlobalService.getCurrentUser();
    this.generateRecoveryImpression();
    this.menuCtrl.enable(false);
  }

  ionViewWillEnter() {
    this.unregisterBackButton = this.platform.backButton.subscribeWithPriority(11, () => {
      this.popOverCtrl.dismiss();
    });
  }

  ionViewWillLeave() {
    this.menuCtrl.enable(true);
    if (this.unregisterBackButton) {
      this.unregisterBackButton.unsubscribe();
    }
  }

  private initializeFormFields() {
    this.recoveryEmailForm = new FormGroup({
      email: new FormControl('', [Validators.required, Validators.pattern(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[a-z]{2,4}$/)]),
    });
    this.recoveryPhoneForm = new FormGroup({
      phone: new FormControl('', [Validators.required, Validators.pattern(/^[6-9]\d{9}$/)]),
    });
  }

  async submitRecoveryId(type: RecoveryType) {
    if (this.commonUtilService.networkInfo.isNetworkAvailable) {
      let loader = await this.commonUtilService.getLoader();
      const req: UpdateServerProfileInfoRequest = this.getReqPayload(type);
      await loader.present();
      this.profileService.updateServerProfile(req).pipe(
        finalize(async () => {
          if (loader) {
            await loader.dismiss();
            loader = undefined;
          }
        })
      )
        .subscribe((data: any) => {
          if (data && data.response === 'SUCCESS') {
            this.popOverCtrl.dismiss({ isEdited: true });
            this.generateRecoveryTelemetry(type);
          }
        }, (error) => {
          if (error && error.response && error.response.body && error.response.body.params &&
            error.response.body.params.err === 'UOS_USRUPD0062') {
            if (type === RecoveryType.EMAIL) { this.sameEmailErr = true; }
            if (type === RecoveryType.PHONE) { this.samePhoneErr = true; }
          } else {
            this.commonUtilService.showToast('SOMETHING_WENT_WRONG');
          }
        });
    } else {
      this.commonUtilService.showToast('INTERNET_CONNECTIVITY_NEEDED');
    }
  }

  private getReqPayload(type: string): UpdateServerProfileInfoRequest {
    const req = {
      userId: this.profile.uid,
      recoveryEmail: '',
      recoveryPhone: ''
    };
    if (type === RecoveryType.EMAIL) { req.recoveryEmail = this.recoveryEmailForm.value.email.toLowerCase(); }
    if (type === RecoveryType.PHONE) { req.recoveryPhone = this.recoveryPhoneForm.value.phone; }
    return req;
  }

  private generateRecoveryImpression() {
    this.telemetryGeneratorService.generateImpressionTelemetry(
      ImpressionType.VIEW, '',
      PageId.RECOVERY_ACCOUNT_ID_POPUP,
      Environment.USER
    );
  }

  private generateRecoveryTelemetry(type: string) {
    const valueMap = { recoveryType: type };
    this.telemetryGeneratorService.generateInteractTelemetry(
      InteractType.TOUCH,
      '',
      Environment.USER,
      PageId.RECOVERY_ACCOUNT_ID_POPUP, undefined, valueMap
    );
  }

  removeSameRecoveryIdErr(type: string) {
    if (this.sameEmailErr && type === RecoveryType.EMAIL) { this.sameEmailErr = false; }
    if (this.samePhoneErr && type === RecoveryType.PHONE) { this.samePhoneErr = false; }
  }

  async cancel() {
    await this.popOverCtrl.dismiss({ isEdited: false });
  }

}
<ion-content>

    <div class="ar-header ion-text-center">
        <h6 class="M0" *ngIf="recoveryEmail?.length || recoveryPhone?.length">{{'UPDATE_RECOVERY_ID' | translate}}</h6>
        <h6 class="M0" *ngIf="!recoveryEmail?.length && !recoveryPhone?.length">{{'ADD_RECOVERY_ID' | translate}}</h6>
    </div>

    <ion-list lines="none">
        <ion-radio-group [(ngModel)]="recoveryIdType">

            <ion-list-header class="recovery-desc">
                <ion-label>{{'RECOVERY_ID_DESCRIPTION' | translate}}</ion-label>
            </ion-list-header>

            <ion-item>
                <ion-label>{{'EMAIL_ID_PLACEHOLDER' | translate}}</ion-label>
                <ion-radio slot="start" value="{{RecoveryType.EMAIL}}"></ion-radio>
            </ion-item>

            <ion-item>
                <ion-label>{{'PHONE_PLACEHOLDER' | translate}}</ion-label>
                <ion-radio slot="start" value="{{RecoveryType.PHONE}}"></ion-radio>
            </ion-item>

        </ion-radio-group>
    </ion-list>

    <div>
        <div *ngIf="recoveryIdType === RecoveryType.EMAIL">
            <form [formGroup]="recoveryEmailForm">
                <div class="M16">
                    <div class="W100 merged-input-container MT10">
                        <ion-input type="text" placeholder="{{'EMAIL_PLACEHOLDER' | translate}}"
                            class="form-control custom" formControlName="email" (input)="removeSameRecoveryIdErr(RecoveryType.EMAIL)">
                        </ion-input>
                    </div>
                    <ion-label class="error"
                        *ngIf="recoveryEmailForm.controls.email.dirty && recoveryEmailForm.controls.email.invalid">
                        {{'ERROR_EMAIL_INVALID' | translate}}
                    </ion-label>
                    <ion-label class="error" *ngIf="sameEmailErr">
                        {{'ERROR_SAME_EMAIL_UPDATED' | translate}}
                    </ion-label>
                </div>
            </form>
        </div>

        <div *ngIf="recoveryIdType === RecoveryType.PHONE">
            <form [formGroup]="recoveryPhoneForm">
                <div class="M16">
                    <div class="W100 merged-input-container MT10" style="text-align:start">
                        <ion-input type="tel" placeholder="+91 -" class="form-control decorator " value="+91 -"
                            disabled>
                        </ion-input>
                        <ion-input type="tel" placeholder="{{'ENTER_PHONE_POPUP_TITLE' | translate}}" maxlength="10"
                            minlength="10" required class="form-control custom" formControlName="phone"
                            (input)="removeSameRecoveryIdErr(RecoveryType.PHONE)">
                        </ion-input>
                    </div>
                    <ion-label class="error"
                        *ngIf="recoveryPhoneForm.controls.phone.dirty && recoveryPhoneForm.controls.phone.invalid">
                        {{'ERROR_RECOVERY_ID_PHONE_INVALID' | translate}}
                    </ion-label>
                    <ion-label class="error" *ngIf="samePhoneErr">
                        {{'ERROR_SAME_PHONE_UPDATED' | translate}}
                    </ion-label>
                </div>
            </form>
        </div>
        <ion-row class="custom-shadow">
            <ion-col class="ion-padding">
                <ion-button expand="block" fill="outline" (click)="cancel()">{{ 'CANCEL' | translate }} </ion-button>
            </ion-col>
            <ion-col class="ion-padding">
                <ion-button expand="block" type="submit" *ngIf="recoveryIdType === RecoveryType.EMAIL"
                    (click)="submitRecoveryId(RecoveryType.EMAIL)" [disabled]="!recoveryEmailForm.valid">
                    {{ 'BTN_SUBMIT' | translate }}</ion-button>

                <ion-button expand="block" type="submit" *ngIf="recoveryIdType === RecoveryType.PHONE"
                    (click)="submitRecoveryId(RecoveryType.PHONE)" [disabled]="!recoveryPhoneForm.valid">
                    {{ 'BTN_SUBMIT' | translate }}</ion-button>
            </ion-col>
        </ion-row>
    </div>

</ion-content>

./account-recovery-id-popup.component.scss

@import "src/assets/styles/variables";
@import "src/assets/styles/_custom-mixins.scss";
@import "src/assets/styles/_variables.scss";

.merged-input-container {
    border: 1px solid $form-input-border-active-color;
    display: flex;
    flex: 1 1 auto;
    border-radius: 4px;
    .decorator {
        display: inline-block;
        max-width: 3.125rem;
    }
    .custom {
        display: inline-block;
    }
}

.ar-submit-btn {
    padding: 12px 15%;
}

.ar-btn-dissable-color {
    background-color: map-get($colors, dark_gray);
    color: map-get($colors, white);
}

.ar-btn-enable-color {
    background-color: map-get($colors, primary);
    color: map-get($colors, white);
}

.ar-header {
    background-color: #{$blue};
    color: map-get($colors, white);
    padding: 16px 0;
}

.recovery-desc{
    @include padding(null, 16px, null, null);
    font-size: 1rem;
}

.custom-shadow {
    box-shadow: 0 -5px 5px -5px rgba(0, 0, 0, 0.2);
}

ion-button{
    --background: #{$blue} !important;
    color: map-get($colors, white);
    --background-hover: #{$blue} !important;
    --background-activated: #{$blue} !important;
}

ion-button[fill="outline"]{
    --background: map-get($colors, white) !important;
    color: #{$blue};
    --border-color: #{$blue};
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""