From 51e5eff58534e81de9e4b125a0ebf069190db4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3hanna=20Magn=C3=BAsd=C3=B3ttir?= Date: Thu, 7 Nov 2024 13:15:18 +0000 Subject: [PATCH] fix(samgongustofa): Disable "Continue" button when selecting vehicle with error (and user has over 20 vehicles) (#16752) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/fields/VehiclesField/index.tsx | 2 +- .../FindVehicleFormField.tsx | 60 +++++++++++++------ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx index 8706ba768779..a3b37a8d45be 100644 --- a/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx +++ b/libs/application/templates/transport-authority/transfer-of-vehicle-ownership/src/fields/VehiclesField/index.tsx @@ -60,9 +60,9 @@ export const VehiclesField: FC> = ( {currentVehicleList.totalRecords > 20 ? ( > = ({ | VehicleDetails | MachineDetails | EnergyFundVehicleDetailsWithGrant = extractDetails(response) + setValues(details) const isVehicleFound = !!details setVehicleNotFound(!isVehicleFound) - setSubmitButtonDisabled && setSubmitButtonDisabled(!isVehicleFound) + setSubmitButtonDisabled?.(!isVehicleFound) } catch (error) { console.error('error', error) setVehicleNotFound(true) setVehicleDetails(null) setMachineDetails(null) setEnergyDetails(null) - setSubmitButtonDisabled && setSubmitButtonDisabled(true) + setSubmitButtonDisabled?.(true) } finally { setIsLoading(false) } @@ -229,27 +230,43 @@ export const FindVehicleFormField: FC> = ({ } } const setVehicleValues = (vehicleDetails: VehicleDetails) => { + const vehicleDisabled = + additionalErrors && + vehicleDetails && + (!vehicleDetails.isDebtLess || + !!vehicleDetails.validationErrorMessages?.length) + + const permno = vehicleDisabled ? '' : vehicleDetails.permno || '' + setValue('findVehicle', true) + setValue(`${field.id}.type`, vehicleDetails.make) setValue(`${field.id}.make`, vehicleDetails.make) - setValue(`${field.id}.plate`, plate) + setValue(`${field.id}.plate`, permno) setValue(`${field.id}.color`, vehicleDetails.color || undefined) setValue(`${field.id}.requireMileage`, vehicleDetails.requireMileage) setValue(`${field.id}.mileageReading`, vehicleDetails.mileageReading) + setValue('vehicleMileage.requireMileage', vehicleDetails?.requireMileage) setValue('vehicleMileage.mileageReading', vehicleDetails?.mileageReading) - setValue('vehicleInfo.plate', plate) - setValue('vehicleInfo.type', vehicleDetails.make) + + if (permno) setValue('vehicleInfo.plate', permno) + if (permno) setValue('vehicleInfo.type', vehicleDetails.make) + + setSubmitButtonDisabled?.(!vehicleDisabled || false) + setVehicleDetails(vehicleDetails) } const setMachineValues = (machineDetails: MachineDetails) => { + const machineDisabled = machineDetails.disabled + if (application.typeId === 'StreetRegistration') { const mustInspect = mustInspectBeforeStreetRegistration( application?.externalData, machineDetails.regNumber || '', ) - if (mustInspect && !machineDetails.disabled) { + if (mustInspect && !machineDisabled) { machineDetails = { ...machineDetails, disabled: true, @@ -264,6 +281,7 @@ export const FindVehicleFormField: FC> = ({ } } setValue('findVehicle', true) + setValue( `${field.id}.paymentRequiredForOwnerChange`, machineDetails.paymentRequiredForOwnerChange, @@ -275,11 +293,13 @@ export const FindVehicleFormField: FC> = ({ setValue(`${field.id}.plate`, machineDetails.plate || '') setValue(`${field.id}.ownerNumber`, machineDetails.ownerNumber || '') setValue(`${field.id}.id`, machineDetails.id) - setValue('pickMachine.id', machineDetails.id) setValue(`${field.id}.date`, new Date().toISOString()) - setValue('pickMachine.isValid', machineDetails.disabled ? undefined : true) - setSubmitButtonDisabled && - setSubmitButtonDisabled(!machineDetails.disabled || false) + + setValue('pickMachine.id', machineDetails.id) + setValue('pickMachine.isValid', machineDisabled ? undefined : true) + + setSubmitButtonDisabled?.(!machineDisabled || false) + setMachineDetails(machineDetails) } @@ -287,6 +307,7 @@ export const FindVehicleFormField: FC> = ({ vehicleDetailsWithGrant: EnergyFundVehicleDetailsWithGrant, ) => { setValue('findVehicle', true) + setValue(`${field.id}.type`, vehicleDetailsWithGrant.make) setValue(`${field.id}.plate`, plate) setValue(`${field.id}.color`, vehicleDetailsWithGrant.color || undefined) @@ -304,25 +325,28 @@ export const FindVehicleFormField: FC> = ({ `${field.id}.grantItemCode`, vehicleDetailsWithGrant.vehicleGrantItemCode, ) + setEnergyDetails(vehicleDetailsWithGrant) } - const isDisabled = + const vehicleDisabled = additionalErrors && vehicleDetails && (!vehicleDetails.isDebtLess || !!vehicleDetails.validationErrorMessages?.length) + const machineDisabled = machineDetails?.disabled + useEffect(() => { if (!submitButtonDisabledCalled) { - setSubmitButtonDisabled && setSubmitButtonDisabled(true) + setSubmitButtonDisabled?.(true) setSubmitButtonDisabledCalled(true) } if (plate.length === 5 || plate.length === 6 || plate.length === 7) { setButtonDisabled(false) } - if (machineDetails && machineDetails.disabled) { - setSubmitButtonDisabled && setSubmitButtonDisabled(true) + if (vehicleDisabled || machineDisabled) { + setSubmitButtonDisabled?.(true) } setFieldLoadingState?.(isLoading) }, [isLoading]) @@ -389,7 +413,7 @@ export const FindVehicleFormField: FC> = ({ )} {vehicleDetails && !vehicleNotFound && ( > = ({ )} {machineDetails && !vehicleNotFound && ( > = ({ }} /> )} - {vehicleDetails && isDisabled && ( + {vehicleDetails && vehicleDisabled && ( > = ({ /> )} - {machineDetails && machineDetails.disabled && ( + {machineDetails && machineDisabled && (