Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaagma committed Nov 19, 2024
1 parent 6d5f553 commit c3e946e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export interface VehicleDetails {
requireMileage?: boolean | null
mileageReading?: string | null
isDebtLess?: boolean | null
validationErrorMessages?: ValidationErrorMessage[] | null
validationErrorMessages?: ValidationErrorMessage[]
}

export interface PlateOwnership {
regno: string
startDate: string
endDate: string
validationErrorMessages?: ValidationErrorMessage[] | null
validationErrorMessages?: ValidationErrorMessage[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FC, useState } from 'react'
import { useFormContext } from 'react-hook-form'
import { RadioController } from '@island.is/shared/form-fields'
import { PlateOwnership, VehicleDetails } from './VehicleDetails'
import { MessageDescriptor } from 'react-intl'

interface Option {
value: string
Expand Down Expand Up @@ -45,11 +46,7 @@ export const VehicleRadioFormField: FC<React.PropsWithChildren<Props>> = ({

const [selectedValue, setSelectedValue] = useState<string | undefined>(
answersSelectedValueKey &&
(getValueViaPath(
application.answers,
answersSelectedValueKey,
'',
) as string),
getValueViaPath<string>(application.answers, answersSelectedValueKey, ''),
)

const onRadioControllerSelect = (s: string) => {
Expand Down Expand Up @@ -81,7 +78,7 @@ export const VehicleRadioFormField: FC<React.PropsWithChildren<Props>> = ({
}

const vehicleOptions = (vehicles: VehicleDetails[]) => {
const options = [] as Option[]
const options: Option[] = []

for (const [index, vehicle] of vehicles.entries()) {
const hasError = !!vehicle.validationErrorMessages?.length
Expand Down Expand Up @@ -131,10 +128,10 @@ export const VehicleRadioFormField: FC<React.PropsWithChildren<Props>> = ({
const message =
field.validationErrorMessages &&
formatMessage(
getValueViaPath(
getValueViaPath<MessageDescriptor>(
field.validationErrorMessages,
error.errorNo || '',
),
) || '',
)
const defaultMessage = error.defaultMessage
const fallbackMessage =
Expand Down Expand Up @@ -168,7 +165,7 @@ export const VehicleRadioFormField: FC<React.PropsWithChildren<Props>> = ({
}

const plateOptions = (plates: PlateOwnership[]) => {
const options = [] as Option[]
const options: Option[] = []

for (const [index, plate] of plates.entries()) {
const hasError = !!plate.validationErrorMessages?.length
Expand Down Expand Up @@ -216,10 +213,10 @@ export const VehicleRadioFormField: FC<React.PropsWithChildren<Props>> = ({
const message =
field.validationErrorMessages &&
formatMessage(
getValueViaPath(
getValueViaPath<MessageDescriptor>(
field.validationErrorMessages,
error.errorNo || '',
),
) || '',
)

const defaultMessage = error.defaultMessage
Expand Down Expand Up @@ -271,7 +268,7 @@ export const VehicleRadioFormField: FC<React.PropsWithChildren<Props>> = ({
options={options}
/>

{!selectedValue?.length && (errors as any)?.[field.id] && (
{!selectedValue?.length && !!errors?.[field.id] && (
<InputError
errorMessage={
field.inputErrorMessage &&
Expand Down

0 comments on commit c3e946e

Please sign in to comment.