Skip to content

Commit

Permalink
Merge pull request #110 from Sohith-code/cbrelease-4.8.20-custom-regi…
Browse files Browse the repository at this point in the history
…stration-sohith

7516,1514,7527 fix
  • Loading branch information
vishnubansaltarento authored Dec 2, 2024
2 parents f234545 + 3803181 commit 917434e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@
</ng-container>
<ng-container *ngIf="openMode !== 'viewMode'; else viewMode">
<form [formGroup]="organisationForm" class="mb-20">
<div class="flex flex-column gap-1 organisation-form mat-field-rounded">
<div class="flex items-center gap-1 required">
<span class="lable">Organisation Name</span>
<ng-container *ngIf="this.openMode !== 'editMode'">
<div class="flex flex-column gap-1 organisation-form mat-field-rounded">
<div class="flex items-center gap-1 required">
<span class="lable">Organisation Name</span>
</div>
<mat-form-field class="w-full">
<input formControlName="organisationName" matInput placeholder="Add organisation name here">
<mat-error *ngIf="controls['organisationName'].errors?.['required']">Organization name is
required.</mat-error>
<mat-error *ngIf="controls['organisationName'].errors?.['duplicateOrgName']">This organization name
is already in use.</mat-error>
</mat-form-field>
</div>
<mat-form-field class="w-full">
<input formControlName="organisationName" matInput placeholder="Add organisation name here">
<mat-error *ngIf="controls['organisationName'].errors?.['required']">Organization name is
required.</mat-error>
</mat-form-field>
</div>

</ng-container>

<ng-container *ngIf="this.openMode !== 'editMode'">
<mat-radio-group aria-labelledby="example-radio-group-label" class="flex gap-12 organisation-form"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'
import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'
import { MatSnackBar } from '@angular/material/snack-bar'
import * as _ from 'lodash'
import { CreateMDOService } from '../../../routes/home/services/create-mdo.services'
import { ActivatedRoute } from '@angular/router'
import { LoaderService } from '../../../routes/home/services/loader.service'
import { IUploadedLogoresponse } from '../interface/interfaces'
import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators'
import { Subject } from 'rxjs'
@Component({
selector: 'ws-app-create-organisation',
templateUrl: './create-organisation.component.html',
Expand All @@ -14,6 +16,7 @@ import { IUploadedLogoresponse } from '../interface/interfaces'
export class CreateOrganisationComponent implements OnInit, OnDestroy {

@Input() rowData: any
@Input() orgList: any[] = []
@Input() dropdownList: {
statesList: any[],
ministriesList: any[]
Expand All @@ -31,14 +34,17 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
selectedLogo: any
selectedLogoName = ''
validFileTypes = ['image/png', 'image/jpeg', 'image/jpg']
maxFileSize = 500 // In KB
maxFileSize = 5 // In MB
loggedInUserId = ""
isLoading = false
filteredStates: any[] = []
filteredMinistry: any[] = []
heirarchyObject: any
selectedLogoFile: any
uploadedLogoResponse!: IUploadedLogoresponse
organizationNameList: string[] = []

untilDestroyed$ = new Subject<void>();
constructor(
private formBuilder: FormBuilder,
private snackBar: MatSnackBar,
Expand All @@ -56,14 +62,18 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
if (this.openMode === 'editMode') {
this.getOrganization(this.rowData.organisation, this.rowData.type.toLowerCase())
}

this.organizationNameList = this.orgList.map(org => org.organisation.trim().toLowerCase())
}

ngOnDestroy(): void {
this.removeOverflowHidden()

this.untilDestroyed$.next()
this.untilDestroyed$.complete()
}

initialization() {
console.log(this.rowData)

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

createDuplicateOrgNameValidator(organizationNameList: string[]) {
return (control: AbstractControl) => {
if (!organizationNameList || !control.value) {
return null
}
const isDuplicate = organizationNameList.includes(control.value.trim().toLowerCase())
return isDuplicate ? { duplicateOrgName: true } : null
}
}

get controls() {
return this.organisationForm.controls
}
Expand All @@ -109,22 +129,36 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {

valueChangeEvents() {
if (this.organisationForm && this.organisationForm.controls.category) {
this.organisationForm.controls.category.valueChanges.subscribe(val => {
if (val === 'state') {
this.organisationForm.controls.state.setValidators([Validators.required])
this.organisationForm.controls.state.updateValueAndValidity()
this.organisationForm.controls.ministry.setValue('')
this.organisationForm.controls.ministry.clearValidators()
this.organisationForm.controls.ministry.updateValueAndValidity()
} else if (val === 'ministry') {
this.organisationForm.controls.ministry.setValidators([Validators.required])
this.organisationForm.controls.ministry.updateValueAndValidity()
this.organisationForm.controls.state.setValue('')
this.organisationForm.controls.state.clearValidators()
this.organisationForm.controls.state.updateValueAndValidity()
this.organisationForm.controls.category.valueChanges
.pipe(takeUntil(this.untilDestroyed$)).subscribe(val => {
if (val === 'state') {
this.organisationForm.controls.state.setValidators([Validators.required])
this.organisationForm.controls.state.updateValueAndValidity()
this.organisationForm.controls.ministry.setValue('')
this.organisationForm.controls.ministry.clearValidators()
this.organisationForm.controls.ministry.updateValueAndValidity()
} else if (val === 'ministry') {
this.organisationForm.controls.ministry.setValidators([Validators.required])
this.organisationForm.controls.ministry.updateValueAndValidity()
this.organisationForm.controls.state.setValue('')
this.organisationForm.controls.state.clearValidators()
this.organisationForm.controls.state.updateValueAndValidity()
}
})
}


this.organisationForm.controls.organisationName.valueChanges
.pipe(takeUntil(this.untilDestroyed$), debounceTime(500), distinctUntilChanged())
.subscribe((_value) => {
const control = this.organisationForm.controls.organisationName
const error = this.createDuplicateOrgNameValidator(this.organizationNameList)(control)
if (error) {
control.setErrors(error)
} else {
control.setErrors(null)
}
})
}
}

get getCategory() {
Expand Down Expand Up @@ -216,15 +250,15 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
if (input.files?.length) {
this.selectedLogoFile = input.files[0]
this.selectedLogoName = this.selectedLogoFile.name
const maxFileSize = this.maxFileSize * 1024
const maxFileSize = this.maxFileSize * 1024 * 1024

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

if (this.selectedLogoFile.size > maxFileSize) {
this.snackBar.open(`File size exceeds ${this.maxFileSize} KB. Please select a smaller file.`, 'X', { panelClass: ['error'] })
this.snackBar.open(`File size exceeds ${this.maxFileSize} MB. Please select a smaller file.`, 'X', { panelClass: ['error'] })
return
}
this.uploadOrganizationLogo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div class="left-overlay" *ngIf="openCreateNavBar || customSelfRegistration"></div>
<ng-container *ngIf="openCreateNavBar">
<ws-app-create-organisation [openMode]="openMode" [dropdownList]="dropdownList" [rowData]="rowData"
(buttonClick)="buttonClickAction($event)" (organizationCreated)="organizationCreatedEmit($event)">
[orgList]="this.dataSource.data" (buttonClick)="buttonClickAction($event)"
(organizationCreated)="organizationCreatedEmit($event)">
</ws-app-create-organisation>
</ng-container>
<ng-container *ngIf="customSelfRegistration">
Expand Down

0 comments on commit 917434e

Please sign in to comment.