@@ -46,8 +46,11 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
46
46
ORG_NAME_PATTERN = / ^ [ a - z A - Z 0 - 9 ( ) . , @ \- \$ \/ \\ : \[ \] ! \s ] * $ /
47
47
48
48
untilDestroyed$ = new Subject < void > ( ) ;
49
- isMatcompleteOpened = false ;
49
+ isMatcompleteOpened = false
50
+ isStateLogin = false
51
+ disableStateBlock = false
50
52
EXCLUDED_MINISRIES : string [ ] = [ ]
53
+ stateName : string = ''
51
54
constructor (
52
55
private formBuilder : FormBuilder ,
53
56
private snackBar : MatSnackBar ,
@@ -70,7 +73,31 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
70
73
}
71
74
72
75
this . organizationNameList = this . orgList . map ( org => org . organisation . trim ( ) . toLowerCase ( ) )
76
+ this . checkState ( )
73
77
}
78
+ checkState ( ) {
79
+ this . statesList = _ . get ( this . dropdownList , 'statesList' , [ ] )
80
+ const userOrgName = _ . get ( this . activatedRoute ?. snapshot . parent ?. data , 'configService.unMappedUser.rootOrg' , null )
81
+
82
+ if ( userOrgName && userOrgName . isState ) {
83
+ this . isStateLogin = userOrgName . isState
84
+ this . stateName = userOrgName . channel
85
+ const findOrgDetails = ( org : string ) => {
86
+ const result = _ . find ( this . statesList , { orgName : org } )
87
+ return result ? { orgName : result . orgName , mapId : result . mapId } : null
88
+ }
89
+ const orgDetails = findOrgDetails ( this . stateName )
90
+ if ( orgDetails && orgDetails ?. mapId && orgDetails ?. orgName ) {
91
+ // Setting form values for organization
92
+ this . organisationForm . controls [ 'category' ] . setValue ( 'state' )
93
+ this . organisationForm . controls [ 'state' ] . setValue ( orgDetails . orgName )
94
+ // Fetching organization details
95
+ this . getOrganization ( this . stateName , 'state' )
96
+ this . disableStateBlock = true
97
+ }
98
+ }
99
+ }
100
+
74
101
75
102
ngOnDestroy ( ) : void {
76
103
this . removeOverflowHidden ( )
@@ -190,24 +217,33 @@ export class CreateOrganisationComponent implements OnInit, OnDestroy {
190
217
}
191
218
192
219
onSubmitCreateOrganization ( ) {
193
- const payload = {
194
- orgName : this . controls [ 'organisationName' ] . value ,
195
- channel : this . controls [ 'organisationName' ] . value ,
220
+ let payload : any = {
221
+ orgName : this . controls [ 'organisationName' ] ? .value || "" ,
222
+ channel : this . controls [ 'organisationName' ] ? .value || "" ,
196
223
organisationType : "mdo" ,
197
224
organisationSubType : "board" ,
198
225
isTenant : true ,
199
226
requestedBy : this . loggedInUserId ,
200
-
201
227
logo : this . uploadedLogoResponse ?. qrcodepath || "" ,
202
- description : this . controls [ 'description' ] . value ,
228
+ description : this . controls [ 'description' ] ? .value || "" ,
203
229
parentMapId : "" ,
204
- sbRootOrgId : this . heirarchyObject ?. sbRootOrgId || "" ,
205
230
}
206
- if ( this . controls [ 'category' ] . value === 'state' ) {
207
- payload . parentMapId = this . controls [ 'state' ] . value . mapId
231
+ // if (this.heirarchyObject.sbRootOrgId) {
232
+ // payload['sbRootOrgId'] = this.heirarchyObject.sbRootOrgId
233
+ // }
234
+ if ( this . controls [ 'category' ] ?. value === 'state' ) {
235
+ const orgDetails = _ . find ( this . statesList , { orgName : this . stateName } )
236
+ if ( orgDetails ) {
237
+ payload . parentMapId = orgDetails . mapId || "" // Assign mapId from orgDetails
238
+ } else if ( this . controls [ 'state' ] ?. value ?. mapId ) {
239
+ payload . parentMapId = this . controls [ 'state' ] . value . mapId // Fallback to state control mapId
240
+ } else {
241
+ return // Exit function in case of error
242
+ }
243
+ } else if ( this . controls [ 'ministry' ] ?. value ?. mapId ) {
244
+ payload . parentMapId = this . controls [ 'ministry' ] . value . mapId // Assign ministry mapId
208
245
} else {
209
- payload . parentMapId = this . controls [ 'ministry' ] . value . mapId
210
-
246
+ return // Exit function in case of error
211
247
}
212
248
213
249
if ( this . openMode === 'editMode' ) {
0 commit comments