Skip to content

Commit 917434e

Browse files
Merge pull request #110 from Sohith-code/cbrelease-4.8.20-custom-registration-sohith
7516,1514,7527 fix
2 parents f234545 + 3803181 commit 917434e

File tree

3 files changed

+69
-29
lines changed

3 files changed

+69
-29
lines changed

project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.html

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@
3636
</ng-container>
3737
<ng-container *ngIf="openMode !== 'viewMode'; else viewMode">
3838
<form [formGroup]="organisationForm" class="mb-20">
39-
<div class="flex flex-column gap-1 organisation-form mat-field-rounded">
40-
<div class="flex items-center gap-1 required">
41-
<span class="lable">Organisation Name</span>
39+
<ng-container *ngIf="this.openMode !== 'editMode'">
40+
<div class="flex flex-column gap-1 organisation-form mat-field-rounded">
41+
<div class="flex items-center gap-1 required">
42+
<span class="lable">Organisation Name</span>
43+
</div>
44+
<mat-form-field class="w-full">
45+
<input formControlName="organisationName" matInput placeholder="Add organisation name here">
46+
<mat-error *ngIf="controls['organisationName'].errors?.['required']">Organization name is
47+
required.</mat-error>
48+
<mat-error *ngIf="controls['organisationName'].errors?.['duplicateOrgName']">This organization name
49+
is already in use.</mat-error>
50+
</mat-form-field>
4251
</div>
43-
<mat-form-field class="w-full">
44-
<input formControlName="organisationName" matInput placeholder="Add organisation name here">
45-
<mat-error *ngIf="controls['organisationName'].errors?.['required']">Organization name is
46-
required.</mat-error>
47-
</mat-form-field>
48-
</div>
52+
53+
</ng-container>
4954

5055
<ng-container *ngIf="this.openMode !== 'editMode'">
5156
<mat-radio-group aria-labelledby="example-radio-group-label" class="flex gap-12 organisation-form"

project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.ts

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'
2-
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'
2+
import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'
33
import { MatSnackBar } from '@angular/material/snack-bar'
44
import * as _ from 'lodash'
55
import { CreateMDOService } from '../../../routes/home/services/create-mdo.services'
66
import { ActivatedRoute } from '@angular/router'
77
import { LoaderService } from '../../../routes/home/services/loader.service'
88
import { IUploadedLogoresponse } from '../interface/interfaces'
9+
import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators'
10+
import { Subject } from 'rxjs'
911
@Component({
1012
selector: 'ws-app-create-organisation',
1113
templateUrl: './create-organisation.component.html',
@@ -14,6 +16,7 @@ import { IUploadedLogoresponse } from '../interface/interfaces'
1416
export class CreateOrganisationComponent implements OnInit, OnDestroy {
1517

1618
@Input() rowData: any
19+
@Input() orgList: any[] = []
1720
@Input() dropdownList: {
1821
statesList: any[],
1922
ministriesList: any[]
@@ -31,14 +34,17 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
3134
selectedLogo: any
3235
selectedLogoName = ''
3336
validFileTypes = ['image/png', 'image/jpeg', 'image/jpg']
34-
maxFileSize = 500 // In KB
37+
maxFileSize = 5 // In MB
3538
loggedInUserId = ""
3639
isLoading = false
3740
filteredStates: any[] = []
3841
filteredMinistry: any[] = []
3942
heirarchyObject: any
4043
selectedLogoFile: any
4144
uploadedLogoResponse!: IUploadedLogoresponse
45+
organizationNameList: string[] = []
46+
47+
untilDestroyed$ = new Subject<void>();
4248
constructor(
4349
private formBuilder: FormBuilder,
4450
private snackBar: MatSnackBar,
@@ -56,14 +62,18 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
5662
if (this.openMode === 'editMode') {
5763
this.getOrganization(this.rowData.organisation, this.rowData.type.toLowerCase())
5864
}
65+
66+
this.organizationNameList = this.orgList.map(org => org.organisation.trim().toLowerCase())
5967
}
6068

6169
ngOnDestroy(): void {
6270
this.removeOverflowHidden()
71+
72+
this.untilDestroyed$.next()
73+
this.untilDestroyed$.complete()
6374
}
6475

6576
initialization() {
66-
console.log(this.rowData)
6777

6878
if (this.dropdownList) {
6979
this.statesList = _.get(this.dropdownList, 'statesList', [])
@@ -85,6 +95,16 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
8595
this.valueChangeEvents()
8696
}
8797

98+
createDuplicateOrgNameValidator(organizationNameList: string[]) {
99+
return (control: AbstractControl) => {
100+
if (!organizationNameList || !control.value) {
101+
return null
102+
}
103+
const isDuplicate = organizationNameList.includes(control.value.trim().toLowerCase())
104+
return isDuplicate ? { duplicateOrgName: true } : null
105+
}
106+
}
107+
88108
get controls() {
89109
return this.organisationForm.controls
90110
}
@@ -109,22 +129,36 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
109129

110130
valueChangeEvents() {
111131
if (this.organisationForm && this.organisationForm.controls.category) {
112-
this.organisationForm.controls.category.valueChanges.subscribe(val => {
113-
if (val === 'state') {
114-
this.organisationForm.controls.state.setValidators([Validators.required])
115-
this.organisationForm.controls.state.updateValueAndValidity()
116-
this.organisationForm.controls.ministry.setValue('')
117-
this.organisationForm.controls.ministry.clearValidators()
118-
this.organisationForm.controls.ministry.updateValueAndValidity()
119-
} else if (val === 'ministry') {
120-
this.organisationForm.controls.ministry.setValidators([Validators.required])
121-
this.organisationForm.controls.ministry.updateValueAndValidity()
122-
this.organisationForm.controls.state.setValue('')
123-
this.organisationForm.controls.state.clearValidators()
124-
this.organisationForm.controls.state.updateValueAndValidity()
132+
this.organisationForm.controls.category.valueChanges
133+
.pipe(takeUntil(this.untilDestroyed$)).subscribe(val => {
134+
if (val === 'state') {
135+
this.organisationForm.controls.state.setValidators([Validators.required])
136+
this.organisationForm.controls.state.updateValueAndValidity()
137+
this.organisationForm.controls.ministry.setValue('')
138+
this.organisationForm.controls.ministry.clearValidators()
139+
this.organisationForm.controls.ministry.updateValueAndValidity()
140+
} else if (val === 'ministry') {
141+
this.organisationForm.controls.ministry.setValidators([Validators.required])
142+
this.organisationForm.controls.ministry.updateValueAndValidity()
143+
this.organisationForm.controls.state.setValue('')
144+
this.organisationForm.controls.state.clearValidators()
145+
this.organisationForm.controls.state.updateValueAndValidity()
146+
}
147+
})
148+
}
149+
150+
151+
this.organisationForm.controls.organisationName.valueChanges
152+
.pipe(takeUntil(this.untilDestroyed$), debounceTime(500), distinctUntilChanged())
153+
.subscribe((_value) => {
154+
const control = this.organisationForm.controls.organisationName
155+
const error = this.createDuplicateOrgNameValidator(this.organizationNameList)(control)
156+
if (error) {
157+
control.setErrors(error)
158+
} else {
159+
control.setErrors(null)
125160
}
126161
})
127-
}
128162
}
129163

130164
get getCategory() {
@@ -216,15 +250,15 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
216250
if (input.files?.length) {
217251
this.selectedLogoFile = input.files[0]
218252
this.selectedLogoName = this.selectedLogoFile.name
219-
const maxFileSize = this.maxFileSize * 1024
253+
const maxFileSize = this.maxFileSize * 1024 * 1024
220254

221255
if (!this.validFileTypes.includes(this.selectedLogoFile.type)) {
222256
this.snackBar.open('Invalid file type', 'X', { panelClass: ['error'] })
223257
return
224258
}
225259

226260
if (this.selectedLogoFile.size > maxFileSize) {
227-
this.snackBar.open(`File size exceeds ${this.maxFileSize} KB. Please select a smaller file.`, 'X', { panelClass: ['error'] })
261+
this.snackBar.open(`File size exceeds ${this.maxFileSize} MB. Please select a smaller file.`, 'X', { panelClass: ['error'] })
228262
return
229263
}
230264
this.uploadOrganizationLogo()

project/ws/app/src/lib/head/ui-admin-table/directory-list/directory-table.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<div class="left-overlay" *ngIf="openCreateNavBar || customSelfRegistration"></div>
33
<ng-container *ngIf="openCreateNavBar">
44
<ws-app-create-organisation [openMode]="openMode" [dropdownList]="dropdownList" [rowData]="rowData"
5-
(buttonClick)="buttonClickAction($event)" (organizationCreated)="organizationCreatedEmit($event)">
5+
[orgList]="this.dataSource.data" (buttonClick)="buttonClickAction($event)"
6+
(organizationCreated)="organizationCreatedEmit($event)">
67
</ws-app-create-organisation>
78
</ng-container>
89
<ng-container *ngIf="customSelfRegistration">

0 commit comments

Comments
 (0)