Skip to content

Commit

Permalink
[FE] metal dealer updates (#2081)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- {List all the changes, if possible add the jira ticket #}
  • Loading branch information
carolcarpenter authored Jan 15, 2025
1 parent 188e8d7 commit 176563e
Show file tree
Hide file tree
Showing 21 changed files with 1,319 additions and 720 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { ApplicationTypeCode } from '@app/api/models';
import { CommonApplicationHelper } from '@app/core/services/common-application.helper';
import { ConfigService } from '@app/core/services/config.service';
import { FileUtilService } from '@app/core/services/file-util.service';
Expand All @@ -9,12 +10,30 @@ import { FormatDatePipe } from '@app/shared/pipes/format-date.pipe';
import { SPD_CONSTANTS } from '../constants/constants';

export abstract class MetalDealersApplicationHelper extends CommonApplicationHelper {
registrationFormGroup: FormGroup = this.formBuilder.group(
{
applicationTypeCode: new FormControl('', [FormControlValidators.required]),
registrationNumber: new FormControl(''),
},
{
validators: [
FormGroupValidators.conditionalDefaultRequiredValidator(
'registrationNumber',
(_form) =>
_form.get('applicationTypeCode')?.value === ApplicationTypeCode.Update ||
_form.get('applicationTypeCode')?.value === ApplicationTypeCode.Renewal
),
],
}
);

businessOwnerFormGroup: FormGroup = this.formBuilder.group({
legalBusinessName: new FormControl('', [FormControlValidators.required]),
tradeName: new FormControl('', [FormControlValidators.required]),
givenName: new FormControl(''),
middleName: new FormControl(''),
surname: new FormControl('', [FormControlValidators.required]),
attachments: new FormControl([]),
});

businessManagerFormGroup: FormGroup = this.formBuilder.group({
Expand All @@ -26,13 +45,13 @@ export abstract class MetalDealersApplicationHelper extends CommonApplicationHel
});

businessAddressFormGroup: FormGroup = this.formBuilder.group({
addressSelected: new FormControl(false),
addressLine1: new FormControl(''),
addressSelected: new FormControl(false, [Validators.requiredTrue]),
addressLine1: new FormControl('', [FormControlValidators.required]),
addressLine2: new FormControl(''),
city: new FormControl(''),
postalCode: new FormControl(''),
province: new FormControl(''),
country: new FormControl(''),
city: new FormControl('', [FormControlValidators.required]),
postalCode: new FormControl('', [FormControlValidators.required]),
province: new FormControl('', [FormControlValidators.required]),
country: new FormControl('', [FormControlValidators.required]),
});

businessMailingAddressFormGroup: FormGroup = this.formBuilder.group(
Expand Down Expand Up @@ -76,9 +95,14 @@ export abstract class MetalDealersApplicationHelper extends CommonApplicationHel
}
);

branchesFormGroup: FormGroup = this.formBuilder.group({
branches: this.formBuilder.array([]),
});
branchesFormGroup: FormGroup = this.formBuilder.group(
{
branches: this.formBuilder.array([]),
},
{
validators: [FormGroupValidators.branchrequiredValidator('branches')],
}
);

branchFormGroup: FormGroup = this.formBuilder.group({
addressSelected: new FormControl(false, [Validators.requiredTrue]),
Expand Down Expand Up @@ -135,31 +159,41 @@ export abstract class MetalDealersApplicationHelper extends CommonApplicationHel
return userNameArray.join(' ');
}

getSummarybusinessOwnerDataname(modelData: any): string {
getSummarybusinessOwnerDataname(metalDealersModelData: any): string {
return this.getFullNameWithMiddle(
modelData.businessOwnerData.givenName,
modelData.businessOwnerData.middleName,
modelData.businessOwnerData.surname
metalDealersModelData.businessOwnerData.givenName,
metalDealersModelData.businessOwnerData.middleName,
metalDealersModelData.businessOwnerData.surname
);
}
getSummarybusinessOwnerDatalegalBusinessName(modelData: any): string {
return modelData.businessOwnerData.legalBusinessName ?? '';
getSummarybusinessOwnerDatalegalBusinessName(metalDealersModelData: any): string {
return metalDealersModelData.businessOwnerData.legalBusinessName ?? '';
}
getSummarybusinessOwnerDatatradeName(metalDealersModelData: any): string {
return metalDealersModelData.businessOwnerData.tradeName ?? '';
}
getSummarybusinessOwnerDatatradeName(modelData: any): string {
return modelData.businessOwnerData.tradeName ?? '';
getSummarybusinessOwnerDataattachments(metalDealersModelData: any): File[] {
return metalDealersModelData.businessOwnerData.attachments ?? [];
}

getSummarybusinessManagerDataname(modelData: any): string {
getSummarybusinessManagerDataname(metalDealersModelData: any): string {
return this.getFullNameWithMiddle(
modelData.businessManagerData.givenName,
modelData.businessManagerData.middleName,
modelData.businessManagerData.surname
metalDealersModelData.businessManagerData.givenName,
metalDealersModelData.businessManagerData.middleName,
metalDealersModelData.businessManagerData.surname
);
}
getSummarybusinessManagerDataphoneNumber(modelData: any): string {
return modelData.businessManagerData.phoneNumber ?? '';
getSummarybusinessManagerDataphoneNumber(metalDealersModelData: any): string {
return metalDealersModelData.businessManagerData.phoneNumber ?? '';
}
getSummarybusinessManagerDataemailAddress(modelData: any): string {
return modelData.businessManagerData.emailAddress ?? '';
getSummarybusinessManagerDataemailAddress(metalDealersModelData: any): string {
return metalDealersModelData.businessManagerData.emailAddress ?? '';
}
getSummarybranchesDatabranches(metalDealersModelData: any): Array<any> {
return metalDealersModelData.branchesData.branches ?? [];
}

getSummaryisAddressTheSame(metalDealersModelData: any): boolean {
return metalDealersModelData.businessMailingAddressData?.isAddressTheSame ?? false;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { FormatDatePipe } from '@app/shared/pipes/format-date.pipe';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, debounceTime, distinctUntilChanged, Observable, of, Subscription } from 'rxjs';
import { ConfigService } from './config.service';
import { FileUtilService } from './file-util.service';
import { MetalDealersApplicationHelper } from './metal-dealers-application.helper';
Expand All @@ -11,9 +11,10 @@ import { UtilService } from './util.service';
providedIn: 'root',
})
export class MetalDealersApplicationService extends MetalDealersApplicationHelper {
modelValueChanges$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
metalDealersModelValueChanges$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

modelFormGroup: FormGroup = this.formBuilder.group({
metalDealersModelFormGroup: FormGroup = this.formBuilder.group({
registrationData: this.registrationFormGroup,
businessOwnerData: this.businessOwnerFormGroup,
businessManagerData: this.businessManagerFormGroup,
businessAddressData: this.businessAddressFormGroup,
Expand All @@ -22,6 +23,8 @@ export class MetalDealersApplicationService extends MetalDealersApplicationHelpe
consentAndDeclarationData: this.consentAndDeclarationFormGroup,
});

metalDealersModelChangedSubscription!: Subscription;

constructor(
formBuilder: FormBuilder,
configService: ConfigService,
Expand All @@ -30,5 +33,95 @@ export class MetalDealersApplicationService extends MetalDealersApplicationHelpe
fileUtilService: FileUtilService
) {
super(formBuilder, configService, formatDatePipe, utilService, fileUtilService);

this.metalDealersModelChangedSubscription = this.metalDealersModelFormGroup.valueChanges
.pipe(debounceTime(200), distinctUntilChanged())
.subscribe((_resp: any) => {
if (this.initialized) {
const step1Complete = this.isStepRegistrationInformationComplete();
const step2Complete = this.isStepBusinessOwnerComplete();
const step3Complete = this.isStepBusinessManagerComplete();
const step4Complete = this.isStepBusinessAddressesComplete();
const step5Complete = this.isStepBranchOfficesComplete();
const isValid = step1Complete && step2Complete && step3Complete && step4Complete && step5Complete;

console.debug('metalDealersModelFormGroup CHANGED', this.metalDealersModelFormGroup.getRawValue());

this.updateModelChangeFlags();

this.metalDealersModelValueChanges$.next(isValid);
}
});
}

/**
* If this step is complete, mark the step as complete in the wizard
* @returns
*/
isStepRegistrationInformationComplete(): boolean {
return this.registrationFormGroup.valid;
}

/**
* If this step is complete, mark the step as complete in the wizard
* @returns
*/
isStepBusinessOwnerComplete(): boolean {
return this.businessOwnerFormGroup.valid;
}

/**
* If this step is complete, mark the step as complete in the wizard
* @returns
*/
isStepBusinessManagerComplete(): boolean {
return this.businessManagerFormGroup.valid;
}

/**
* If this step is complete, mark the step as complete in the wizard
* @returns
*/
isStepBusinessAddressesComplete(): boolean {
return this.businessAddressFormGroup.valid;
}

/**
* If this step is complete, mark the step as complete in the wizard
* @returns
*/
isStepBranchOfficesComplete(): boolean {
return this.branchesFormGroup.valid;
}

/**
* Create an empty registration
* @returns
*/
createNewRegistration(): Observable<any> {
this.reset();

this.initialized = true;
return of(this.metalDealersModelFormGroup.value);
}

/**
* Reset the licence data
* @returns
*/
reset(): void {
this.resetModelFlags();
this.resetCommon();

this.consentAndDeclarationFormGroup.reset();
this.metalDealersModelFormGroup.reset();

// clear the branches data - this does not seem to get reset during a formgroup reset
const branchesArray = this.metalDealersModelFormGroup.get('branchesData.branches') as FormArray;
while (branchesArray.length) {
branchesArray.removeAt(0);
}

console.debug('RESET', this.initialized, this.metalDealersModelFormGroup.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ export class FormGroupValidators {
};
}

public static branchrequiredValidator(controlArrayName: string): ValidatorFn {
return (controls: AbstractControl) => {
const control = controls.get(controlArrayName);
const value = control?.value;
const count = value.length;

if (count === 0) return { branchrequired: true };

return null;
};
}

public static matchValidator(controlName: string, checkControlName: string): ValidatorFn {
return (controls: AbstractControl) => {
const control = controls.get(controlName);
Expand Down
Loading

0 comments on commit 176563e

Please sign in to comment.