@@ -173,8 +173,11 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
173173
174174 this . structuresForm = new FormGroup ( { } ) ;
175175 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+ }
178181 }
179182 this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
180183 this . prepareStructureSpecificTextInputs ( ) ;
@@ -429,8 +432,8 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
429432 if ( ! result ) return ;
430433 const structureToEdit = this . proposedStructures . find ( ( structure ) => structure . id === id ) ;
431434 if ( structureToEdit ) {
435+ this . setStructureTypeInput ( structureToEdit , result . dto . type ) ;
432436 structureToEdit . area = result . dto . area . toString ( ) ;
433- structureToEdit . type = result . dto . type ;
434437 this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
435438 const areaControl = this . structuresForm . controls [ `${ structureToEdit ?. id } -area` ] ;
436439 const typeControl = this . structuresForm . controls [ `${ structureToEdit ?. id } -type` ] ;
@@ -486,11 +489,14 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
486489 . beforeClosed ( )
487490 . subscribe ( async ( result : { isEditing : boolean ; structureId : string ; dto : ProposedStructure } ) => {
488491 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+ }
490496 this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
491497 } ) ;
492498 } else {
493- this . addControl ( null , null ) ;
499+ this . addControl ( ) ;
494500 this . structuresSource = new MatTableDataSource ( this . proposedStructures ) ;
495501 }
496502 }
@@ -499,20 +505,22 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
499505 return item . type === STRUCTURE_TYPES . PRINCIPAL_RESIDENCE || item . type === STRUCTURE_TYPES . ADDITIONAL_RESIDENCE ;
500506 }
501507
502- private addControl ( type : STRUCTURE_TYPES | null , area : number | null ) {
508+ private addControl ( area : number | null = null ) {
503509 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 ( ) } ;
505511 this . proposedStructures . push ( newStructure ) ;
506512 this . structuresForm . addControl (
507513 `${ newStructure . id } -type` ,
508- new FormControl < string | null > ( type , [ Validators . required ] ) ,
514+ new FormControl < string | null > ( null , [ Validators . required ] ) ,
509515 ) ;
510516 this . structuresForm . addControl (
511517 `${ newStructure . id } -area` ,
512518 new FormControl < string | null > ( areaStr , [ Validators . required ] ) ,
513519 ) ;
514520
515521 this . structuresForm . markAsDirty ( ) ;
522+
523+ return newStructure ;
516524 }
517525
518526 private setRequired ( formControl : FormControl < any > ) {
0 commit comments