|
| 1 | +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; |
| 2 | +import { CommonApplicationHelper } from '@app/core/services/common-application.helper'; |
| 3 | +import { ConfigService } from '@app/core/services/config.service'; |
| 4 | +import { FileUtilService } from '@app/core/services/file-util.service'; |
| 5 | +import { UtilService } from '@app/core/services/util.service'; |
| 6 | +import { FormControlValidators } from '@app/core/validators/form-control.validators'; |
| 7 | +import { FormGroupValidators } from '@app/core/validators/form-group.validators'; |
| 8 | +import { FormatDatePipe } from '@app/shared/pipes/format-date.pipe'; |
| 9 | +import { SPD_CONSTANTS } from '../constants/constants'; |
| 10 | + |
| 11 | +export abstract class MetalDealersApplicationHelper extends CommonApplicationHelper { |
| 12 | + businessOwnerFormGroup: FormGroup = this.formBuilder.group({ |
| 13 | + legalBusinessName: new FormControl('', [FormControlValidators.required]), |
| 14 | + tradeName: new FormControl('', [FormControlValidators.required]), |
| 15 | + givenName: new FormControl(''), |
| 16 | + middleName: new FormControl(''), |
| 17 | + surname: new FormControl('', [FormControlValidators.required]), |
| 18 | + }); |
| 19 | + |
| 20 | + businessManagerFormGroup: FormGroup = this.formBuilder.group({ |
| 21 | + givenName: new FormControl(''), |
| 22 | + middleName: new FormControl(''), |
| 23 | + surname: new FormControl('', [FormControlValidators.required]), |
| 24 | + phoneNumber: new FormControl('', [FormControlValidators.required]), |
| 25 | + emailAddress: new FormControl('', [FormControlValidators.email]), |
| 26 | + }); |
| 27 | + |
| 28 | + businessAddressFormGroup: FormGroup = this.formBuilder.group({ |
| 29 | + addressSelected: new FormControl(false), |
| 30 | + addressLine1: new FormControl(''), |
| 31 | + addressLine2: new FormControl(''), |
| 32 | + city: new FormControl(''), |
| 33 | + postalCode: new FormControl(''), |
| 34 | + province: new FormControl(''), |
| 35 | + country: new FormControl(''), |
| 36 | + }); |
| 37 | + |
| 38 | + businessMailingAddressFormGroup: FormGroup = this.formBuilder.group( |
| 39 | + { |
| 40 | + addressSelected: new FormControl(false), |
| 41 | + addressLine1: new FormControl(''), |
| 42 | + addressLine2: new FormControl(''), |
| 43 | + city: new FormControl(''), |
| 44 | + postalCode: new FormControl(''), |
| 45 | + province: new FormControl(''), |
| 46 | + country: new FormControl(''), |
| 47 | + isAddressTheSame: new FormControl(false), |
| 48 | + }, |
| 49 | + { |
| 50 | + validators: [ |
| 51 | + FormGroupValidators.conditionalDefaultRequiredTrueValidator( |
| 52 | + 'addressSelected', |
| 53 | + (_form) => _form.get('isAddressTheSame')?.value != true |
| 54 | + ), |
| 55 | + FormGroupValidators.conditionalRequiredValidator( |
| 56 | + 'addressLine1', |
| 57 | + (_form) => _form.get('isAddressTheSame')?.value != true |
| 58 | + ), |
| 59 | + FormGroupValidators.conditionalRequiredValidator( |
| 60 | + 'city', |
| 61 | + (_form) => _form.get('isAddressTheSame')?.value != true |
| 62 | + ), |
| 63 | + FormGroupValidators.conditionalRequiredValidator( |
| 64 | + 'postalCode', |
| 65 | + (_form) => _form.get('isAddressTheSame')?.value != true |
| 66 | + ), |
| 67 | + FormGroupValidators.conditionalRequiredValidator( |
| 68 | + 'province', |
| 69 | + (_form) => _form.get('isAddressTheSame')?.value != true |
| 70 | + ), |
| 71 | + FormGroupValidators.conditionalRequiredValidator( |
| 72 | + 'country', |
| 73 | + (_form) => _form.get('isAddressTheSame')?.value != true |
| 74 | + ), |
| 75 | + ], |
| 76 | + } |
| 77 | + ); |
| 78 | + |
| 79 | + branchesFormGroup: FormGroup = this.formBuilder.group({ |
| 80 | + branches: this.formBuilder.array([]), |
| 81 | + }); |
| 82 | + |
| 83 | + branchFormGroup: FormGroup = this.formBuilder.group({ |
| 84 | + addressSelected: new FormControl(false, [Validators.requiredTrue]), |
| 85 | + addressLine1: new FormControl('', [FormControlValidators.required]), |
| 86 | + addressLine2: new FormControl(''), |
| 87 | + city: new FormControl('', [FormControlValidators.required]), |
| 88 | + postalCode: new FormControl('', [FormControlValidators.required]), |
| 89 | + province: new FormControl('', [FormControlValidators.required]), |
| 90 | + country: new FormControl('', [ |
| 91 | + FormControlValidators.required, |
| 92 | + FormControlValidators.requiredValue(SPD_CONSTANTS.address.countryCA, SPD_CONSTANTS.address.countryCanada), |
| 93 | + ]), |
| 94 | + givenName: new FormControl(''), |
| 95 | + middleName: new FormControl(''), |
| 96 | + surname: new FormControl('', [FormControlValidators.required]), |
| 97 | + phoneNumber: new FormControl('', [FormControlValidators.required]), |
| 98 | + emailAddress: new FormControl('', [FormControlValidators.email]), |
| 99 | + }); |
| 100 | + |
| 101 | + consentAndDeclarationFormGroup: FormGroup = this.formBuilder.group({ |
| 102 | + check1: new FormControl(null, [Validators.requiredTrue]), |
| 103 | + agreeToCompleteAndAccurate: new FormControl(null, [Validators.requiredTrue]), |
| 104 | + dateSigned: new FormControl({ value: null, disabled: true }), |
| 105 | + captchaFormGroup: new FormGroup({ |
| 106 | + token: new FormControl('', FormControlValidators.required), |
| 107 | + }), |
| 108 | + }); |
| 109 | + |
| 110 | + constructor( |
| 111 | + formBuilder: FormBuilder, |
| 112 | + protected configService: ConfigService, |
| 113 | + protected formatDatePipe: FormatDatePipe, |
| 114 | + protected utilService: UtilService, |
| 115 | + protected fileUtilService: FileUtilService |
| 116 | + ) { |
| 117 | + super(formBuilder); |
| 118 | + } |
| 119 | + |
| 120 | + getFullNameWithMiddle( |
| 121 | + givenName: string | null | undefined, |
| 122 | + middleName: string | null | undefined, |
| 123 | + surname: string | null | undefined |
| 124 | + ): string { |
| 125 | + const userNameArray: string[] = []; |
| 126 | + if (givenName) { |
| 127 | + userNameArray.push(givenName); |
| 128 | + } |
| 129 | + if (middleName) { |
| 130 | + userNameArray.push(middleName); |
| 131 | + } |
| 132 | + if (surname) { |
| 133 | + userNameArray.push(surname); |
| 134 | + } |
| 135 | + return userNameArray.join(' '); |
| 136 | + } |
| 137 | + |
| 138 | + getSummarybusinessOwnerDataname(modelData: any): string { |
| 139 | + return this.getFullNameWithMiddle( |
| 140 | + modelData.businessOwnerData.givenName, |
| 141 | + modelData.businessOwnerData.middleName, |
| 142 | + modelData.businessOwnerData.surname |
| 143 | + ); |
| 144 | + } |
| 145 | + getSummarybusinessOwnerDatalegalBusinessName(modelData: any): string { |
| 146 | + return modelData.businessOwnerData.legalBusinessName ?? ''; |
| 147 | + } |
| 148 | + getSummarybusinessOwnerDatatradeName(modelData: any): string { |
| 149 | + return modelData.businessOwnerData.tradeName ?? ''; |
| 150 | + } |
| 151 | + |
| 152 | + getSummarybusinessManagerDataname(modelData: any): string { |
| 153 | + return this.getFullNameWithMiddle( |
| 154 | + modelData.businessManagerData.givenName, |
| 155 | + modelData.businessManagerData.middleName, |
| 156 | + modelData.businessManagerData.surname |
| 157 | + ); |
| 158 | + } |
| 159 | + getSummarybusinessManagerDataphoneNumber(modelData: any): string { |
| 160 | + return modelData.businessManagerData.phoneNumber ?? ''; |
| 161 | + } |
| 162 | + getSummarybusinessManagerDataemailAddress(modelData: any): string { |
| 163 | + return modelData.businessManagerData.emailAddress ?? ''; |
| 164 | + } |
| 165 | +} |
0 commit comments