Skip to content

Commit

Permalink
Issue #SH-429 merge: Merge pull request #1035 from NavKumarV/release-…
Browse files Browse the repository at this point in the history
…3.1.0

Issue #SH-429 fix: Issue for self declaration form
  • Loading branch information
swayangjit authored Jul 7, 2020
2 parents bb495c1 + 3aca7a0 commit a5a0e44
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 33 deletions.
7 changes: 1 addition & 6 deletions src/app/components/common-forms/common-forms.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ export class CommonFormsComponent implements OnInit, OnChanges, OnDestroy, After
constructor(
private formBuilder: FormBuilder,
private commonUtilService: CommonUtilService
) {
if (!window['forms']) {
window['forms'] = [];
}
window['forms'].push(this);
}
) { }
ngOnDestroy(): void {
this.finalize.emit();
if (this.statusChangesSubscription) {
Expand Down
16 changes: 13 additions & 3 deletions src/app/profile/profile.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,28 @@
<div class="bolder">{{selfDeclaredTeacherDetails?.district}}</div>
</div>

<div class="container" *ngIf = "selfDeclaredTeacherDetails?.mobile">
<div>{{'PHONE_PLACEHOLDER' | translate }}:</div>
<div class="bolder">{{selfDeclaredTeacherDetails?.mobile}}</div>
</div>

<div class="container" *ngIf = "selfDeclaredTeacherDetails?.email">
<div>{{'EMAIL_ID_PLACEHOLDER' | translate }}:</div>
<div class="bolder">{{selfDeclaredTeacherDetails?.email}}</div>
</div>

<div class="container" *ngIf = "selfDeclaredTeacherDetails?.schoolName">
<div>{{'SCHOOL_OR_ORG_NAME' | translate }}</div>
<div>{{'SCHOOL_OR_ORG_NAME' | translate }}:</div>
<div class="bolder">{{selfDeclaredTeacherDetails?.schoolName}}</div>
</div>

<div class="container" *ngIf = "selfDeclaredTeacherDetails?.udiseId">
<div>{{'SCHOOL_UDISE_ID_OR_ORG_ID' | translate }}</div>
<div>{{'SCHOOL_UDISE_ID_OR_ORG_ID' | translate }}:</div>
<div class="bolder">{{selfDeclaredTeacherDetails?.udiseId}}</div>
</div>

<div class="container" *ngIf = "selfDeclaredTeacherDetails?.teacherId">
<div>{{'YOUR_ID_FROM_STATE_BOARD_ORG' | translate }}</div>
<div>{{'YOUR_ID_FROM_STATE_BOARD_ORG' | translate }}:</div>
<div class="bolder">{{selfDeclaredTeacherDetails?.teacherId}}</div>
</div>

Expand Down
6 changes: 6 additions & 0 deletions src/app/profile/profile.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,12 @@ export class ProfilePage implements OnInit {
case 'declared-district':
districtCode = ele.id;
break;
case 'declared-phone':
this.selfDeclaredTeacherDetails.mobile = ele.id;
break;
case 'declared-email':
this.selfDeclaredTeacherDetails.email = ele.id;
break;
case 'declared-school-name':
this.selfDeclaredTeacherDetails.schoolName = ele.id;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { distinctUntilChanged, switchMap, tap } from 'rxjs/operators';
export class SelfDeclaredTeacherEditPage {

private profile: ServerProfile;
private initialExternalIds: any;
private initialExternalIds: any = {};
private backButtonFunc: Subscription;
private availableLocationDistrict: string;
private availableLocationState: string;
Expand Down Expand Up @@ -106,10 +106,10 @@ export class SelfDeclaredTeacherEditPage {

async ionViewDidEnter() {
this.appName = await this.appVersion.getAppName();
this.getTeacherDetailsFormApi();
this.getTeacherDetailsFormApi(undefined, false);
}

async getTeacherDetailsFormApi(rootOrgId?) {
async getTeacherDetailsFormApi(rootOrgId?, isFormLoaded?) {

const req: FormRequest = {
from: CachedItemRequestSourceFrom.SERVER,
Expand All @@ -129,7 +129,7 @@ export class SelfDeclaredTeacherEditPage {
if (formData && formData.form && formData.form.data) {
const formConfig = formData.form.data.fields;
if (formConfig.length) {
this.initializeFormData(formConfig, !!rootOrgId);
this.initializeFormData(formConfig, isFormLoaded);
}
}

Expand All @@ -143,7 +143,7 @@ export class SelfDeclaredTeacherEditPage {
});
}

async initializeFormData(formConfig, formLoaded) {
async initializeFormData(formConfig, isFormLoaded) {

this.teacherDetailsForm = formConfig.map((config: FieldConfig<any>) => {
if (config.code === 'externalIds' && config.children) {
Expand All @@ -161,30 +161,56 @@ export class SelfDeclaredTeacherEditPage {
}
stateCode = stateDetails && stateDetails.id;
}
childConfig.templateOptions.options = this.buildStateListClosure(stateCode);
if (!isFormLoaded) {
this.initialExternalIds[childConfig.code] = stateCode;
}
childConfig.templateOptions.options = this.buildStateListClosure(stateCode, isFormLoaded);
} else if (childConfig.templateOptions['dataSrc'].params.id === 'district') {
let districtDetails;
if (this.profile.externalIds && this.profile.externalIds.length) {
districtDetails = this.profile.externalIds.find(eId => eId.idType === childConfig.code);
}
childConfig.templateOptions.options = this.buildDistrictListClosure(districtDetails && districtDetails.id, formLoaded);

if (!isFormLoaded) {
this.initialExternalIds[childConfig.code] = districtDetails && districtDetails.id;
}
childConfig.templateOptions.options = this.buildDistrictListClosure(districtDetails && districtDetails.id, isFormLoaded);
}
return childConfig;
}

if (childConfig.asyncValidation) {
childConfig = this.assignDefaultValue(childConfig, isFormLoaded);

if (childConfig.asyncValidation.marker === 'MOBILE_OTP_VALIDATION') {
const telemetryData = {
type: InteractType.TOUCH,
subType: '',
env: Environment.USER,
pageId: PageId.TEACHER_SELF_DECLARATION,
id: ID.VALIDATE_MOBILE
};
childConfig.asyncValidation.asyncValidatorFactory =
this.formValidationAsyncFactory.mobileVerificationAsyncFactory(childConfig, this.profile);
this.formValidationAsyncFactory.mobileVerificationAsyncFactory(
childConfig, this.profile, this.initialExternalIds[childConfig.code], telemetryData
);
} else if (childConfig.asyncValidation.marker === 'EMAIL_OTP_VALIDATION') {
const telemetryData = {
type: InteractType.TOUCH,
subType: '',
env: Environment.USER,
pageId: PageId.TEACHER_SELF_DECLARATION,
id: ID.VALIDATE_EMAIL
};
childConfig.asyncValidation.asyncValidatorFactory =
this.formValidationAsyncFactory.emailVerificationAsyncFactory(childConfig, this.profile);
this.formValidationAsyncFactory.emailVerificationAsyncFactory(
childConfig, this.profile, this.initialExternalIds[childConfig.code], telemetryData
);
}
childConfig = this.assignDefaultValue(childConfig, formLoaded);
return childConfig;
}

this.assignDefaultValue(childConfig, formLoaded);
this.assignDefaultValue(childConfig, isFormLoaded);

return childConfig;
});
Expand All @@ -208,8 +234,8 @@ export class SelfDeclaredTeacherEditPage {

}

private assignDefaultValue(childConfig: FieldConfig<any>, formLoaded) {
if (formLoaded) {
private assignDefaultValue(childConfig: FieldConfig<any>, isFormLoaded) {
if (isFormLoaded) {
if (this.latestFormValue && this.latestFormValue.children.externalIds) {
childConfig.default = this.latestFormValue.children.externalIds[childConfig.code];
}
Expand All @@ -232,6 +258,10 @@ export class SelfDeclaredTeacherEditPage {
childConfig.default = this.profile['maskedEmail'];
}
}

if (!isFormLoaded) {
this.initialExternalIds[childConfig.code] = childConfig.default || undefined;
}
return childConfig;
}

Expand Down Expand Up @@ -516,7 +546,7 @@ export class SelfDeclaredTeacherEditPage {
};
}

private buildDistrictListClosure(districtCode?, formLoaded?): FieldConfigOptionsBuilder<string> {
private buildDistrictListClosure(districtCode?, isFormLoaded?): FieldConfigOptionsBuilder<string> {
return (formControl: FormControl, contextFormControl: FormControl, notifyLoading, notifyLoaded) => {
if (!contextFormControl) {
return of([]);
Expand Down Expand Up @@ -554,8 +584,7 @@ export class SelfDeclaredTeacherEditPage {
formDistrictList.push({ label: districtData.name, value: districtData.code });
});

if (!formLoaded) {

if (!isFormLoaded) {
if (this.editType === 'add' && this.availableLocationDistrict) {
selectedDistrict = this.districtList.find(s =>
(s.name === this.availableLocationDistrict)
Expand Down Expand Up @@ -597,7 +626,7 @@ export class SelfDeclaredTeacherEditPage {
if (event.children.externalIds['declared-state'] && this.selectedStateCode && this.selectedStateCode !== event.children.externalIds['declared-state']) {
this.selectedStateCode = event.children.externalIds['declared-state'];
const selectedState = this.getStateIdFromCode(this.selectedStateCode);
this.getTeacherDetailsFormApi(selectedState && selectedState.id);
this.getTeacherDetailsFormApi(selectedState && selectedState.id, true);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -795,5 +795,6 @@
"SEARCH_FOR_GROUP_MEMBER": "Search for group member",
"PRIVACY_POLICY": "Privacy Policy",
"SELF_DECLARE_TEACHER_TNC": "I agree to share these details with the Administrators of",
"AS_PER_THE": "as per the"
"AS_PER_THE": "as per the",
"SPECIAL_CHARACTERS_NOT_SUPPORTED": "Special characters not supported"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@ import { ProfileConstants } from '@app/app/app.constant';
import { CommonUtilService } from '../common-util.service';
import { EditContactVerifyPopupComponent } from '@app/app/components/popups/edit-contact-verify-popup/edit-contact-verify-popup.component';
import { FieldConfig } from '@app/app/components/common-forms/field-config';
import { TelemetryGeneratorService } from '../telemetry-generator.service';

@Injectable({ providedIn: 'root' })
export class FormValidationAsyncFactory {

constructor(
@Inject('PROFILE_SERVICE') private profileService: ProfileService,
private commonUtilService: CommonUtilService,
private popoverCtrl: PopoverController
private popoverCtrl: PopoverController,
private telemetryGeneratorService: TelemetryGeneratorService,
) { }

mobileVerificationAsyncFactory(formElement: FieldConfig<any>, profile: ServerProfile) {
mobileVerificationAsyncFactory(formElement: FieldConfig<any>, profile: ServerProfile, initialMobileVal, telemetryData?) {
return (marker: string, triggers: QueryList<any>) => {
if (marker === 'MOBILE_OTP_VALIDATION') {
return async (control: FormControl) => {
if (control && !control.value) {
if ((control && !control.value) || (initialMobileVal && initialMobileVal === control.value)) {
return null;
}
return new Promise<ValidationErrors | null>(resolve => {
const trigger: IonButton = triggers.find(e => e['el'].getAttribute('data-marker') === 'MOBILE_OTP_VALIDATION');
if (trigger) {
const that = this;
trigger['el'].onclick = (async () => {
if (telemetryData) {
this.generateTelemetryInteract(telemetryData);
}
try {
const isOtpVerified: boolean = await that.generateAndVerifyOTP(profile, control, ProfileConstants.CONTACT_TYPE_PHONE);
if (isOtpVerified) {
Expand All @@ -49,18 +54,21 @@ export class FormValidationAsyncFactory {
};
}

emailVerificationAsyncFactory(formElement: FieldConfig<any>, profile: ServerProfile) {
emailVerificationAsyncFactory(formElement: FieldConfig<any>, profile: ServerProfile, initialEmailVal, telemetryData?) {
return (marker: string, triggers: QueryList<any>) => {
if (marker === 'EMAIL_OTP_VALIDATION') {
return async (control: FormControl) => {
if (control && !control.value) {
if ((control && !control.value) || (initialEmailVal && initialEmailVal === control.value)) {
return null;
}
return new Promise<ValidationErrors | null>(resolve => {
const trigger: IonButton = triggers.find(e => e['el'].getAttribute('data-marker') === 'EMAIL_OTP_VALIDATION');
if (trigger) {
const that = this;
trigger['el'].onclick = (async () => {
if (telemetryData) {
this.generateTelemetryInteract(telemetryData);
}
try {
const isOtpVerified: boolean = await that.generateAndVerifyOTP(profile, control, ProfileConstants.CONTACT_TYPE_EMAIL);
if (isOtpVerified) {
Expand Down Expand Up @@ -161,4 +169,18 @@ export class FormValidationAsyncFactory {
return data;
}

private generateTelemetryInteract(telemetryData) {
this.telemetryGeneratorService.generateInteractTelemetry(
telemetryData.type,
telemetryData.subType,
telemetryData.env,
telemetryData.pageId,
undefined,
undefined,
undefined,
undefined,
telemetryData.id
);
}

}
4 changes: 3 additions & 1 deletion src/services/telemetry-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ export enum ID {
BTN_I_AM_A_TEACHER = 'btn-i-am-a-teacher',
TEACHER_DECLARATION = 'teacher-declaration',
MUA_USER_CREATION = 'mua-user-creation',
DATA_SHARING = 'data-sharing'
DATA_SHARING = 'data-sharing',
VALIDATE_EMAIL = 'validate-email',
VALIDATE_MOBILE = 'validate-mobile'
}

export enum ActionButtonType {
Expand Down

0 comments on commit a5a0e44

Please sign in to comment.