src/app/modules/shared-feature/components/onboarding-user-selection/onboarding-user-selection.component.ts
OnInit
OnDestroy
selector | app-onboarding-user-selection |
styleUrls | ./onboarding-user-selection.component.scss |
templateUrl | ./onboarding-user-selection.component.html |
Properties |
|
Methods |
|
Inputs |
Outputs |
constructor(resourceService: ResourceService, tenantService: TenantService, router: Router, navigationHelperService: NavigationHelperService, telemetryService: TelemetryService, activatedRoute: ActivatedRoute, formService: FormService, profileService: ProfileService, userService: UserService, toasterService: ToasterService)
|
|||||||||||||||||||||||||||||||||
Parameters :
|
isStepper | |
Type : boolean
|
|
Default value : false
|
|
tenantInfo | |
Type : ITenantData
|
|
userSelect | |
Type : EventEmitter
|
|
Private getFormConfig |
getFormConfig()
|
Returns :
any
|
Private initialize |
initialize()
|
Returns :
any
|
logAuditEvent | ||||||
logAuditEvent(code: any)
|
||||||
Parameters :
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
Private prepareGuestList | ||||||||
prepareGuestList(fields: [])
|
||||||||
Parameters :
Returns :
any
|
selectUserType | ||||||
selectUserType(selectedGuest: IGuest)
|
||||||
Parameters :
Returns :
void
|
setPopupInteractEdata |
setPopupInteractEdata()
|
Returns :
void
|
submit |
submit()
|
Returns :
void
|
Private updateUserSelection |
updateUserSelection()
|
Returns :
any
|
Public activatedRoute |
Type : ActivatedRoute
|
guestList |
Type : IGuest[]
|
Default value : []
|
Public navigationHelperService |
Type : NavigationHelperService
|
Public resourceService |
Type : ResourceService
|
Public router |
Type : Router
|
selectedUserType |
Type : IGuest
|
telemetryImpression |
Type : IImpressionEventInput
|
Public telemetryService |
Type : TelemetryService
|
Public tenantService |
Type : TenantService
|
Public unsubscribe$ |
Default value : new Subject<void>()
|
Private updateUserSelection$ |
Default value : new BehaviorSubject<string>(undefined)
|
userSelectionInteractEdata |
Type : IInteractEventEdata
|
import { ResourceService, ToasterService } from '@sunbird/shared';
import { Component, OnInit, Output, EventEmitter, Input, OnDestroy } from '@angular/core';
import { TenantService, FormService, UserService } from '@sunbird/core';
import * as _ from 'lodash-es';
import { IImpressionEventInput, TelemetryService, IInteractEventEdata, IAuditEventInput } from '@sunbird/telemetry';
import { Router, ActivatedRoute } from '@angular/router';
import { NavigationHelperService } from '@sunbird/shared';
import { ITenantData } from './../../../core/services/tenant/interfaces/tenant';
import { ProfileService } from '@sunbird/profile';
import { BehaviorSubject, merge, empty, of, Subject } from 'rxjs';
import { switchMap, retry, tap, skipWhile, catchError, takeUntil, concatMap, take, skip } from 'rxjs/operators';
interface IGuest {
code: string;
name: string;
label: string;
icon: string;
isActive: boolean;
searchFilter: string[];
}
@Component({
selector: 'app-onboarding-user-selection',
templateUrl: './onboarding-user-selection.component.html',
styleUrls: ['./onboarding-user-selection.component.scss']
})
export class OnboardingUserSelectionComponent implements OnInit, OnDestroy {
@Input() tenantInfo: ITenantData;
@Output() userSelect = new EventEmitter<boolean>();
@Input() isStepper: boolean = false;
guestList: IGuest[] = [];
selectedUserType: IGuest;
telemetryImpression: IImpressionEventInput;
userSelectionInteractEdata: IInteractEventEdata;
private updateUserSelection$ = new BehaviorSubject<string>(undefined);
public unsubscribe$ = new Subject<void>();
constructor(
public resourceService: ResourceService,
public tenantService: TenantService,
public router: Router,
public navigationHelperService: NavigationHelperService,
public telemetryService: TelemetryService,
public activatedRoute: ActivatedRoute,
private formService: FormService,
private profileService: ProfileService,
private userService: UserService,
private toasterService: ToasterService
) { }
ngOnInit() {
this.setPopupInteractEdata();
this.initialize().subscribe();
if(this.isStepper) {
this.tenantService.tenantData$
.pipe(takeUntil(this.unsubscribe$))
.subscribe(data => {
if (_.get(data, 'tenantData')) {
this.tenantInfo = data.tenantData;
this.tenantInfo.titleName = data.tenantData.titleName || this.resourceService.instance;
}
});
}
}
private initialize() {
return merge(this.getFormConfig().pipe(
tap((fields: object[]) => {
this.guestList = this.prepareGuestList(fields);
})
), this.updateUserSelection()).pipe(takeUntil(this.unsubscribe$));
}
private prepareGuestList(fields = []) {
return _.reduce(_.sortBy(fields, ['index']), (result, field) => {
const { name = null, visibility = true, image = 'guest-img3.svg', searchFilter = [], code = null, label = null, translations = null } = field || {};
if (visibility) {
result.push({
name, searchFilter, code, isActive: false, icon: `assets/images/${image}`,
label: _.get(this.resourceService, label || translations)
});
}
return result;
}, []);
}
private getFormConfig() {
const formServiceInputParams = {
formType: 'config',
formAction: 'get',
contentType: 'userType',
component: 'portal'
};
return this.formService.getFormConfig(formServiceInputParams).pipe(
retry(5),
catchError(err => {
this.userSelect.emit(true);
return of([]);
})
);
}
private updateUserSelection() {
return this.updateUserSelection$
.pipe(
skipWhile(data => data === undefined || data === null),
switchMap(userType => {
const payload = {
userId: _.get(this.userService, 'userid'),
profileUserTypes: [{
'type': userType.toLowerCase()
}]
};
return this.profileService.updateProfile(payload)
.pipe(
retry(5),
concatMap(() => {
return this.userService.userData$.pipe(
skip(1),
take(1)
).pipe(
tap(v => { console.log(v); this.userSelect.emit(true); }),
);
}),
catchError(err => {
this.toasterService.error(_.get(this.resourceService, 'messages.emsg.m0005'));
return empty();
})
);
})
);
}
ngAfterViewInit() {
setTimeout(() => {
this.telemetryImpression = {
context: {
env: 'user-type'
},
edata: {
type: 'view',
pageid: 'user-type-popup',
uri: this.router.url,
duration: this.navigationHelperService.getPageLoadTime()
}
};
});
}
selectUserType(selectedGuest: IGuest) {
this.selectedUserType = selectedGuest;
this.guestList.forEach(guest => {
guest.isActive = guest === selectedGuest;
});
}
submit() {
const { code } = this.selectedUserType;
localStorage.setItem('userType', code);
if (this.userService.loggedIn) {
this.updateUserSelection$.next(code);
} else {
const { name } = this.selectedUserType;
localStorage.setItem('guestUserType', name);
this.userSelect.emit(true);
}
this.logAuditEvent(code);
}
logAuditEvent(code: any) {
const auditEventInput: IAuditEventInput = {
'context': {
'env': 'onboarding',
'cdata': [
{ id: code, type: 'UserType' },
]
},
'object': {
'id': code,
'type': '',
'ver': ''
},
'edata': {
'state': 'Updated',
'props': [
'profile_type'
],
'type': 'set-usertype',
'prevstate': 'set-usertype',
}
};
this.telemetryService.audit(auditEventInput);
}
setPopupInteractEdata() {
this.userSelectionInteractEdata = {
id: 'user-type-select',
type: 'click',
pageid: _.get(this.activatedRoute, 'snapshot.data.telemetry.pageid') || this.router.url.split('/')[1]
};
}
ngOnDestroy() {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
}
<div class="sb-mat__modal" [appTelemetryImpression]="telemetryImpression">
<div mat-dialog-title class="flex-jc-center">
<div class="sb-onboard__header">
<img [src]="tenantInfo?.logo" class="brand-logo" height="40"
alt="{{resourceService?.frmelmnts?.lbl?.welcomeToInstance | interpolate:'{instance}': tenantInfo?.titleName}}" />
<h1 class="mb-0">{{resourceService?.frmelmnts?.lbl?.welcomeToInstance | interpolate:'{instance}': tenantInfo?.titleName}}
</h1>
</div>
</div>
<mat-dialog-content>
<div class="sb-mat__modal__content">
<div class="animation">
<div class="sb-onbrd-g-box px-32 pb-32">
<p class="subtitle" id="SelectUser">{{resourceService?.frmelmnts?.lbl?.youAre}}</p>
<div class="sb-onbrd-g-box__guest" role="radiogroup" attr.aria-labelledby="SelectUser">
<div *ngFor="let guest of guestList; let index=index;" class="sb-onbrd-g-box__guest__item"
[ngClass]="{'active': guest?.isActive}" role="radio" attr.aria-label="{{guest?.label}} Selected"
[attr.aria-checked]="guest?.isActive" [attr.aria-selected]="guest?.isActive"
(click)="selectUserType(guest)" tabindex="0">
<div class="p-16">
<img [src]="guest?.icon" alt="{{guest?.label}}" />
<img src="assets/images/round-check2.svg" class="check-icon" alt="check-mark" />
<div class="title mt-4">{{guest?.label}}</div>
</div>
</div>
</div>
</div>
</div>
</div>
</mat-dialog-content>
<mat-dialog-actions class="mb-0 sb-mat__modal__actions flex-jc-center">
<div class="sb-onboard__footer">
<button type="button" *ngIf="selectedUserType" class="sb-btn sb-btn-sm sb-btn-primary text-uppercase w-100"
type="submit" (click)="submit()" tabindex="0" appTelemetryInteract
[telemetryInteractEdata]="userSelectionInteractEdata">
{{resourceService?.frmelmnts?.lbl?.continue}}
<span class='arrow-icon'>
<em class="icon-svg icon-svg--xxs icon-back">
<svg class="icon icon-svg--white">
<use xlink:href="assets/images/sprite.svg#arrow-long-right"></use>
</svg>
</em>
</span>
</button>
</div>
</mat-dialog-actions>
</div>
<!--
<div class="sb-onboard" [appTelemetryImpression]="telemetryImpression">
<div class="sb-onboard__container">
<div class="sb-onboard__header">
<img [src]="tenantInfo?.logo" class="brand-logo"
alt="{{resourceService?.frmelmnts?.lbl?.welcomeToInstance | interpolate:'{instance}': tenantInfo?.titleName}}" />
<h1>{{resourceService?.frmelmnts?.lbl?.welcomeToInstance | interpolate:'{instance}': tenantInfo?.titleName}}</h1>
</div>
<div class="sb-onboard__content">
<div class="animation">
<div class="sb-onbrd-g-box px-32 pb-32">
<p class="subtitle" id="SelectUser">{{resourceService?.frmelmnts?.lbl?.youAre}}</p>
<div class="sb-onbrd-g-box__guest" role="radiogroup" attr.aria-labelledby="SelectUser">
<div *ngFor="let guest of guestList; let index=index;" class="sb-onbrd-g-box__guest__item"
[ngClass]="{'active': guest?.isActive}" role="radio" attr.aria-label="{{guest?.label}} Selected"
[attr.aria-checked]="guest?.isActive" [attr.aria-selected]="guest?.isActive"
(click)="selectUserType(guest)" tabindex="0">
<div class="p-16">
<img [src]="guest?.icon" alt="{{guest?.label}}" />
<img src="assets/images/round-check2.svg" class="check-icon" alt="check-mark" />
<div class="title mt-4">{{guest?.label}}</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sb-onboard__footer">
<button type="button" *ngIf="selectedUserType" class="sb-btn sb-btn-sm sb-btn-primary text-uppercase w-100"
type="submit" (click)="submit()" tabindex="0" appTelemetryInteract
[telemetryInteractEdata]="userSelectionInteractEdata">
{{resourceService?.frmelmnts?.lbl?.continue}}
<span class='arrow-icon'>
<em class="icon-svg icon-svg--xxs icon-back">
<svg class="icon icon-svg--white">
<use xlink:href="assets/images/sprite.svg#arrow-long-right"></use>
</svg>
</em>
</span>
</button>
</div>
</div>
</div> -->
./onboarding-user-selection.component.scss
@use './../user-onboarding/user-onboarding.component.scss' as *;