Skip to content

Commit

Permalink
feat(feat/cb2-14449): fix for function code issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Evans committed Jan 14, 2025
1 parent 32a4d41 commit 0f7f130
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
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<string, string> = {
rigid: 'R',
articulated: 'A',
'semi-trailer': 'A',
};

const functionCode = functionCodes[value];
this.form.patchValue({
techRecord_functionCode: functionCode,
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Record<keyof TechRecordType<'hgv' | 'car' | 'psv' | 'lgv' | 'trl'>, FormControl>>;

Expand Down Expand Up @@ -101,8 +100,6 @@ export class VehicleSectionEditComponent implements OnInit, OnDestroy {
parent.addControl(key, control, { emitEvent: false });
}
}

this.handleUpdateFunctionCode();
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -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<string, string> = {
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) {
Expand Down

0 comments on commit 0f7f130

Please sign in to comment.