From a991680b402296d0560206b6d58df4bb04869b49 Mon Sep 17 00:00:00 2001 From: Afzal84 Date: Thu, 9 Jan 2025 13:40:50 +0530 Subject: [PATCH] STATE Admin Org creation Flow fix --- .../create-organisation.component.html | 4 +- .../create-organisation.component.ts | 58 +++++++++++++++---- .../routes/directory/directroy.component.ts | 2 +- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.html b/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.html index 1f474dc1..c93061ff 100644 --- a/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.html +++ b/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.html @@ -65,7 +65,7 @@ - + @@ -82,7 +82,7 @@ - +
State diff --git a/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.ts b/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.ts index 75ff5805..1a60b66e 100644 --- a/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.ts +++ b/project/ws/app/src/lib/head/ui-admin-table/create-organisation/create-organisation.component.ts @@ -46,8 +46,11 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy { ORG_NAME_PATTERN = /^[a-zA-Z0-9 ().,@\-\$\/\\:\[\]!\s]*$/ untilDestroyed$ = new Subject(); - isMatcompleteOpened = false; + isMatcompleteOpened = false + isStateLogin = false + disableStateBlock = false EXCLUDED_MINISRIES: string[] = [] + stateName: string = '' constructor( private formBuilder: FormBuilder, private snackBar: MatSnackBar, @@ -70,7 +73,31 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy { } this.organizationNameList = this.orgList.map(org => org.organisation.trim().toLowerCase()) + this.checkState() } + checkState() { + this.statesList = _.get(this.dropdownList, 'statesList', []) + const userOrgName = _.get(this.activatedRoute?.snapshot.parent?.data, 'configService.unMappedUser.rootOrg', null) + + if (userOrgName && userOrgName.isState) { + this.isStateLogin = userOrgName.isState + this.stateName = userOrgName.channel + const findOrgDetails = (org: string) => { + const result = _.find(this.statesList, { orgName: org }) + return result ? { orgName: result.orgName, mapId: result.mapId } : null + } + const orgDetails = findOrgDetails(this.stateName) + if (orgDetails && orgDetails?.mapId && orgDetails?.orgName) { + // Setting form values for organization + this.organisationForm.controls['category'].setValue('state') + this.organisationForm.controls['state'].setValue(orgDetails.orgName) + // Fetching organization details + this.getOrganization(this.stateName, 'state') + this.disableStateBlock = true + } + } + } + ngOnDestroy(): void { this.removeOverflowHidden() @@ -190,24 +217,33 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy { } onSubmitCreateOrganization() { - const payload = { - orgName: this.controls['organisationName'].value, - channel: this.controls['organisationName'].value, + let payload: any = { + orgName: this.controls['organisationName']?.value || "", + channel: this.controls['organisationName']?.value || "", organisationType: "mdo", organisationSubType: "board", isTenant: true, requestedBy: this.loggedInUserId, - logo: this.uploadedLogoResponse?.qrcodepath || "", - description: this.controls['description'].value, + description: this.controls['description']?.value || "", parentMapId: "", - sbRootOrgId: this.heirarchyObject?.sbRootOrgId || "", } - if (this.controls['category'].value === 'state') { - payload.parentMapId = this.controls['state'].value.mapId + // if (this.heirarchyObject.sbRootOrgId) { + // payload['sbRootOrgId'] = this.heirarchyObject.sbRootOrgId + // } + if (this.controls['category']?.value === 'state') { + const orgDetails = _.find(this.statesList, { orgName: this.stateName }) + if (orgDetails) { + payload.parentMapId = orgDetails.mapId || "" // Assign mapId from orgDetails + } else if (this.controls['state']?.value?.mapId) { + payload.parentMapId = this.controls['state'].value.mapId // Fallback to state control mapId + } else { + return // Exit function in case of error + } + } else if (this.controls['ministry']?.value?.mapId) { + payload.parentMapId = this.controls['ministry'].value.mapId // Assign ministry mapId } else { - payload.parentMapId = this.controls['ministry'].value.mapId - + return // Exit function in case of error } if (this.openMode === 'editMode') { diff --git a/project/ws/app/src/lib/routes/home/routes/directory/directroy.component.ts b/project/ws/app/src/lib/routes/home/routes/directory/directroy.component.ts index 9eefba29..b6844a65 100644 --- a/project/ws/app/src/lib/routes/home/routes/directory/directroy.component.ts +++ b/project/ws/app/src/lib/routes/home/routes/directory/directroy.component.ts @@ -38,7 +38,7 @@ export class DirectoryViewComponent implements OnInit { pagination = { limit: 20, offset: 0 } totalCount = 0 userRoles: any - allowedCreateRoles = ['DASHBOARD_ADMIN', 'SPV_ADMIN', 'SPV_PUBLISHER'] + allowedCreateRoles = ['DASHBOARD_ADMIN', 'SPV_ADMIN', 'SPV_PUBLISHER', 'STATE_ADMIN'] constructor( public dialog: MatDialog, private route: ActivatedRoute,