From badf031cbbd93e3543e2c0e5d34a50385642d539 Mon Sep 17 00:00:00 2001 From: "christopher.fernandes" Date: Mon, 4 Jul 2022 20:03:44 +0530 Subject: [PATCH] Task #58821: Reverting signup changes for hirarchy fields --- .../public-signup.component.html | 116 +------- .../public-signup/public-signup.component.ts | 247 ++++-------------- .../public/public-signup/signup.service.ts | 24 +- 3 files changed, 58 insertions(+), 329 deletions(-) diff --git a/src/app/routes/public/public-signup/public-signup.component.html b/src/app/routes/public/public-signup/public-signup.component.html index dfc22659c..c0f594773 100644 --- a/src/app/routes/public/public-signup/public-signup.component.html +++ b/src/app/routes/public/public-signup/public-signup.component.html @@ -166,116 +166,6 @@

- - - - Center - - - State - - -
-
- - - - - {{typeValueStartCase}} is mandatory - - - You must enter value from suggested list only. - - - - - {{ option.orgname }} - - -
- -
- - - - - Department is mandatory - - - You must enter value from suggested list only. - - - - - {{ option.orgname }} - - -
- -
- - - - - Organisation is mandatory - - - You must enter value from suggested list only. - - - - - {{ option.orgname }} - - -
- +
@@ -341,4 +231,4 @@

- + \ No newline at end of file diff --git a/src/app/routes/public/public-signup/public-signup.component.ts b/src/app/routes/public/public-signup/public-signup.component.ts index 5db1135a0..6665e900f 100644 --- a/src/app/routes/public/public-signup/public-signup.component.ts +++ b/src/app/routes/public/public-signup/public-signup.component.ts @@ -9,8 +9,6 @@ import { MatSnackBar, MatDialog } from '@angular/material' import { ReCaptchaV3Service } from 'ng-recaptcha' import { SignupSuccessDialogueComponent } from './signup-success-dialogue/signup-success-dialogue/signup-success-dialogue.component' import { DOCUMENT, isPlatformBrowser } from '@angular/common' -// tslint:disable-next-line: import-name -import _ from 'lodash' export function forbiddenNamesValidator(optionsArray: any): ValidatorFn { return (control: AbstractControl): { [key: string]: any } | null => { @@ -63,11 +61,6 @@ export class PublicSignupComponent implements OnInit, OnDestroy { telemetryConfig: NsInstanceConfig.ITelemetryConfig | null = null portalID = '' confirm = false - disableBtn = false - ministeries: any[] = [] - masterMinisteries!: Observable | undefined - orgs: any[] = [] - masterOrgs!: Observable | undefined private subscriptionContact: Subscription | null = null private recaptchaSubscription!: Subscription @@ -87,18 +80,14 @@ export class PublicSignupComponent implements OnInit, OnDestroy { lastname: new FormControl('', [Validators.required, Validators.pattern(this.namePatern)]), position: new FormControl('', [Validators.required, forbiddenNamesValidatorPosition(this.masterPositions)]), email: new FormControl('', [Validators.required, Validators.pattern(this.emailWhitelistPattern)]), - // department: new FormControl('', [Validators.required, forbiddenNamesValidator(this.masterDepartments)]), + department: new FormControl('', [Validators.required, forbiddenNamesValidator(this.masterDepartments)]), confirmBox: new FormControl(false, [Validators.required]), - type: new FormControl('ministry', [Validators.required]), - ministry: new FormControl('', [Validators.required, forbiddenNamesValidator(this.masterMinisteries)]), - department: new FormControl('', [forbiddenNamesValidator(this.masterDepartments)]), - organisation: new FormControl('', [forbiddenNamesValidator(this.masterOrgs)]), // recaptchaReactive: new FormControl(null, [Validators.required]), }) } ngOnInit() { - this.fetchDropDownValues('ministry') + this.fetchDepartments() const instanceConfig = this.configSvc.instanceConfig this.positionsOriginal = this.configSvc.positions || [] this.onPositionsChange() @@ -110,109 +99,39 @@ export class PublicSignupComponent implements OnInit, OnDestroy { if (isPlatformBrowser(this._platformId)) { this._document.body.classList.add('cs-recaptcha') } - - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('type')!.valueChanges.subscribe((value: any) => { - if (value) { - this.fetchDropDownValues(value) - } - }) - } - - get typeValueStartCase() { - // tslint:disable-next-line: no-non-null-assertion - return _.startCase(this.registrationForm.get('type')!.value) } - get typeValue() { - // tslint:disable-next-line: no-non-null-assertion - return this.registrationForm.get('type')!.value - } - - fetchDropDownValues(type: string) { - this.clearValues() - if (type === 'state') { - this.signupSvc.getStatesOrMinisteries('state').subscribe(res => { - if (res && res.result && res.result && res.result.response && res.result.response.content) { - this.ministeries = res.result.response.content - this.onMinisteriesChange() + fetchDepartments() { + this.signupSvc.getDepartments().subscribe( + (res: any) => { + if (res && res.result) { + this.masterDepartmentsOriginal = res.result.content + this.onDepartmentsChange() } - }) - } - if (type === 'ministry') { - this.signupSvc.getStatesOrMinisteries('ministry').subscribe(res => { - if (res && res.result && res.result && res.result.response && res.result.response.content) { - this.ministeries = res.result.response.content - this.onMinisteriesChange() - } - }) - } - } - - clearValues() { - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('ministry')!.setValue('') - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('department')!.setValue('') - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('organisation')!.setValue('') + }, + (err: any) => { + this.loggerSvc.error('USER RATING FETCH ERROR >', err) + } + ) } - onMinisteriesChange() { - // tslint:disable-next-line: no-non-null-assertion - this.masterMinisteries = this.registrationForm.get('ministry')!.valueChanges - .pipe( - debounceTime(500), - distinctUntilChanged(), - startWith(''), - map(value => typeof (value) === 'string' ? value : (value && value.orgname ? value.orgname : '')), - map(orgname => orgname ? this.filterMinisteries(orgname) : this.ministeries.slice()) - ) - - this.masterMinisteries.subscribe((event: any) => { - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('ministry')!.setValidators([Validators.required, forbiddenNamesValidator(event)]) - this.registrationForm.updateValueAndValidity() - }) - } + onDepartmentsChange(): void { - onDepartmentChange() { // tslint:disable-next-line: no-non-null-assertion this.masterDepartments = this.registrationForm.get('department')!.valueChanges .pipe( debounceTime(500), distinctUntilChanged(), startWith(''), - map(value => typeof (value) === 'string' ? value : (value && value.orgname ? value.orgname : '')), - map(orgname => orgname ? this.filterDepartments(orgname) : this.departments.slice()) - ) - - this.masterDepartments.subscribe((event: any) => { - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('department')!.setValidators([forbiddenNamesValidator(event)]) - // tslint:disable-next-line: no-non-null-assertion - // this.registrationForm.get('department')!.setValidators(null) - this.registrationForm.updateValueAndValidity() - }) - } - onOrgsChange() { - // tslint:disable-next-line: no-non-null-assertion - this.masterOrgs = this.registrationForm.get('organisation')!.valueChanges - .pipe( - debounceTime(500), - distinctUntilChanged(), - startWith(''), - map(value => typeof (value) === 'string' ? value : (value && value.orgname ? value.orgname : '')), - map(orgname => orgname ? this.filterOrgs(orgname) : this.orgs.slice()) + map(value => typeof (value) === 'string' ? value : (value && value.name ? value.name : '')), + map(name => name ? this.filterDepartments(name) : this.masterDepartmentsOriginal.slice()) ) - this.masterOrgs.subscribe((event: any) => { - // tslint:disable-next-line: no-non-null-assertion - this.registrationForm.get('organisation')!.setValidators([forbiddenNamesValidator(event)]) - // tslint:disable-next-line: no-non-null-assertion - // this.registrationForm.get('organisation')!.setValidators(null) - this.registrationForm.updateValueAndValidity() - }) + this.masterDepartments.subscribe((event: any) => { + // tslint:disable-next-line: no-non-null-assertion + this.registrationForm.get('department')!.setValidators([Validators.required, forbiddenNamesValidator(event)]) + this.registrationForm.updateValueAndValidity() + }) } onPositionsChange() { @@ -233,28 +152,12 @@ export class PublicSignupComponent implements OnInit, OnDestroy { }) } - filterMinisteries(orgname: string) { - if (orgname) { - const filterValue = orgname.toLowerCase() - return this.ministeries.filter((option: any) => option.orgname.toLowerCase().includes(filterValue)) - } - return this.ministeries - } - - filterDepartments(orgname: string) { - if (orgname) { - const filterValue = orgname.toLowerCase() - return this.departments.filter((option: any) => option.orgname.toLowerCase().includes(filterValue)) - } - return this.departments - } - - filterOrgs(orgname: string) { - if (orgname) { - const filterValue = orgname.toLowerCase() - return this.orgs.filter((option: any) => option.orgname.toLowerCase().includes(filterValue)) + private filterDepartments(name: string): any { + if (name) { + const filterValue = name.toLowerCase() + return this.masterDepartmentsOriginal.filter((option: any) => option.channel.toLowerCase().includes(filterValue)) } - return this.orgs + return this.masterDepartmentsOriginal } private filterPositions(name: string): any { @@ -272,6 +175,19 @@ export class PublicSignupComponent implements OnInit, OnDestroy { }) } + ngOnDestroy() { + if (this.subscriptionContact) { + this.subscriptionContact.unsubscribe() + } + if (this.recaptchaSubscription) { + this.recaptchaSubscription.unsubscribe() + } + + if (isPlatformBrowser(this._platformId)) { + this._document.body.classList.remove('cs-recaptcha') + } + } + displayFn = (value: any) => { return value ? value.channel : undefined } @@ -281,43 +197,22 @@ export class PublicSignupComponent implements OnInit, OnDestroy { } signup() { - this.disableBtn = true + this.recaptchaSubscription = this.recaptchaV3Service.execute('importantAction') .subscribe( _token => { // tslint:disable-next-line: no-console console.log('captcha validation success') - // to get the org details from either ministry/state, or department or organisation which ever user has filled - let hierarchyObj - let req: any - if (this.registrationForm.value.ministry) { - hierarchyObj = this.registrationForm.value.ministry - if (this.registrationForm.value.department) { - hierarchyObj = this.registrationForm.value.department - if (this.registrationForm.value.organisation) { - hierarchyObj = this.registrationForm.value.organisation - } - } - } - // console.log('hierarchyObj: ', hierarchyObj) - if (hierarchyObj) { - req = { - firstName: this.registrationForm.value.firstname || '', - lastName: this.registrationForm.value.lastname || '', - email: this.registrationForm.value.email || '', - // deptId: this.registrationForm.value.department.identifier || '', - // deptName: this.registrationForm.value.department.channel || '', - position: this.registrationForm.value.position.name || '', - source: `${environment.name}.${this.portalID}` || '', - orgName: hierarchyObj.orgname || '', - channel: hierarchyObj.orgname || '', - organisationType: hierarchyObj.sborgtype || '', - organisationSubType: hierarchyObj.sbsuborgtype || '', - mapId: hierarchyObj.mapid || '', - sbRootOrgId: hierarchyObj.sbrootorgid, - sbOrgId: hierarchyObj.sborgid, - } + // perform signup operations + const req = { + firstName: this.registrationForm.value.firstname || '', + lastName: this.registrationForm.value.lastname || '', + email: this.registrationForm.value.email || '', + deptId: this.registrationForm.value.department.identifier || '', + deptName: this.registrationForm.value.department.channel || '', + position: this.registrationForm.value.position.name || '', + source: `${environment.name}.${this.portalID}` || '', } // console.log('req: ', req) @@ -326,10 +221,8 @@ export class PublicSignupComponent implements OnInit, OnDestroy { (_res: any) => { // console.log('success', res) this.openDialog() - this.disableBtn = false }, (err: any) => { - this.disableBtn = false this.loggerSvc.error('Error in registering new user >', err) if (err.error && err.error.params && err.error.params.errmsg) { this.openSnackbar(err.error.params.errmsg) @@ -341,7 +234,6 @@ export class PublicSignupComponent implements OnInit, OnDestroy { ) }, error => { - this.disableBtn = false // tslint:disable-next-line: no-console console.error('captcha validation error', error) this.openSnackbar(`reCAPTCHA validation failed: ${error}`) @@ -364,43 +256,4 @@ export class PublicSignupComponent implements OnInit, OnDestroy { dialogRef.afterClosed().subscribe((_result: any) => { }) } - - ministrySelected(value: any) { - if (value && value.mapid) { - this.signupSvc.getDeparmentsOfState(value.mapid).subscribe(res => { - if (res && res.result && res.result && res.result.response && res.result.response.content) { - this.departments = res.result.response.content - this.onDepartmentChange() - } - }) - } - } - - departmentSelected(value: any) { - if (value && value.mapid) { - this.signupSvc.getOrgsOfDepartment(value.mapid).subscribe(res => { - if (res && res.result && res.result && res.result.response && res.result.response.content) { - this.orgs = res.result.response.content - this.onOrgsChange() - } - }) - } - } - - displayFnState = (value: any) => { - return value ? value.orgname : undefined - } - - ngOnDestroy() { - if (this.subscriptionContact) { - this.subscriptionContact.unsubscribe() - } - if (this.recaptchaSubscription) { - this.recaptchaSubscription.unsubscribe() - } - - if (isPlatformBrowser(this._platformId)) { - this._document.body.classList.remove('cs-recaptcha') - } - } -} +} \ No newline at end of file diff --git a/src/app/routes/public/public-signup/signup.service.ts b/src/app/routes/public/public-signup/signup.service.ts index e4dc4343e..d10673278 100644 --- a/src/app/routes/public/public-signup/signup.service.ts +++ b/src/app/routes/public/public-signup/signup.service.ts @@ -3,11 +3,8 @@ import { Observable } from 'rxjs' import { HttpClient } from '@angular/common/http' const API_END_POINTS = { - // GET_DEPARTMENTS: `/api/user/registration/v1/getDeptDetails`, + GET_DEPARTMENTS: `/api/user/registration/v1/getDeptDetails`, REGISTER: `/api/user/registration/v1/register`, - GET_ALL_STATES: '/apis/public/v8/org/v1/list', - GET_DEPARTMENTS_OF_STATE: '/apis/public/v8/org/v1/list', - GET_ORGS_OF_DEPT: '/apis/public/v8/org/v1/list', } @Injectable({ @@ -17,24 +14,13 @@ export class SignupService { constructor(private http: HttpClient) { } - // getDepartments(): Observable { - // return this.http.get(API_END_POINTS.GET_DEPARTMENTS) - // } + getDepartments(): Observable { + return this.http.get(API_END_POINTS.GET_DEPARTMENTS) + } register(req: any) { return this.http.post( API_END_POINTS.REGISTER, req ) } - - getStatesOrMinisteries(type: string): Observable { - return this.http.get(`${API_END_POINTS.GET_ALL_STATES}/${type}`) - } - getDeparmentsOfState(stateId: string): Observable { - return this.http.get(`${API_END_POINTS.GET_DEPARTMENTS_OF_STATE}/${stateId}`) - } - getOrgsOfDepartment(deptId: string): Observable { - return this.http.get(`${API_END_POINTS.GET_ORGS_OF_DEPT}/${deptId}`) - } - -} +} \ No newline at end of file