src/app/signup/signup-email-password/signup-email-password.page.ts
OnInit
selector | app-signup-email-password |
styleUrls | ./signup-email-password.page.scss |
templateUrl | ./signup-email-password.page.html |
Properties |
Methods |
constructor(profileService: ProfileService, platform: Platform, commonUtilService: CommonUtilService, router: Router, location: Location)
|
||||||||||||||||||
Parameters :
|
contactTypeChange |
contactTypeChange()
|
Returns :
void
|
Async continue |
continue()
|
Returns :
any
|
Async generateOTP |
generateOTP()
|
Returns :
any
|
goBack |
goBack()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onFormEmailPasswordChange | ||||||
onFormEmailPasswordChange(value: any)
|
||||||
Parameters :
Returns :
void
|
redirectToLogin |
redirectToLogin()
|
Returns :
void
|
Async setappname |
setappname()
|
Returns :
any
|
statusChanges | ||||
statusChanges(event)
|
||||
Parameters :
Returns :
void
|
appName |
Type : string
|
Default value : ''
|
btnColor |
Type : string
|
Default value : '#8FC4FF'
|
contactConfig |
Type : FieldConfig<any>[]
|
Default value : []
|
contactType |
Type : string
|
Default value : 'phone'
|
emailConfig |
Type : FieldConfig<any>[]
|
Default value : []
|
errorConfirmPassword |
Default value : false
|
isFormValid |
Default value : false
|
loader |
Type : any
|
mobileNumberConfig |
Type : FieldConfig<any>[]
|
Default value : []
|
Public platform |
Type : Platform
|
userData |
Type : any
|
userId |
Type : string
|
import { Component, Inject, OnInit } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';
import { ProfileConstants, RouterLinks } from '@app/app/app.constant';
import { CommonUtilService } from '@app/services';
import { Platform, } from '@ionic/angular';
import { IsProfileAlreadyInUseRequest, GenerateOtpRequest, ProfileService } from 'sunbird-sdk';
import { FieldConfig, FieldConfigValidationType } from 'common-form-elements';
import { Location } from '@angular/common';
@Component({
selector: 'app-signup-email-password',
templateUrl: './signup-email-password.page.html',
styleUrls: ['./signup-email-password.page.scss'],
})
export class SignupEmailPasswordPage implements OnInit {
contactType = 'phone';
appName = '';
mobileNumberConfig: FieldConfig<any>[] = [];
emailConfig: FieldConfig<any>[] = [];
// passwordConfig: FieldConfig<any>[] = [];
contactConfig: FieldConfig<any>[] = [];
isFormValid = false;
errorConfirmPassword = false;
loader: any;
userId: string;
userData: any;
btnColor = '#8FC4FF';
constructor(
@Inject('PROFILE_SERVICE') private profileService: ProfileService,
public platform: Platform,
private commonUtilService: CommonUtilService,
private router: Router,
private location: Location
) {
const extrasState = this.router.getCurrentNavigation().extras.state;
this.userData = extrasState.userData;
}
ngOnInit() {
this.contactType = 'phone';
this.mobileNumberConfig = [{
code: 'phone',
type: 'input',
templateOptions: {
type: 'tel',
label: '',
placeHolder: this.commonUtilService.translateMessage('ENTER_PHONE_POPUP_TITLE'),
},
validations: [{
type: FieldConfigValidationType.REQUIRED,
value: null,
message: this.commonUtilService.translateMessage('FRMELEMNTS_LBL_CONFIRM_CONTACT_VALIDATION')
},
{
type: FieldConfigValidationType.PATTERN,
value: /^[6-9]\d{9}$/,
message: this.commonUtilService.translateMessage('FRMELEMNTS_LBL_CONTACT_PATTERN_VALIDATION')
}]
}];
this.contactConfig = this.mobileNumberConfig;
this.setappname()
}
async setappname() {
this.appName = await this.commonUtilService.getAppName();
}
contactTypeChange() {
if (this.contactType === 'email') {
this.emailConfig = [{
code: 'email',
type: 'input',
templateOptions: {
type: 'email',
label: '',
placeHolder: this.commonUtilService.translateMessage('FRMELEMNTS_LBL_ENTER_EMAIL'),
},
validations: [{
type: FieldConfigValidationType.REQUIRED,
value: null,
message: this.commonUtilService.translateMessage('FRMELEMNTS_LBL_CONFIRM_EMAIL_VALIDATION')
},
{
type: FieldConfigValidationType.PATTERN,
value: /^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,}$/,
message: this.commonUtilService.translateMessage('FRMELEMNTS_LBL_CONFIRM_EMAIL_PATTERN_VALIDATION')
}]
}];
this.contactConfig = this.emailConfig;
} else if (this.contactType === 'phone') {
this.contactConfig = this.mobileNumberConfig;
}
}
async continue() {
if (this.commonUtilService.networkInfo.isNetworkAvailable) {
this.loader = await this.commonUtilService.getLoader();
await this.loader.present();
let req: IsProfileAlreadyInUseRequest;
if (this.contactType === ProfileConstants.CONTACT_TYPE_PHONE) {
req = {
key: this.userData.contactInfo.phone,
type: ProfileConstants.CONTACT_TYPE_PHONE
};
} else {
req = {
key: this.userData.contactInfo.email,
type: ProfileConstants.CONTACT_TYPE_EMAIL
};
}
this.generateOTP();
if (this.loader) {
await this.loader.dismiss();
this.loader = undefined;
}
} else {
this.commonUtilService.showToast(this.commonUtilService.translateMessage('INTERNET_CONNECTIVITY_NEEDED'));
}
}
async generateOTP() {
let req: GenerateOtpRequest;
if (this.contactType === ProfileConstants.CONTACT_TYPE_PHONE) {
req = {
key: this.userData.contactInfo.phone,
type: ProfileConstants.CONTACT_TYPE_PHONE
};
} else {
req = {
key: this.userData.contactInfo.email,
type: ProfileConstants.CONTACT_TYPE_EMAIL
};
}
this.profileService.generateOTP(req).toPromise()
.then(async () => {
if (this.loader) {
await this.loader.dismiss();
this.loader = undefined;
}
const navigationExtras: NavigationExtras = {
state: {
userData: this.userData
}
};
this.router.navigate([RouterLinks.OTP], navigationExtras);
})
.catch(async (err) => {
if (this.loader) {
await this.loader.dismiss();
this.loader = undefined;
}
if (err.response && err.response.body.params.err === 'UOS_OTPCRT0059') {
this.commonUtilService.showToast(this.commonUtilService.translateMessage('FRMELEMNTS_MSG_OTP_ATTEMPT_LIMIT'));
}
});
}
onFormEmailPasswordChange(value: any) {
this.userData['contactInfo'] = value;
this.userData['contactInfo']['type'] = this.contactType;
}
statusChanges(event) {
this.isFormValid = event.isValid;
}
redirectToLogin() {
this.router.navigate([RouterLinks.SIGN_IN]);
}
goBack() {
this.location.back();
}
}
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button icon-only (click)="goBack()">
<ion-icon class="arrow-icon back-arrow" role="button" aria-label="back" name="arrow-back"></ion-icon>
</ion-button>
</ion-buttons>
<ion-title role="heading" aria-level="1">{{'FRMELEMNTS_LBL_STEP' | translate:{'page_number': '3/4'} }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<div class="sign-up-div">
<div class="header">
<div class="logos">
<img src="assets/imgs/ic_launcher.png" alt="app">
</div>
<div class="ion-padding">
<h1 class="title">{{'APP_TITLE' | translate:{'%s': appName} }}</h1>
<h5 class="subtitle">{{'FRMELEMNTS_LBL_MOBILE_OR_EMAIL' | translate}}</h5>
<span>({{'FRMELEMNTS_LBL_OTP_SENT' | translate}})</span>
</div>
</div>
<ion-radio-group [(ngModel)]="contactType" (ionChange)="contactTypeChange()">
<ion-item lines="none">
<ion-label>{{'PHONE_PLACEHOLDER' | translate}}</ion-label>
<ion-radio slot="start" value="phone" name="contactType"></ion-radio>
</ion-item>
<ion-item lines="none">
<ion-radio slot="start" value="email" name="contactType"></ion-radio>
<ion-text>{{'EMAIL_ID_PLACEHOLDER' | translate }}</ion-text>
</ion-item>
</ion-radio-group>
<div class="emailPasswordForm">
<sb-form *ngIf="contactConfig && contactConfig.length" [config]='contactConfig'
[platform]="'mobile'" (valueChanges)="onFormEmailPasswordChange($event)"
(statusChanges)="statusChanges($event)">
</sb-form>
</div>
<div class="submit-info">
<ion-button expand="block"
[disabled]="!isFormValid" (click)="continue()">
{{'FRMELEMNTS_BTN_SUBMIT' | translate}} <ion-icon class="mg-popup-btn-icon" name="arrow-forward" slot="end"></ion-icon>
</ion-button>
</div>
</div>
</ion-content>
<div class="footer">
<label>{{'HAVE_ACCOUNT' | translate }}</label>
<button class="login-info sb-btn sb-btn-normal sb-btn-outline-primary text-uppercase"
aria-label="Already have an account? Login here" tabindex="0" (click)="redirectToLogin()" type="submit">{{'SIGN_IN'
| translate}}</button>
</div>
./signup-email-password.page.scss
.sign-up-div {
margin-top: 2vh;
.header {
text-align: center;
margin: auto;
.logos {
display: flex;
justify-content: center;
align-items: center;
img {
width: 4rem;
padding: 10px;
}
}
.title {
color: #005A9E;
font-weight: bold;
margin-top: 2px;
}
.subtitle {
font-weight: bold;
color: #333333;
}
}
}
ion-input,
section {
border: 1px solid gray;
border-radius: 16px;
margin: 10px auto;
padding-left: 1rem !important;
}
section {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 0 1rem;
ion-icon {
font-size: 23px;
color: gray;
}
}
ion-radio {
margin: 10px;
}
.important::after {
content: '*';
color: red;
margin-left: 5px;
}
.bold {
font-weight: bold;
}
.flex {
display: flex;
justify-content: space-between;
align-items: center;
}
.start {
justify-content: start;
}
.radiobox div ion-text {
font-size: 13px;
}
ion-radio-group {
width: 100%;
display: flex;
ion-label {
font-size: 13px;
}
}
.danger {
color: red;
font-size: 11px;
margin-top: -10px;
}
.prb-4 {
padding-right: 7rem;
padding-bottom: 4rem;
}
sb-textbox {
.sb-input {
margin: 0 1rem;
border-radius: 10px;
border: 1px solid #8080805c;
padding: 0px 10px;
input {
border: none;
}
}
}
.footer {
background: #F8FAFC;
border-top: 1px solid #d1d6dd;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
position: absolute;
bottom: 0;
width: 100%;
padding: 1rem;
a {
color: #005A9E;
}
}
.submit-info{
padding: 1rem;
}
ion-button{
height: 2.5rem
}