Skip to content

Commit

Permalink
Merge pull request #2123 from HemanthKona/stories/EMBCESS-5266-self-s…
Browse files Browse the repository at this point in the history
…erve-bug-fixes

EMBCESS-5266 EMBCESS-5267 self serve eligibility, support detail form bug fixes
  • Loading branch information
ytqsl authored May 8, 2024
2 parents 1bcca68 + fdd79b0 commit 8f600a8
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h2 class="highlightText">
Proceed With e-Transfer
</button>
<div>
<a class="highlightText" style="cursor: pointer" (click)="optOutSelfServe()">
<a class="highlightText" style="cursor: pointer; text-decoration: none" (click)="optOutSelfServe()">
Opt-out and Receive Supports via Referrals
</a>
<button mat-icon-button (click)="openInteracOptOutDialog()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
SelfServeFoodRestaurantSupport,
SelfServeIncidentalsSupport,
SelfServeShelterAllowanceSupport,
SelfServeSupportType
SelfServeSupportType,
SupportDayMeals
} from 'src/app/core/api/models';
import * as moment from 'moment';

Expand Down Expand Up @@ -117,10 +118,76 @@ export class SelfServeSupportDetailsFormComponent {
);
});

const originalMealSupportsDraft: Record<string, SupportDayMeals> = {};

this.supportDraftForm.controls.food.controls.restaurant.controls.mealTypes.valueChanges.subscribe({
next: () => {
// get all unchecked and undisabled control
const unCheckedControls: Record<string, FormControl[]> = {
breakfast: [],
lunch: [],
dinner: []
};

const checkedCount: Record<string, number> = {
breakfast: 0,
lunch: 0,
dinner: 0
};

this.supportDraftForm.controls.food.controls.restaurant.controls.mealTypes.controls.forEach((meal) => {
if (meal.controls.breakfast.value === true) checkedCount.breakfast++;
else if (
originalMealSupportsDraft[meal.controls.date.value.format('YYYY-MM-DD')].breakfast === true ||
originalMealSupportsDraft[meal.controls.date.value.format('YYYY-MM-DD')].breakfast === false
)
unCheckedControls.breakfast.push(meal.controls.breakfast);

if (meal.controls.lunch.value === true) checkedCount.lunch++;
else if (
originalMealSupportsDraft[meal.controls.date.value.format('YYYY-MM-DD')].lunch === true ||
originalMealSupportsDraft[meal.controls.date.value.format('YYYY-MM-DD')].lunch === false
)
unCheckedControls.lunch.push(meal.controls.lunch);

if (meal.controls.dinner.value === true) checkedCount.dinner++;
else if (
originalMealSupportsDraft[meal.controls.date.value.format('YYYY-MM-DD')].dinner === true ||
originalMealSupportsDraft[meal.controls.date.value.format('YYYY-MM-DD')].dinner === false
)
unCheckedControls.dinner.push(meal.controls.dinner);
});

// @Note: Only 3 dates can be checked per meal type
// check count of selected checkboxes are 3 then disable the first unchecked
if (checkedCount.breakfast >= 3) {
unCheckedControls.breakfast.forEach((c) => c.disable({ emitEvent: false }));
} else {
unCheckedControls.breakfast.forEach((c) => c.enable({ emitEvent: false }));
}

if (checkedCount.lunch >= 3) {
unCheckedControls.lunch.forEach((c) => c.disable({ emitEvent: false }));
} else {
unCheckedControls.lunch.forEach((c) => c.enable({ emitEvent: false }));
}

if (checkedCount.dinner >= 3) {
unCheckedControls.dinner.forEach((c) => c.disable({ emitEvent: false }));
} else {
unCheckedControls.dinner.forEach((c) => c.enable({ emitEvent: false }));
}
}
});

selfServeSupport.meals.forEach((m) => {
const date = moment(m.date, 'YYYY-MM-DD');

originalMealSupportsDraft[date.format('YYYY-MM-DD')] = m;

this.supportDraftForm.controls.food.controls.restaurant.controls.mealTypes.push(
new FormGroup<SelfServeSupportDayMealForm>({
date: new FormControl(moment(m.date, 'YYYY-MM-DD')),
date: new FormControl(date),
breakfast: new FormControl({ value: m.breakfast, disabled: m.breakfast !== true && m.breakfast !== false }),
lunch: new FormControl({ value: m.lunch, disabled: m.lunch !== true && m.lunch !== false }),
dinner: new FormControl({ value: m.dinner, disabled: m.dinner !== true && m.dinner !== false })
Expand All @@ -132,9 +199,9 @@ export class SelfServeSupportDetailsFormComponent {
next: (includedHouseholdMembers) => {
if (includedHouseholdMembers.every((m) => !m.isSelected)) {
this.supportDraftForm.controls.food.controls.restaurant.controls.mealTypes.controls.forEach((m) => {
if (m.controls.breakfast.value === true) m.controls.breakfast.setValue(false);
if (m.controls.lunch.value === true) m.controls.lunch.setValue(false);
if (m.controls.dinner.value === true) m.controls.dinner.setValue(false);
if (m.controls.breakfast.value === true) m.controls.breakfast.setValue(false, { emitEvent: false });
if (m.controls.lunch.value === true) m.controls.lunch.setValue(false, { emitEvent: false });
if (m.controls.dinner.value === true) m.controls.dinner.setValue(false, { emitEvent: false });
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { AppLoaderComponent } from 'src/app/core/components/app-loader/app-loade
import { tap } from 'rxjs';
import { MatSelectModule } from '@angular/material/select';
import { CustomValidationService } from 'src/app/core/services/customValidation.service';
import { IMaskDirective } from 'angular-imask';
import { ProfileDataService } from '../profile/profile-data.service';
import { ETransferNotificationPreference } from 'src/app/core/model/e-transfer-notification-preference.model';
import {
Expand All @@ -41,7 +40,7 @@ import {
SupportPersonForm,
SelfServeIncidentsSupportForm,
ETransferDetailsForm,
SelfServeSupportDayMealForm
SelfServeFoodGroceriesSupportForm
} from './self-serve-support.model';
import { SelfServeSupportDetailsFormComponent } from './self-serve-support-details-form/self-serve-support-details-form.component';
import { SelfServeSupportInteracETransfterFormComponent } from './self-serve-interac-e-transfer-form/self-serve-support-interac-e-transfer-form.component';
Expand Down Expand Up @@ -296,8 +295,10 @@ export class SelfServeSupportFormComponent implements OnInit {
}
}

processShelterAllowanceData(): SelfServeShelterAllowanceSupport | null {
const supportFormValue = this.supportDraftForm.value.shelterAllowance;
processShelterAllowanceData(
supportForm: FormGroup<SelfServeShelerAllowanceSupportForm>
): SelfServeShelterAllowanceSupport | null {
const supportFormValue = supportForm.value;

const data: SelfServeShelterAllowanceSupport & { $type: 'SelfServeShelterAllowanceSupport' } = {
$type: 'SelfServeShelterAllowanceSupport',
Expand All @@ -314,61 +315,56 @@ export class SelfServeSupportFormComponent implements OnInit {
return data;
}

processFoodGroceriesData(): SelfServeFoodGroceriesSupport | null {
const supportFormValue = this.supportDraftForm.value.food;
processFoodGroceriesData(
supportForm: FormGroup<SelfServeFoodGroceriesSupportForm>
): SelfServeFoodGroceriesSupport | null {
const supportFormValue = supportForm.value;

if (supportFormValue.fundsFor === SelfServeSupportType.FoodGroceries) {
const data: SelfServeFoodGroceriesSupport & { $type: 'SelfServeFoodGroceriesSupport' } = {
$type: 'SelfServeFoodGroceriesSupport',
type: SelfServeSupportType.FoodGroceries,
totalAmount: 34
};
const data: SelfServeFoodGroceriesSupport & { $type: 'SelfServeFoodGroceriesSupport' } = {
$type: 'SelfServeFoodGroceriesSupport',
type: SelfServeSupportType.FoodGroceries,
totalAmount: supportFormValue.totalAmount
};

const supportDays: Record<string, SupportDay> = this.getSupportDays(
this.supportDraftForm.controls.food.controls.groceries.controls.nights
);
const supportDays: Record<string, SupportDay> = this.getSupportDays(supportForm.controls.nights);

data.nights = Object.values(supportDays);
data.nights = Object.values(supportDays);

return data;
}

return null;
return data;
}

processFoodRestaurantData(): SelfServeFoodRestaurantSupport | null {
const supportFormValue = this.supportDraftForm.value.food;

if (supportFormValue.fundsFor === SelfServeSupportType.FoodRestaurant) {
const data: SelfServeFoodRestaurantSupport & { $type: 'SelfServeFoodRestaurantSupport' } = {
$type: 'SelfServeFoodRestaurantSupport',
type: SelfServeSupportType.FoodRestaurant,
totalAmount: 234,
includedHouseholdMembers: [],
meals: []
};

data.includedHouseholdMembers = supportFormValue.restaurant.includedHouseholdMembers
.filter((p) => p.isSelected)
.map((p) => p.personId);

data.meals = supportFormValue.restaurant.mealTypes
.filter((m) => m.breakfast || m.lunch || m.dinner)
.map((m) => ({
breakfast: m.breakfast,
lunch: m.lunch,
dinner: m.dinner,
date: m.date.format('YYYY-MM-DD')
}));

return data;
}
processFoodRestaurantData(
supportForm: FormGroup<SelfServeFoodRestaurantSupportForm>
): SelfServeFoodRestaurantSupport | null {
const supportFormValue = supportForm.value;

const data: SelfServeFoodRestaurantSupport & { $type: 'SelfServeFoodRestaurantSupport' } = {
$type: 'SelfServeFoodRestaurantSupport',
type: SelfServeSupportType.FoodRestaurant,
totalAmount: supportFormValue.totalAmount,
includedHouseholdMembers: [],
meals: []
};

data.includedHouseholdMembers = supportFormValue.includedHouseholdMembers
.filter((p) => p.isSelected)
.map((p) => p.personId);

data.meals = supportFormValue.mealTypes
.filter((m) => m.breakfast || m.lunch || m.dinner)
.map((m) => ({
breakfast: m.breakfast,
lunch: m.lunch,
dinner: m.dinner,
date: m.date.format('YYYY-MM-DD')
}));

return null;
return data;
}

processClothing() {
const supportFormValue = this.supportDraftForm.value.clothing;
processClothing(supportForm: FormGroup<SelfServeClothingSupportForm>) {
const supportFormValue = supportForm.value;

const data: SelfServeClothingSupport & { $type: 'SelfServeClothingSupport' } = {
$type: 'SelfServeClothingSupport',
type: SelfServeSupportType.Clothing,
Expand All @@ -382,8 +378,9 @@ export class SelfServeSupportFormComponent implements OnInit {
return data;
}

processIncidents() {
const supportFormValue = this.supportDraftForm.value.incidents;
processIncidents(supportForm: FormGroup<SelfServeIncidentsSupportForm>) {
const supportFormValue = supportForm.value;

const data: SelfServeIncidentalsSupport & { $type: 'SelfServeIncidentalsSupport' } = {
$type: 'SelfServeIncidentalsSupport',
type: SelfServeSupportType.Incidentals,
Expand Down Expand Up @@ -422,27 +419,37 @@ export class SelfServeSupportFormComponent implements OnInit {
this.draftSupports.items.forEach((support) => {
switch (support.type) {
case SelfServeSupportType.ShelterAllowance:
const processShelterAllowance = this.processShelterAllowanceData();
const processShelterAllowance = this.processShelterAllowanceData(
this.supportDraftForm.controls.shelterAllowance
);
if (processShelterAllowance) selfServeSupportRequest.supports.push(processShelterAllowance);
break;

case SelfServeSupportType.FoodGroceries:
const processFoodGroceries = this.processFoodGroceriesData();
if (processFoodGroceries) selfServeSupportRequest.supports.push(processFoodGroceries);
if (this.supportDraftForm.controls.food.controls.fundsFor.value === SelfServeSupportType.FoodGroceries) {
const processFoodGroceries = this.processFoodGroceriesData(
this.supportDraftForm.controls.food.controls.groceries
);
if (processFoodGroceries) selfServeSupportRequest.supports.push(processFoodGroceries);
}
break;

case SelfServeSupportType.FoodRestaurant:
const processFoodRestaurant = this.processFoodRestaurantData();
if (processFoodRestaurant) selfServeSupportRequest.supports.push(processFoodRestaurant);
if (this.supportDraftForm.controls.food.controls.fundsFor.value === SelfServeSupportType.FoodRestaurant) {
const processFoodRestaurant = this.processFoodRestaurantData(
this.supportDraftForm.controls.food.controls.restaurant
);
if (processFoodRestaurant) selfServeSupportRequest.supports.push(processFoodRestaurant);
}
break;

case SelfServeSupportType.Clothing:
const processClothing = this.processClothing();
const processClothing = this.processClothing(this.supportDraftForm.controls.clothing);
if (processClothing) selfServeSupportRequest.supports.push(processClothing);
break;

case SelfServeSupportType.Incidentals:
const processIncidents = this.processIncidents();
const processIncidents = this.processIncidents(this.supportDraftForm.controls.incidents);
if (processIncidents) selfServeSupportRequest.supports.push(processIncidents);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export class DashboardComponent implements OnInit {
const registrationResult = this.needsAssessmentService.getVerifiedEvacuationFileNo();

if (registrationResult !== null) {
const { selfServe, supportData } = this.router.lastSuccessfulNavigation.extras.state;
const { selfServe = null, supportData = null } = this.router.lastSuccessfulNavigation.extras?.state ?? {
selfServe: false,
supportData: null
};

if (selfServe) {
this.dialog
.open(SelfServeSubmissionDialogComponent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { MatCardModule } from '@angular/material/card';
})
export class EvacuationDetailsComponent implements OnInit, AfterViewInit {
@Input() allExpandState = false;
previousUrl: string;
evacuationFileTab: string;
backArrowImgSrc = '/assets/images/back_arrow.svg';
type = 'need';
Expand All @@ -48,14 +47,10 @@ export class EvacuationDetailsComponent implements OnInit, AfterViewInit {
public evacuationFileDataService: EvacuationFileDataService,
private datePipe: DatePipe,
private cd: ChangeDetectorRef
) {
this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
this.previousUrl = event.url;
});
}
) {}

ngOnInit(): void {
if (this.previousUrl?.includes('current')) {
if (this.router.url?.includes('current')) {
this.evacuationFileTab = 'Current';
} else {
this.evacuationFileTab = 'Past';
Expand All @@ -82,7 +77,7 @@ export class EvacuationDetailsComponent implements OnInit, AfterViewInit {
}

goToCurrent(): void {
if (this.previousUrl.includes('current')) {
if (this.router.url.includes('current')) {
this.router.navigate(['/verified-registration/dashboard/current']);
} else {
this.router.navigate(['/verified-registration/dashboard/past']);
Expand Down

0 comments on commit 8f600a8

Please sign in to comment.