src/app/components/popups/teacher-id-verification-popup/teacher-id-verification-popup.component.ts
OnInit
selector | app-teacher-id-verification-popup |
styleUrls | ./teacher-id-verification-popup.component.scss |
templateUrl | ./teacher-id-verification-popup.component.html |
Properties |
Methods |
constructor(profileService: ProfileService, popOverCtrl: PopoverController, navParams: NavParams, telemetryGeneratorService: TelemetryGeneratorService, commonUtilService: CommonUtilService, events: Events)
|
|||||||||||||||||||||
Parameters :
|
Async cancelPopup | ||||
cancelPopup(message)
|
||||
Parameters :
Returns :
any
|
Async closePopup |
closePopup()
|
Returns :
any
|
externalUserVerfication | ||||
externalUserVerfication(req)
|
||||
Parameters :
Returns :
void
|
generateTelemetryForClose |
generateTelemetryForClose()
|
Returns :
void
|
generateTelemetryForFailedVerification |
generateTelemetryForFailedVerification()
|
Returns :
void
|
generateTelemetryForYesAndNo | ||||
generateTelemetryForYesAndNo(id)
|
||||
Parameters :
Returns :
void
|
initializeFormFields |
initializeFormFields()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
selectState | ||||
selectState(stateName)
|
||||
Parameters :
Returns :
void
|
submitTeacherId |
submitTeacherId()
|
Returns :
void
|
teacherConfirmation | ||||||
teacherConfirmation(flag: boolean)
|
||||||
Parameters :
Returns :
void
|
count |
Type : number
|
Default value : 0
|
showStates |
Type : boolean
|
showTeacherIdIncorrectErr |
Default value : false
|
stateFlag |
Default value : false
|
stateList |
Type : any
|
stateName |
Type : any
|
teacherIdFlag |
Type : string
|
teacherIdForm |
Type : FormGroup
|
teacherIdPopupFlags |
Default value : TeacherIdPopupFlags
|
teacherModelId |
Type : string
|
tenantMessages |
Type : any
|
userFeed |
Type : any
|
import { Component, OnInit, Inject } from '@angular/core';
import { PopoverController, NavParams } from '@ionic/angular';
import { Events } from '@app/util/events';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { ProfileService, UserMigrateRequest, HttpClientError } from 'sunbird-sdk';
import { CommonUtilService } from '@app/services/common-util.service';
import { TelemetryGeneratorService } from '@app/services/telemetry-generator.service';
import { featureIdMap } from '@app/feature-id-map';
import {
Environment,
ImpressionType,
InteractSubtype,
InteractType,
PageId,
ID
} from '@app/services/telemetry-constants';
export enum TeacherIdPopupFlags {
STATE_CONFIRMATION = 'stateConfirmation',
STATE_ID_INPUT = 'stateIdInput',
VERIFIED_STATE_ID = 'verifiedStateId',
FAILED_STATE_ID = 'failedStateId',
OK = 'ok',
INVALIDEXTERNALID = 'invaliduserexternalid'
}
@Component({
selector: 'app-teacher-id-verification-popup',
templateUrl: './teacher-id-verification-popup.component.html',
styleUrls: ['./teacher-id-verification-popup.component.scss']
})
export class TeacherIdVerificationComponent implements OnInit {
teacherIdPopupFlags = TeacherIdPopupFlags;
showTeacherIdIncorrectErr = false;
teacherIdFlag: string;
teacherIdForm: FormGroup;
stateFlag = false;
stateName: any;
showStates: boolean;
stateList: any;
userFeed: any;
count = 0;
teacherModelId: string;
tenantMessages: any;
constructor(
@Inject('PROFILE_SERVICE') private profileService: ProfileService,
private popOverCtrl: PopoverController,
private navParams: NavParams,
private telemetryGeneratorService: TelemetryGeneratorService,
private commonUtilService: CommonUtilService,
private events: Events
) {
if (this.navParams.data) {
this.userFeed = this.navParams.data.userFeed;
this.stateList = this.userFeed.data.prospectChannels;
this.tenantMessages = this.navParams.data.tenantMessages;
}
}
ngOnInit() {
this.teacherIdFlag = TeacherIdPopupFlags.STATE_CONFIRMATION;
this.telemetryGeneratorService.generateImpressionTelemetry(
ImpressionType.VIEW,
'',
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
Environment.HOME, '', '', '', undefined, featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION);
}
async closePopup() {
this.generateTelemetryForClose();
await this.popOverCtrl.dismiss();
}
teacherConfirmation(flag: boolean) {
if (flag) {
this.initializeFormFields();
this.generateTelemetryForYesAndNo(ID.USER_VERIFICATION_CONFIRMED);
} else {
this.generateTelemetryForYesAndNo(ID.USER_VERIFICATION_REJECTED);
const req: UserMigrateRequest = {
userId: this.userFeed.userId,
action: 'reject',
channel: this.stateName ? this.stateName : this.userFeed.data.prospectChannels[0],
feedId: this.userFeed.id
};
this.profileService.userMigrate(req).toPromise()
.then(async (response) => {
this.count = 0;
if ((response.responseCode).toLowerCase() === TeacherIdPopupFlags.OK) {
this.teacherIdFlag = TeacherIdPopupFlags.VERIFIED_STATE_ID;
this.closePopup();
}
})
.catch((error) => {
this.closePopup();
});
}
}
initializeFormFields() {
this.teacherIdFlag = TeacherIdPopupFlags.STATE_ID_INPUT;
this.teacherIdForm = new FormGroup({
teacherId: new FormControl('', Validators.requiredTrue)
});
}
submitTeacherId() {
this.count++;
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
'',
Environment.HOME,
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
undefined,
undefined,
undefined,
featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION,
ID.USER_VERIFICATION_SUBMITED
);
if (this.teacherIdForm.value.teacherId) {
const req: UserMigrateRequest = {
userId: this.userFeed.userId,
userExtId: this.teacherIdForm.value.teacherId,
channel: this.stateName ? this.stateName : this.userFeed.data.prospectChannels[0],
action: 'accept',
feedId: this.userFeed.id
};
this.externalUserVerfication(req);
}
}
externalUserVerfication(req) {
this.profileService.userMigrate(req).toPromise()
.then(async (response) => {
this.count = 0;
if ((response.responseCode).toLowerCase() === TeacherIdPopupFlags.INVALIDEXTERNALID) {
this.showTeacherIdIncorrectErr = true;
this.teacherModelId = '';
} else if ((response.responseCode).toLowerCase() === TeacherIdPopupFlags.OK) {
this.teacherIdFlag = TeacherIdPopupFlags.VERIFIED_STATE_ID;
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.OTHER,
'',
Environment.USER,
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
undefined,
undefined,
undefined,
featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION,
ID.USER_VERIFICATION_SUCCESS
);
this.events.publish('loggedInProfile:update');
}
})
.catch((error) => {
if (HttpClientError.isInstance(error)) {
if (error.response.responseCode === 400) {
this.generateTelemetryForFailedVerification();
this.teacherIdFlag = TeacherIdPopupFlags.FAILED_STATE_ID;
} else if (error.response.responseCode === 404) {
this.generateTelemetryForFailedVerification();
this.teacherIdFlag = TeacherIdPopupFlags.FAILED_STATE_ID;
} else if (error.response.responseCode === 429) {
this.closePopup();
this.commonUtilService.showToast('USER_IS_NOT_VERIFIED');
} else if (error.response.responseCode === 401) {
this.closePopup();
this.commonUtilService.showToast('USER_IS_NOT_VERIFIED');
} else {
this.closePopup();
this.commonUtilService.showToast('USER_IS_NOT_VERIFIED');
}
}
});
}
selectState(stateName) {
this.stateName = stateName;
this.showStates = false;
}
generateTelemetryForClose() {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.POPUP_DISMISSED,
Environment.HOME,
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
undefined,
undefined,
undefined,
featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION
);
}
generateTelemetryForFailedVerification() {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.OTHER,
'',
Environment.HOME,
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
undefined,
undefined,
undefined,
featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION,
ID.USER_VERIFICATION_FAILED
);
}
generateTelemetryForYesAndNo(id) {
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
'',
Environment.HOME,
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
undefined,
undefined,
undefined,
featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION,
id
);
}
async cancelPopup(message) {
const reason = new Map();
reason['popup_close'] = message;
this.telemetryGeneratorService.generateInteractTelemetry(
InteractType.TOUCH,
InteractSubtype.POPUP_DISMISSED,
Environment.HOME,
PageId.EXTERNAL_USER_VERIFICATION_POPUP,
undefined,
reason,
undefined,
featureIdMap.userVerification.EXTERNAL_USER_VERIFICATION,
);
await this.popOverCtrl.dismiss();
}
}
<ion-content style="overflow: auto">
<div [ngClass]="{ 'sb-popup-header-info': (teacherIdPopupFlags.STATE_CONFIRMATION === teacherIdFlag || teacherIdPopupFlags.STATE_ID_INPUT === teacherIdFlag),
'sb-popup-header-success': teacherIdPopupFlags.VERIFIED_STATE_ID === teacherIdFlag,
'sb-popup-header-danger': teacherIdPopupFlags.FAILED_STATE_ID === teacherIdFlag }">
<h6 class="M0">{{tenantMessages?.popupHeaderLabel}}</h6>
</div>
<section class="sb-popover" *ngIf="teacherIdPopupFlags.STATE_CONFIRMATION === teacherIdFlag">
<div class="M16 text-center">
<p>{{ tenantMessages?.headerLabel }}</p>
</div>
<div class="sb-popover-footer MT30 d-flex">
<button class="sb-popover-action-btn sb-btn sb-btn-normal sb-btn-outline-info W100"
(click)="teacherConfirmation(false)">
{{ 'NO' | translate | uppercase }}</button>
<button class="sb-popover-action-btn sb-btn sb-btn-normal sb-btn-info W100"
(click)="teacherConfirmation(true)">
{{ 'YES' | translate | uppercase }}</button>
</div>
</section>
<section class="sb-popover" *ngIf="teacherIdPopupFlags.STATE_ID_INPUT === teacherIdFlag">
<div class="M16" *ngIf="stateList.length > 1">
<p>{{'SELECT_YOUR_STATE' | translate}}</p>
<div class="input-container">
<input type="text" class="input" placeholder="Select State" [(ngModel)]="stateName">
<ion-icon (click)="showStates = !showStates;" class="input-icon" name="arrow-down">
</ion-icon>
</div>
<div class="showList" *ngIf="showStates">
<ul>
<li (click)="selectState(state)" *ngFor="let state of stateList">{{state}}</li>
</ul>
</div>
</div>
<form [formGroup]="teacherIdForm">
<div class="M16">
<p>{{ tenantMessages?.fieldLabel }}</p>
<ion-input type="text"
[ngClass]="{'sb-input-danger': showTeacherIdIncorrectErr,'sb-input-black': !showTeacherIdIncorrectErr}"
placeholder="{{'ID_PLACEHOLDER' | translate}}" formControlName="teacherId"
[(ngModel)]="teacherModelId" name="teacherId"> </ion-input>
<p class="error" *ngIf="showTeacherIdIncorrectErr">{{ tenantMessages.incorrectIDLabel }}
</p>
</div>
<div class="sb-popover-footer MT30">
<button class="sb-popover-action-btn sb-btn sb-btn-normal sb-btn-info W50" (click)="submitTeacherId()"
[disabled]='(!stateName || !teacherModelId || count > 0)' *ngIf="stateList.length > 1">
{{ 'BTN_SUBMIT' | translate | uppercase }}</button>
<button class="sb-popover-action-btn sb-btn sb-btn-normal sb-btn-info W50" (click)="submitTeacherId()"
[disabled]='!teacherModelId || count > 0' *ngIf="stateList.length == 1">
{{ 'BTN_SUBMIT' | translate | uppercase }}</button>
</div>
</form>
</section>
<section class="sb-popover" *ngIf="teacherIdPopupFlags.VERIFIED_STATE_ID === teacherIdFlag">
<div class="M16 text-center">
<p>{{tenantMessages?.verificationSuccessfulLabel }}</p>
</div>
<div class="sb-popover-footer MT30">
<button class="sb-popover-action-btn sb-btn sb-btn-normal sb-btn-success W50" (click)="cancelPopup('PROFILE_VERIFIED')">
{{ 'OKAY' | translate }}</button>
</div>
</section>
<section class="sb-popover" *ngIf="teacherIdPopupFlags.FAILED_STATE_ID === teacherIdFlag">
<div class="M16 text-center">
<p>{{ tenantMessages?.verficationFailureLabel }}</p>
</div>
<div class="sb-popover-footer MT30">
<button class="sb-popover-action-btn sb-btn sb-btn-normal sb-btn-error W50" (click)="cancelPopup('PROFILE_FAILED')">
{{ 'OKAY' | translate }}</button>
</div>
</section>
</ion-content>
./teacher-id-verification-popup.component.scss
@import "src/assets/styles/variables.scss";
@import "src/assets/styles/_variables.scss";
.merged-input-container {
border: 1px solid $info-color;
display: flex;
flex: 1 1 auto;
border-radius: 4px;
.decorator {
display: inline-block;
max-width: 3.125rem;
}
.custom {
display: inline-block;
}
}
.sb-input {
width: 100%;
padding: 8px;
border: 1px solid red;
border-radius: 2px;
}
.sb-input-black {
@extend .sb-input;
border: 1px solid map-get($colors, primary_black);
}
.sb-input-info {
@extend .sb-input;
border: 1px solid $info-color;
}
.sb-input-danger {
@extend .sb-input;
border: 1px solid $danger-color;
}
input:focus {
outline: $info-color auto 1px;
}
.input-container {
border: 0.5px solid map-get($colors, primary_black);
padding: 8px;
border-radius: 3px;
.input {
border: map-get($colors, white);
outline: none;
}
.input-icon {
float: right;
font-size: 1.25rem;
color: map-get($colors, primary_black);
}
}
.showList {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-height: 12.5rem;
overflow-y: scroll;
ul {
list-style-type: none;
}
li {
padding: 8px 0px 8px 8px;
}
}