File

src/app/modules/shared-feature/components/validate-teacher-identifier-popup/validate-teacher-identifier-popup.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(userService: UserService, resourceService: ResourceService, toasterService: ToasterService, router: Router, popupControlService: PopupControlService)
Parameters :
Name Type Optional
userService UserService No
resourceService ResourceService No
toasterService ToasterService No
router Router No
popupControlService PopupControlService No

Inputs

labels
Type : any
userFeedData
Type : literal type

Outputs

close
Type : EventEmitter

Methods

closeModal
closeModal()
Returns : void
handleSubmitButton
handleSubmitButton()
Returns : void
initializeFormField
initializeFormField()
Returns : void
navigateToValidateId
navigateToValidateId()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
processUserFeedData
processUserFeedData()
Returns : void
setTelemetryData
setTelemetryData()
Returns : void
verifyExtId
verifyExtId(action: string)
Parameters :
Name Type Optional
action string No
Returns : void

Properties

channelData
Type : []
closeInteractEdata
Type : any
createValidateModal
Decorators :
@ViewChild('createValidateModal')
enableSubmitButton
Type : boolean
extIdFailed
Type : boolean
extIdVerified
Type : boolean
formBuilder
Type : UntypedFormBuilder
pageId
Type : string
Default value : 'user-verification-popup'
Public popupControlService
Type : PopupControlService
processValidation
Default value : false
Public resourceService
Type : ResourceService
Public router
Type : Router
showError
Type : boolean
showStateDropdown
Type : boolean
telemetryCdata
Type : Array<literal type>
Default value : []
telemetryImpressionData
Type : IImpressionEventInput
telemetryInteractObject
Type : IInteractEventObject
Public toasterService
Type : ToasterService
userDetailsForm
Type : UntypedFormGroup
userId
Type : string
Public userService
Type : UserService
import { IInteractEventObject, IImpressionEventInput } from '@sunbird/telemetry';
import { ResourceService } from '@sunbird/shared';
import { Component, OnInit, ViewChild, Output, EventEmitter, Input, OnDestroy } from '@angular/core';
import { UserService } from '@sunbird/core';
import { ToasterService } from '@sunbird/shared';
import * as _ from 'lodash-es';
import { UntypedFormBuilder, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import { Router } from '@angular/router';
import { PopupControlService } from '../../../../service/popup-control.service';

@Component({
  selector: 'app-validate-teacher-identifier-popup',
  templateUrl: './validate-teacher-identifier-popup.component.html',
  styleUrls: ['./validate-teacher-identifier-popup.component.scss']
})
export class ValidateTeacherIdentifierPopupComponent implements OnInit, OnDestroy {
  @Input() userFeedData: {};
  @Input() labels: any;
  @Output() close = new EventEmitter<any>();
  @ViewChild('createValidateModal') createValidateModal;
  userDetailsForm: UntypedFormGroup;
  formBuilder: UntypedFormBuilder;
  processValidation = false;
  enableSubmitButton: boolean;
  showError: boolean;
  extIdVerified: boolean;
  extIdFailed: boolean;
  userId: string;
  channelData: [];
  showStateDropdown: boolean;
  telemetryCdata: Array<{}> = [];
  telemetryInteractObject: IInteractEventObject;
  telemetryImpressionData: IImpressionEventInput;
  closeInteractEdata: any;
  pageId = 'user-verification-popup';
  constructor(
    public userService: UserService,
    public resourceService: ResourceService,
    public toasterService: ToasterService,
    public router: Router, public popupControlService: PopupControlService) { }

  ngOnInit() {
    this.popupControlService.changePopupStatus(false);
    this.setTelemetryData();
    this.userId = this.userService.userid;
    this.processUserFeedData();
    this.initializeFormField();
  }

  initializeFormField() {
    this.userDetailsForm = new UntypedFormGroup({
      extId: new UntypedFormControl('', Validators.required)
    });
    if (this.showStateDropdown) {
      this.userDetailsForm.addControl('state', new UntypedFormControl('', Validators.required));
    }
    this.handleSubmitButton();
  }

  handleSubmitButton() {
    this.enableSubmitButton = false;
    this.userDetailsForm.valueChanges.subscribe(val => {
      this.showError = false;
      this.enableSubmitButton = (this.userDetailsForm.status === 'VALID');
    });
  }

  verifyExtId(action: string) {
    const req = {
      request: {
        'userId': this.userId,
        'action': action,
        'feedId': _.get(this.userFeedData, 'id')
      }
    };
    if (action === 'accept') {
      const channelValue = _.get(this.userFeedData, 'data.prospectChannels').length > 1 ?
        this.userDetailsForm.get('state').value : _.get(this.userFeedData, 'data.prospectChannels[0]');
      req.request['channel'] = channelValue;
      req.request['userExtId'] = this.userDetailsForm.get('extId').value;
    }

    this.userService.userMigrate(req).subscribe((data) => {
      if (_.get(data, 'responseCode') === 'OK' && _.get(data, 'result.response') === 'SUCCESS') {
        this.extIdVerified = true;
      }
    }, (error) => {
      if (_.get(error, 'responseCode') === 'invalidUserExternalId' && _.get(error, 'result.remainingAttempt') > 0) {
        this.userDetailsForm.reset();
        this.showError = true;
      } else if (_.get(error, 'error.params.err') === 'USER_MIGRATION_FAILED') {
        this.extIdFailed = true;
      } else {
        this.toasterService.error(this.resourceService.messages.emsg.m0005);
        this.closeModal();
      }
    });
  }

  processUserFeedData() {
    this.channelData = _.get(this.userFeedData, 'data.prospectChannels');
    this.showStateDropdown = this.channelData.length > 1 ? true : false;
  }

  closeModal() {
    if (this.extIdVerified) {
      this.userService.getUserProfile();
    }
    this.createValidateModal.deny();
    this.close.emit();
    this.popupControlService.changePopupStatus(true);
  }

  navigateToValidateId() {
    this.processValidation = true;
  }

  setTelemetryData() {
    this.closeInteractEdata = {
      id: this.extIdVerified ? 'ext-user-verify-success' : 'ext-user-verify-fail',
      type: 'click',
      pageid: this.pageId

    };
    this.telemetryCdata = [
      {
        id: 'user:state:teacherId',
        type: 'Feature'
      },
      {
        id: 'SC-1349',
        type: 'Task'
      }
    ];

    this.telemetryInteractObject = {
      id: this.userService.userid,
      type: 'User',
      ver: '1.0'
    };

    this.telemetryImpressionData = {
      context: {
        env: 'user-verification',
        cdata: this.telemetryCdata
      },
      edata: {
        type: 'view',
        pageid: this.pageId,
        uri: this.router.url
      }
    };
  }

  ngOnDestroy(): void {
    this.popupControlService.changePopupStatus(true);
  }

}
<app-modal-wrapper [config]="{disableClose: true, size: 'normal'}" [appTelemetryImpression]="telemetryImpressionData"
  #createValidateModal>
  <ng-template sbModalContent>
    <div class="sb-modal">
      <div class="transition ui dimmer page modals active visible">
        <div class="ui modal transition active visible normal">
          <!--Header-->
          <div class="sb-modal-header">
            {{labels?.popupHeaderLabel}}
          </div>
          <!--/Header-->

          <!--modal content-->
          <div class="sb-modal-content">
            <div *ngIf="!processValidation">
              {{labels?.headerLabel}}
            </div>
            <form class="sb-form" [formGroup]="userDetailsForm">
              <div *ngIf="processValidation && !(extIdVerified || extIdFailed)" class="sb-field-group mb-16 text-left">
                <div class="sb-field" *ngIf="showStateDropdown">
                  <label>{{resourceService?.frmelmnts?.lbl?.state}}</label>
                  <sui-select id="stateField" [isSearchable]="false" class="selection" [options]="options"
                    formControlName="state">
                    <sui-select-option *ngFor="let option of channelData" [value]="option"></sui-select-option>
                  </sui-select>
                </div>
                <div class="sb-field">
                  <label class="required">{{labels?.fieldLabel}}</label>
                  <input #extIdInputField type="text" required name="extId" placeholder="For example, ER12345"
                    class="sb-form-control" formControlName="extId" />
                  <span *ngIf="showError" class="sb-color-error fxsmall mt-8">
                    {{labels?.incorrectIDLabel}}
                  </span>
                </div>
              </div>
            </form>
            <!-- Success / error field  -->
            <div *ngIf="extIdVerified" class="text-center my-24">
              {{labels?.verificationSuccessfulLabel}}
            </div>

            <div *ngIf="extIdFailed" class="text-center my-24">
              {{labels?.verficationFailureLabel}}
            </div>
          </div>
          <!--modal content-->

          <!--action buttons-->

          <div class="sb-modal-actions">
            <div class="action-btns" *ngIf="!processValidation">
              <button tabindex="0" appTelemetryInteract
                [telemetryInteractEdata]="{id:'ext-user-verify-reject' , type:'click' , pageid: pageId }"
                [telemetryInteractCdata]="telemetryCdata" [telemetryInteractObject]="telemetryInteractObject"
                type="button" class="sb-btn sb-btn-normal sb-btn-outline-primary mr-8" tabindex="0"
                (click)="verifyExtId('reject'); closeModal()">
                {{resourceService?.frmelmnts?.btn?.no}}
              </button>
              <button tabindex="0" appTelemetryInteract
                [telemetryInteractEdata]="{id:'ext-user-verify-confirm' , type:'click' , pageid: pageId }"
                [telemetryInteractCdata]="telemetryCdata" [telemetryInteractObject]="telemetryInteractObject"
                type="button" class="sb-btn sb-btn-normal sb-btn-primary" tabindex="0" (click)="navigateToValidateId()">
                {{resourceService?.frmelmnts?.btn?.yes}}
              </button>
            </div>
            <button tabindex="0" appTelemetryInteract
              [telemetryInteractEdata]="{id:'ext-user-verify-submit' , type:'click' , pageid: pageId }"
              [telemetryInteractCdata]="telemetryCdata" [telemetryInteractObject]="telemetryInteractObject"
              [disabled]="!enableSubmitButton" *ngIf="processValidation && !(extIdVerified || extIdFailed)"
              type="submit" class="sb-btn sb-btn-normal sb-btn-primary" tabindex="0" (click)="verifyExtId('accept')">
              {{resourceService?.frmelmnts?.btn?.submit}}
            </button>
            <button tabindex="0" appTelemetryInteract [telemetryInteractEdata]="closeInteractEdata"
              [telemetryInteractCdata]="telemetryCdata" [telemetryInteractObject]="telemetryInteractObject"
              *ngIf="extIdVerified || extIdFailed"
              [ngClass]="{'sb-btn-error' : extIdFailed, 'sb-btn-success' : extIdVerified }" type="button"
              class="sb-btn sb-btn-normal" tabindex="0" (click)="closeModal()">
              <!--sb-btn-success-->
              {{resourceService?.frmelmnts?.btn?.ok}}
            </button>
          </div>
          <!--action buttons-->
        </div>
      </div>
    </div>
  </ng-template>
</app-modal-wrapper>

./validate-teacher-identifier-popup.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""