Skip to content

Commit 8c9cbf1

Browse files
authored
Merge pull request #1978 from bcgov/bugfix/ALCS-2378
Keep residential structure question when changing between residential types
2 parents f366f40 + dcfac3e commit 8c9cbf1

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

portal-frontend/src/app/features/notice-of-intents/edit-submission/additional-information/additional-information.component.ts

+26-24
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,26 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
331331
}
332332
}
333333

334-
private checkStructureTypeInput(type: STRUCTURE_TYPES | null) {
335-
switch (type) {
336-
case STRUCTURE_TYPES.FARM_STRUCTURE:
337-
return !!(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value);
338-
case STRUCTURE_TYPES.ACCESSORY_STRUCTURE:
339-
return !!(
340-
this.soilStructureResidentialUseReason.value || this.soilStructureResidentialAccessoryUseReason.value
341-
);
342-
case STRUCTURE_TYPES.OTHER_STRUCTURE:
343-
return !!this.soilStructureOtherUseReason.value;
344-
case STRUCTURE_TYPES.PRINCIPAL_RESIDENCE:
345-
case STRUCTURE_TYPES.ADDITIONAL_RESIDENCE:
346-
return !!this.soilStructureResidentialUseReason.value;
347-
case null:
348-
return false;
349-
}
334+
private structureChangeRequiresConfirmation(oldType: STRUCTURE_TYPES | null, newType: STRUCTURE_TYPES): boolean {
335+
const residentialTypes = [
336+
STRUCTURE_TYPES.PRINCIPAL_RESIDENCE,
337+
STRUCTURE_TYPES.ADDITIONAL_RESIDENCE,
338+
STRUCTURE_TYPES.ACCESSORY_STRUCTURE,
339+
];
340+
const changingFromResidentialType = oldType && residentialTypes.includes(oldType);
341+
const changingToResidentialType = newType && residentialTypes.includes(newType);
342+
343+
return !!(
344+
oldType !== newType &&
345+
((oldType &&
346+
oldType === STRUCTURE_TYPES.FARM_STRUCTURE &&
347+
(this.soilAgriParcelActivity.value || this.soilStructureFarmUseReason.value)) ||
348+
(changingFromResidentialType && !changingToResidentialType && this.soilStructureResidentialUseReason.value) ||
349+
(oldType &&
350+
oldType === STRUCTURE_TYPES.ACCESSORY_STRUCTURE &&
351+
this.soilStructureResidentialAccessoryUseReason.value) ||
352+
(oldType && oldType === STRUCTURE_TYPES.OTHER_STRUCTURE && this.soilStructureOtherUseReason.value))
353+
);
350354
}
351355

352356
private setStructureTypeInput(structure: FormProposedStructure, newType: STRUCTURE_TYPES) {
@@ -362,18 +366,16 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
362366
this.form.markAsDirty();
363367
}
364368

365-
onChangeStructureType(id: string, value: STRUCTURE_TYPES) {
369+
onChangeStructureType(id: string, newType: STRUCTURE_TYPES) {
366370
const structure = this.proposedStructures.find((structure) => structure.id === id);
367371
if (!structure) {
368372
console.error('Failed to find structure');
369373
return;
370374
}
371375
this.structuresSource = new MatTableDataSource(this.proposedStructures);
372-
const prevType = structure.type;
373-
const hasInput = this.checkStructureTypeInput(prevType);
374-
375-
if (!hasInput) {
376-
return this.setStructureTypeInput(structure, value);
376+
const oldType = structure.type;
377+
if (!this.structureChangeRequiresConfirmation(oldType, newType)) {
378+
return this.setStructureTypeInput(structure, newType);
377379
} else {
378380
const dialog = this.confirmationDialogService.openDialog({
379381
title: 'Change Structure Type',
@@ -384,9 +386,9 @@ export class AdditionalInformationComponent extends FilesStepComponent implement
384386

385387
dialog.subscribe((isConfirmed) => {
386388
if (isConfirmed) {
387-
this.setStructureTypeInput(structure, value);
389+
this.setStructureTypeInput(structure, newType);
388390
} else {
389-
this.structuresForm.get(structure.id + '-type')?.setValue(prevType);
391+
this.structuresForm.get(structure.id + '-type')?.setValue(oldType);
390392
}
391393
});
392394
}

0 commit comments

Comments
 (0)