@@ -173,8 +173,11 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
173
173
174
174
this . structuresForm = new FormGroup ( { } ) ;
175
175
this . proposedStructures = [ ] ;
176
- for ( const lot of noiSubmission . soilProposedStructures ) {
177
- this . addControl ( lot . type , lot . area ) ;
176
+ for ( const structure of noiSubmission . soilProposedStructures ) {
177
+ const newStructure = this . addControl ( structure . area ) ;
178
+ if ( structure . type !== null ) {
179
+ this . setStructureTypeInput ( newStructure , structure . type ) ;
180
+ }
178
181
}
179
182
this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
180
183
this . prepareStructureSpecificTextInputs ( ) ;
@@ -429,8 +432,8 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
429
432
if ( ! result ) return ;
430
433
const structureToEdit = this . proposedStructures . find ( ( structure ) => structure . id === id ) ;
431
434
if ( structureToEdit ) {
435
+ this . setStructureTypeInput ( structureToEdit , result . dto . type ) ;
432
436
structureToEdit . area = result . dto . area . toString ( ) ;
433
- structureToEdit . type = result . dto . type ;
434
437
this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
435
438
const areaControl = this . structuresForm . controls [ `${ structureToEdit ?. id } -area` ] ;
436
439
const typeControl = this . structuresForm . controls [ `${ structureToEdit ?. id } -type` ] ;
@@ -486,11 +489,14 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
486
489
. beforeClosed ( )
487
490
. subscribe ( async ( result : { isEditing : boolean ; structureId : string ; dto : ProposedStructure } ) => {
488
491
if ( ! result ) return ;
489
- this . addControl ( result . dto . type , result . dto . area ) ;
492
+ const newStructure = this . addControl ( result . dto . area ) ;
493
+ if ( result . dto . type !== null ) {
494
+ this . setStructureTypeInput ( newStructure , result . dto . type ) ;
495
+ }
490
496
this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
491
497
} ) ;
492
498
} else {
493
- this . addControl ( null , null ) ;
499
+ this . addControl ( ) ;
494
500
this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
495
501
}
496
502
}
@@ -499,20 +505,22 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
499
505
return item . type === STRUCTURE_TYPES . PRINCIPAL_RESIDENCE || item . type === STRUCTURE_TYPES . ADDITIONAL_RESIDENCE ;
500
506
}
501
507
502
- private addControl ( type : STRUCTURE_TYPES | null , area : number | null ) {
508
+ private addControl ( area : number | null = null ) {
503
509
const areaStr = area ? area . toString ( 10 ) : null ;
504
- const newStructure : FormProposedStructure = { type, area : areaStr , id : v4 ( ) } ;
510
+ const newStructure : FormProposedStructure = { type : null , area : areaStr , id : v4 ( ) } ;
505
511
this . proposedStructures . push ( newStructure ) ;
506
512
this . structuresForm . addControl (
507
513
`${ newStructure . id } -type` ,
508
- new FormControl < string | null > ( type , [ Validators . required ] ) ,
514
+ new FormControl < string | null > ( null , [ Validators . required ] ) ,
509
515
) ;
510
516
this . structuresForm . addControl (
511
517
`${ newStructure . id } -area` ,
512
518
new FormControl < string | null > ( areaStr , [ Validators . required ] ) ,
513
519
) ;
514
520
515
521
this . structuresForm . markAsDirty ( ) ;
522
+
523
+ return newStructure ;
516
524
}
517
525
518
526
private setRequired ( formControl : FormControl < any > ) {
0 commit comments