Skip to content

Commit

Permalink
Merge pull request bcgov#2018 from HemanthKona/stories/EMBCESSMOD-5109
Browse files Browse the repository at this point in the history
EMBCESSMOD-5108, EMBCESSMOD-5109, EMBCESSMOD-5110 Fix unselecting Shelter Type when requires shelter is unchecked
  • Loading branch information
ytqsl authored Apr 11, 2024
2 parents 15c8441 + 3de1f03 commit 594249f
Showing 1 changed file with 23 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import {
AbstractControl,
UntypedFormBuilder,
UntypedFormGroup
} from '@angular/forms';
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { StepEssFileService } from '../../step-ess-file/step-ess-file.service';
Expand Down Expand Up @@ -40,17 +36,16 @@ export class NeedsComponent implements OnInit, OnDestroy {
private evacueeSessionService: EvacueeSessionService,
private customValidationService: CustomValidationService,
private dialog: MatDialog
) { }
) {}

ngOnInit(): void {
// Creates the main form
this.createNeedsForm();

// Set "update tab status" method, called for any tab navigation
this.tabUpdateSubscription =
this.stepEssFileService.nextTabUpdate.subscribe(() => {
this.updateTabStatus();
});
this.tabUpdateSubscription = this.stepEssFileService.nextTabUpdate.subscribe(() => {
this.updateTabStatus();
});

this.tabMetaData = this.stepEssFileService.getNavLinks('needs');
}
Expand Down Expand Up @@ -91,10 +86,7 @@ export class NeedsComponent implements OnInit, OnDestroy {
*/
ngOnDestroy(): void {
if (this.stepEssFileService.checkForEdit()) {
const isFormUpdated = this.wizardService.hasChanged(
this.needsForm.controls,
'needs'
);
const isFormUpdated = this.wizardService.hasChanged(this.needsForm.controls, 'needs');

this.wizardService.setEditStatus({
tabName: 'needs',
Expand Down Expand Up @@ -130,25 +122,15 @@ export class NeedsComponent implements OnInit, OnDestroy {

private createNeedsForm(): void {
this.needsForm = this.formBuilder.group({
requiresShelter: [
this.stepEssFileService.requiresShelterAllowance ||
this.stepEssFileService.requiresShelterReferral
],
requiresShelter: [this.stepEssFileService.requiresShelterAllowance || this.stepEssFileService.requiresShelterReferral],
requiresShelterType: [
this.stepEssFileService.requiresShelterReferral
? ShelterType.referral
: this.stepEssFileService.requiresShelterAllowance
? ShelterType.allowance
: undefined
this.stepEssFileService.requiresShelterReferral ? ShelterType.referral : this.stepEssFileService.requiresShelterAllowance ? ShelterType.allowance : undefined,
this.customValidationService.conditionalValidation(() => this.needsFormControl.requiresShelter.value === true, Validators.required)
],
requiresFood: [this.stepEssFileService.requiresFood ?? false],
requiresClothing: [this.stepEssFileService.requiresClothing ?? false],
requiresTransportation: [
this.stepEssFileService.requiresTransportation ?? false
],
requiresIncidentals: [
this.stepEssFileService.requiresIncidentals ?? false
],
requiresTransportation: [this.stepEssFileService.requiresTransportation ?? false],
requiresIncidentals: [this.stepEssFileService.requiresIncidentals ?? false],
requiresNothing: [this.stepEssFileService.requiresNothing ?? false]
});
this.needsForm.addValidators(this.customValidationService.needsValidator());
Expand All @@ -159,6 +141,11 @@ export class NeedsComponent implements OnInit, OnDestroy {
this.enableNeeds();
}
});
this.needsFormControl.requiresShelter.valueChanges.subscribe((checked) => {
if (!checked) {
this.needsFormControl.requiresShelterType.reset();
}
});
if (this.stepEssFileService.requiresNothing) {
this.disableNeeds();
}
Expand Down Expand Up @@ -212,19 +199,12 @@ export class NeedsComponent implements OnInit, OnDestroy {
* Saves information inserted inthe form into the service
*/
private saveFormData() {
this.stepEssFileService.requiresClothing =
this.needsFormControl.requiresClothing.value;
this.stepEssFileService.requiresFood =
this.needsFormControl.requiresFood.value;
this.stepEssFileService.requiresIncidentals =
this.needsFormControl.requiresIncidentals.value;
this.stepEssFileService.requiresTransportation =
this.needsFormControl.requiresTransportation.value;
this.stepEssFileService.requiresShelterAllowance =
this.needsFormControl.requiresShelterType.value === ShelterType.allowance;
this.stepEssFileService.requiresShelterReferral =
this.needsFormControl.requiresShelterType.value === ShelterType.referral;
this.stepEssFileService.requiresNothing =
this.needsFormControl.requiresNothing.value;
this.stepEssFileService.requiresClothing = this.needsFormControl.requiresClothing.value;
this.stepEssFileService.requiresFood = this.needsFormControl.requiresFood.value;
this.stepEssFileService.requiresIncidentals = this.needsFormControl.requiresIncidentals.value;
this.stepEssFileService.requiresTransportation = this.needsFormControl.requiresTransportation.value;
this.stepEssFileService.requiresShelterAllowance = this.needsFormControl.requiresShelterType.value === ShelterType.allowance;
this.stepEssFileService.requiresShelterReferral = this.needsFormControl.requiresShelterType.value === ShelterType.referral;
this.stepEssFileService.requiresNothing = this.needsFormControl.requiresNothing.value;
}
}

0 comments on commit 594249f

Please sign in to comment.