Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(samgongustofa): Include operators and co-owners in validation + other minor fixes #17609

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export class EnergyFundsService extends BaseTemplateApiService {
const currentVehicleList = application.externalData?.currentVehicles
?.data as VehiclesWithTotalCount

const currentvehicleDetails = application.answers.findVehicle
const currentvehicleDetails = getValueViaPath<boolean | undefined>(
application.answers,
'selectVehicle.findVehicle',
)
? (getValueViaPath(
application.answers,
'selectVehicle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
if (answers.findVehicle) {
if (getValueViaPath<boolean | undefined>(answers, 'machine.findVehicle')) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
if (answers.findVehicle) {
if (getValueViaPath<boolean | undefined>(answers, 'machine.findVehicle')) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
if (answers.findVehicle) {
if (getValueViaPath<boolean | undefined>(answers, 'machine.findVehicle')) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
if (answers.findVehicle) {
if (getValueViaPath<boolean | undefined>(answers, 'machine.findVehicle')) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getSelectedMachine = (
externalData: ExternalData,
answers: FormValue,
) => {
if (answers.findVehicle) {
if (getValueViaPath<boolean | undefined>(answers, 'machine.findVehicle')) {
const machine = getValueViaPath(answers, 'machine') as Machine
return machine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const getSelectedVehicle = (
externalData: ExternalData,
answers: FormValue,
) => {
if (answers.findVehicle) {
if (
getValueViaPath<boolean | undefined>(answers, 'selectVehicle.findVehicle')
) {
const vehicle = getValueViaPath(
answers,
'selectVehicle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const vehicleSubSection = buildSubSection({
title: information.labels.vehicle.mileage,
width: 'full',
variant: 'number',
required: true,
condition: (answers, externalData) => {
const vehicle = getSelectedVehicle(externalData, answers)
return vehicle?.requireMileage || false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const getSelectedVehicle = (
externalData: ExternalData,
answers: FormValue,
): VehiclesCurrentVehicle | undefined => {
if (answers.findVehicle) {
if (
getValueViaPath<boolean | undefined>(answers, 'pickVehicle.findVehicle')
) {
const vehicle = getValueViaPath(
answers,
'pickVehicle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const vehicleSubSection = buildSubSection({
title: information.labels.vehicle.mileage,
width: 'full',
variant: 'number',
required: true,
condition: (answers, externalData) => {
const vehicle = getSelectedVehicle(externalData, answers)
return vehicle?.requireMileage || false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const getSelectedVehicle = (
externalData: ExternalData,
answers: FormValue,
): VehiclesCurrentVehicle | undefined => {
if (answers.findVehicle) {
if (
getValueViaPath<boolean | undefined>(answers, 'pickVehicle.findVehicle')
) {
const vehicle = getValueViaPath(
answers,
'pickVehicle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const getSelectedVehicle = (
externalData: ExternalData,
answers: FormValue,
): VehiclesCurrentVehicle | undefined => {
if (answers.findVehicle) {
if (
getValueViaPath<boolean | undefined>(answers, 'pickVehicle.findVehicle')
) {
const vehicle = getValueViaPath(
answers,
'pickVehicle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const getSelectedVehicle = (
externalData: ExternalData,
answers: FormValue,
): VehiclesCurrentVehicle | undefined => {
if (answers.findVehicle) {
if (
getValueViaPath<boolean | undefined>(answers, 'pickVehicle.findVehicle')
) {
const vehicle = getValueViaPath(
answers,
'pickVehicle',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql, useQuery } from '@apollo/client'
import { VehiclesCurrentOwnerInfo } from '@island.is/api/schema'
import { getValueViaPath } from '@island.is/application/core'
import { getErrorViaPath, getValueViaPath } from '@island.is/application/core'
import { FieldBaseProps } from '@island.is/application/types'
import {
AlertMessage,
Expand All @@ -17,7 +17,7 @@ import { information } from '../../lib/messages'
import { getSelectedVehicle } from '../../utils'

export const CoOwner: FC<React.PropsWithChildren<FieldBaseProps>> = (props) => {
const { application, field, setFieldLoadingState } = props
const { application, field, setFieldLoadingState, errors } = props

const { formatMessage } = useLocale()
const { id } = field
Expand Down Expand Up @@ -51,70 +51,83 @@ export const CoOwner: FC<React.PropsWithChildren<FieldBaseProps>> = (props) => {
data.vehiclesDetail.coOwners.length > 0 ? (
<Box>
{data.vehiclesDetail.coOwners.map(
(coOwner: VehiclesCurrentOwnerInfo, index: number) => (
<Box marginTop={3}>
<Text variant="h5">
{formatMessage(information.labels.coOwner.title)}
{data.vehiclesDetail.coOwners.length > 1 ? ` ${index + 1}` : ''}
</Text>
<GridRow>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={`${id}[${index}].nationalId`}
name={`${id}[${index}].nationalId`}
defaultValue={coOwner.nationalId || ''}
label={formatMessage(information.labels.coOwner.nationalId)}
format="######-####"
readOnly
/>
</GridColumn>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={`${id}[${index}].name`}
name={`${id}[${index}].name`}
defaultValue={coOwner.owner || ''}
label={formatMessage(information.labels.coOwner.name)}
readOnly
/>
</GridColumn>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={`${id}[${index}].email`}
name={`${id}[${index}].email`}
label={formatMessage(information.labels.coOwner.email)}
defaultValue={
getValueViaPath(
application.answers,
`${id}[${index}].email`,
'',
) as string
}
type="email"
backgroundColor="blue"
required
/>
</GridColumn>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={`${id}[${index}].phone`}
name={`${id}[${index}].phone`}
label={formatMessage(information.labels.coOwner.phone)}
defaultValue={
getValueViaPath(
application.answers,
`${id}[${index}].phone`,
'',
) as string
}
type="tel"
format="###-####"
backgroundColor="blue"
required
/>
</GridColumn>
</GridRow>
</Box>
),
(coOwner: VehiclesCurrentOwnerInfo, index: number) => {
const nationalIdField = `${id}[${index}].nationalId`
const nameField = `${id}[${index}].name`
const emailField = `${id}[${index}].email`
const phoneField = `${id}[${index}].phone`

return (
<Box marginTop={3}>
<Text variant="h5">
{formatMessage(information.labels.coOwner.title)}
{data.vehiclesDetail.coOwners.length > 1
? ` ${index + 1}`
: ''}
</Text>
<GridRow>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={nationalIdField}
name={nationalIdField}
defaultValue={coOwner.nationalId || ''}
label={formatMessage(
information.labels.coOwner.nationalId,
)}
format="######-####"
readOnly
/>
</GridColumn>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={nameField}
name={nameField}
defaultValue={coOwner.owner || ''}
label={formatMessage(information.labels.coOwner.name)}
readOnly
/>
</GridColumn>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={emailField}
name={emailField}
label={formatMessage(information.labels.coOwner.email)}
defaultValue={
getValueViaPath(
application.answers,
emailField,
'',
) as string
}
type="email"
backgroundColor="blue"
required
error={errors && getErrorViaPath(errors, emailField)}
/>
</GridColumn>
<GridColumn span={['1/1', '1/1', '1/2']} paddingTop={2}>
<InputController
id={phoneField}
name={phoneField}
label={formatMessage(information.labels.coOwner.phone)}
defaultValue={
getValueViaPath(
application.answers,
phoneField,
'',
) as string
}
type="tel"
format="###-####"
backgroundColor="blue"
required
error={errors && getErrorViaPath(errors, phoneField)}
/>
</GridColumn>
</GridRow>
</Box>
)
},
johannaagma marked this conversation as resolved.
Show resolved Hide resolved
)}
</Box>
) : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const vehicleSubSection = buildSubSection({
title: information.labels.vehicle.mileage,
width: 'full',
variant: 'number',
required: true,
condition: (answers, externalData) => {
const vehicle = getSelectedVehicle(externalData, answers)
return vehicle?.requireMileage || false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const getSelectedVehicle = (
externalData: ExternalData,
answers: FormValue,
): VehiclesCurrentVehicle | undefined => {
if (answers.findVehicle) {
if (
getValueViaPath<boolean | undefined>(answers, 'pickVehicle.findVehicle')
) {
const vehicle = getValueViaPath(
answers,
'pickVehicle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export const FindVehicleFormField: FC<React.PropsWithChildren<Props>> = ({

const permno = vehicleDisabled ? '' : vehicleDetails.permno || ''

setValue('findVehicle', true)
setValue(`${field.id}.findVehicle`, true)

setValue(`${field.id}.type`, vehicleDetails.make)
setValue(`${field.id}.make`, vehicleDetails.make)
Expand Down Expand Up @@ -294,7 +294,7 @@ export const FindVehicleFormField: FC<React.PropsWithChildren<Props>> = ({
}
}
}
setValue('findVehicle', true)
setValue(`${field.id}.findVehicle`, true)

setValue(
`${field.id}.paymentRequiredForOwnerChange`,
Expand All @@ -320,7 +320,7 @@ export const FindVehicleFormField: FC<React.PropsWithChildren<Props>> = ({
const setEnergyFundsValues = (
vehicleDetailsWithGrant: EnergyFundVehicleDetailsWithGrant,
) => {
setValue('findVehicle', true)
setValue(`${field.id}.findVehicle`, true)

setValue(`${field.id}.type`, vehicleDetailsWithGrant.make)
setValue(`${field.id}.plate`, plate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ export class VehicleOwnerChangeClient {
saleAmount: ownerChange.saleAmount,
insuranceCompanyCode: insuranceCompanyCode,
useGroup: useGroup,
operatorEmail: null,
operators: null,
coOwners: null,
operatorEmail:
ownerChange.operators?.find((x) => x.isMainOperator)?.email || null,
operators:
ownerChange.operators?.map((operator) => ({
personIdNumber: operator.ssn,
mainOperator: operator.isMainOperator ? 1 : 0,
})) || null,
coOwners:
ownerChange.coOwners?.map((coOwner) => ({
personIdNumber: coOwner.ssn,
})) || null,
reportingPersonIdNumber: auth.nationalId,
mileage: ownerChange.mileage,
},
Expand Down
Loading