diff --git a/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts b/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts index cfa527eba..acb49a932 100644 --- a/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts +++ b/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts @@ -186,25 +186,26 @@ export class TechRecordSummaryComponent implements OnInit, OnDestroy, AfterViewI // TODO clean this up in the future const formControl = this.form.get('techRecord_vehicleConfiguration'); formControl?.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => { - if (!value) { - return; - } - if (this.techRecordCalculated?.techRecord_vehicleType === VehicleTypes.HGV && value === 'articulated') { + if (value && formControl?.dirty) { + if (this.techRecordCalculated?.techRecord_vehicleType === VehicleTypes.HGV && value === 'articulated') { + this.form.patchValue({ + techRecord_bodyType_description: 'articulated', + techRecord_bodyType_code: 'a', + }); + } + + const functionCodes: Record = { + rigid: 'R', + articulated: 'A', + 'semi-trailer': 'A', + }; + + const functionCode = functionCodes[value]; this.form.patchValue({ - techRecord_bodyType_description: 'articulated', - techRecord_bodyType_code: 'a', + techRecord_functionCode: functionCode, }); + formControl.markAsPristine(); } - const functionCodes: Record = { - rigid: 'R', - articulated: 'A', - 'semi-trailer': 'A', - }; - - const functionCode = functionCodes[value]; - this.form.patchValue({ - techRecord_functionCode: functionCode, - }); }); } diff --git a/src/app/forms/custom-sections/vehicle-section/vehicle-section-edit/vehicle-section-edit.component.ts b/src/app/forms/custom-sections/vehicle-section/vehicle-section-edit/vehicle-section-edit.component.ts index dac152d38..cc9147000 100644 --- a/src/app/forms/custom-sections/vehicle-section/vehicle-section-edit/vehicle-section-edit.component.ts +++ b/src/app/forms/custom-sections/vehicle-section/vehicle-section-edit/vehicle-section-edit.component.ts @@ -12,7 +12,6 @@ import { TagType } from '@components/tag/tag.component'; import { VehicleClassDescription } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/vehicleClassDescription.enum.js'; import { FuelPropulsionSystem } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete'; import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type'; -import { TechRecordType as TechRecordTypeVerb } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-verb'; import { CommonValidatorsService } from '@forms/validators/common-validators.service'; import { CouplingTypeOptions } from '@models/coupling-type-enum'; import { @@ -42,7 +41,7 @@ import { V3TechRecordModel, VehicleSizes, VehicleTypes } from '@models/vehicle-t import { Store } from '@ngrx/store'; import { FormNodeWidth, TagTypeLabels } from '@services/dynamic-forms/dynamic-form.types'; import { TechnicalRecordService } from '@services/technical-record/technical-record.service'; -import { ReplaySubject, takeUntil } from 'rxjs'; +import { ReplaySubject } from 'rxjs'; type VehicleSectionForm = Partial, FormControl>>; @@ -101,8 +100,6 @@ export class VehicleSectionEditComponent implements OnInit, OnDestroy { parent.addControl(key, control, { emitEvent: false }); } } - - this.handleUpdateFunctionCode(); } ngOnDestroy(): void { @@ -266,27 +263,6 @@ export class VehicleSectionEditComponent implements OnInit, OnDestroy { }; } - handleUpdateFunctionCode() { - const control = this.form.controls.techRecord_vehicleConfiguration; - control?.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => { - if (value && control?.dirty) { - const functionCodes: Record = { - rigid: 'R', - articulated: 'A', - 'semi-trailer': 'A', - }; - - const functionCode = functionCodes[value]; - - this.technicalRecordService.updateEditingTechRecord({ - techRecord_functionCode: functionCode, - } as TechRecordTypeVerb<'put'>); - - control.markAsPristine(); - } - }); - } - handlePsvPassengersChange(): ValidatorFn { return (control: AbstractControl): ValidationErrors | null => { if (control.dirty) {