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(register-new-machine): small fixes #15993

Merged
merged 13 commits into from
Sep 16, 2024
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 @@ -61,15 +61,17 @@ export class RegisterNewMachineTemplateService extends BaseTemplateApiService {
auth,
}: TemplateApiModuleActionProps): Promise<void> {
const answers = application.answers as unknown as NewMachineAnswers
const techInfo = {} as { [key: string]: string | undefined }
const techInfo = {} as { [key: string]: string | boolean | undefined }

answers.techInfo.forEach(({ variableName, value }) => {
if (variableName && value) {
techInfo[variableName] = value
techInfo[variableName] =
value === 'yes' ? true : value === 'no' ? false : value
}
})

await this.workMachineClientService.addNewMachine(auth, {
xCorrelationID: application.id,
machineRegistrationCreateDto: {
importer: {
nationalId: answers.importerInformation.importer.nationalId,
Expand All @@ -83,20 +85,20 @@ export class RegisterNewMachineTemplateService extends BaseTemplateApiService {
email: answers.importerInformation.importer.email,
},
owner:
answers.importerInformation.isOwnerOtherThanImporter === 'yes'
answers.ownerInformation.isOwnerOtherThanImporter === 'yes'
? {
nationalId: answers.importerInformation.owner?.nationalId ?? '',
name: answers.importerInformation.owner?.name ?? '',
address: answers.importerInformation.owner?.address ?? '',
postalCode: answers.importerInformation.owner?.postCode
? parseInt(answers.importerInformation.owner?.postCode, 10)
nationalId: answers.ownerInformation.owner?.nationalId ?? '',
name: answers.ownerInformation.owner?.name ?? '',
address: answers.ownerInformation.owner?.address ?? '',
postalCode: answers.ownerInformation.owner?.postCode
? parseInt(answers.ownerInformation.owner?.postCode, 10)
: 0,
gsm: answers.importerInformation.owner?.phone ?? '',
email: answers.importerInformation.owner?.email ?? '',
gsm: answers.ownerInformation.owner?.phone ?? '',
email: answers.ownerInformation.owner?.email ?? '',
}
: undefined,
supervisor:
answers.operatorInformation.hasOperator === 'yes'
answers.operatorInformation?.hasOperator === 'yes'
? {
nationalId:
answers.operatorInformation.operator?.nationalId ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const AboutMachine: FC<React.PropsWithChildren<FieldBaseProps>> = (
backgroundColor="blue"
required
disabled={fromService}
maxLength={50}
onChange={(e) => setType(e.target.value)}
error={
displayError && type.length === 0
Expand All @@ -145,6 +146,7 @@ export const AboutMachine: FC<React.PropsWithChildren<FieldBaseProps>> = (
backgroundColor="blue"
required
disabled={fromService}
maxLength={50}
onChange={(e) => setModel(e.target.value)}
error={
displayError && model.length === 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FieldBaseProps, NO } from '@island.is/application/types'
import { FC } from 'react'
import { useFormContext } from 'react-hook-form'
import { getValueViaPath } from '@island.is/application/core'
import { PersonInformation } from '../../lib/dataSchema'

interface ChangeAnswersProps {
field: {
props: {
sectionName: string
questionName: string
person: string
}
}
}

export const ChangeAnswers: FC<
React.PropsWithChildren<FieldBaseProps & ChangeAnswersProps>
> = (props) => {
const { application, field } = props
const { sectionName, questionName, person } = field.props
const { setValue } = useFormContext()

const personInformation = getValueViaPath(
application.answers,
`${sectionName}.${person}`,
) as PersonInformation

if (!personInformation) {
setValue(`${sectionName}.${questionName}`, NO)
}
sigruntg marked this conversation as resolved.
Show resolved Hide resolved

return <></>
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ export const MachineType: FC<React.PropsWithChildren<FieldBaseProps>> = (
setBeforeSubmitCallback?.(async () => {
// Call updateApplication for basicInformation.type and basicInformation.model
// Get information for basicInformation here and updateApplication
const response =
type && model && type !== 'unknown' && model !== 'unknown'
? await getMachineCategoryCallback(type, model)
: undefined
if (modelFromAnswers === model && typeFromAnswers === type) {
return [true, null]
}
let response = undefined
try {
response =
type && model && type !== 'unknown' && model !== 'unknown'
? await getMachineCategoryCallback(type, model)
: undefined
} catch (e) {
console.error('Could not get machine category', e)
sigruntg marked this conversation as resolved.
Show resolved Hide resolved
}

const category =
response?.getMachineParentCategoryByTypeAndModel?.name ?? ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const Overview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
label: information.labels.owner.title,
value: isOwnerOtherThanImporter(application.answers)
? getPersonInformationForOverview(
'importerInformation.owner',
'ownerInformation.owner',
application.answers,
formatMessage,
)
Expand Down Expand Up @@ -133,7 +133,7 @@ export const Overview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
component: FieldComponents.KEY_VALUE,
title: '',
label: machine.labels.technicalMachineInformation.overviewTitle,
value: getTechnicalInformation(application.answers),
value: getTechnicalInformation(application.answers, formatMessage),
}}
/>
</ReviewGroup>
Expand All @@ -160,14 +160,6 @@ export const Overview: FC<React.PropsWithChildren<FieldBaseProps>> = ({
/>
</ReviewGroup>
)}

{canMaybeRegisterToTraffic(application.answers) && (
<AlertMessage
type="warning"
title={formatMessage(overview.labels.alertMessageTitle)}
message={formatMessage(overview.labels.alertMessageMessage)}
/>
)}
</Box>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { MachineType } from './MachineType'
export { LicensePlates } from './LicensePlates'
export { Overview } from './Overview'
export { AboutMachine } from './AboutMachine'
export { TechnicalInfo } from './TechnicalInfo'
export { ChangeAnswers } from './ChangeAnswers'
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {
buildTextField,
buildSubSection,
buildPhoneField,
buildRadioField,
buildDescriptionField,
getValueViaPath,
buildSelectField,
buildCustomField,
} from '@island.is/application/core'
import { information } from '../../../lib/messages'
import { Application } from '@island.is/api/schema'
import { FormValue, NO, YES } from '@island.is/application/types'
import { isOwnerOtherThanImporter } from '../../../utils/isOwnerOtherThanImporter'
import { postalCodes } from '@island.is/shared/utils'

export const ImporterInformationSubSection = buildSubSection({
id: 'importerInformation',
Expand All @@ -27,6 +26,7 @@ export const ImporterInformationSubSection = buildSubSection({
backgroundColor: 'white',
width: 'half',
readOnly: true,
maxLength: 100,
defaultValue: (application: Application) =>
getValueViaPath(
application.externalData,
Expand All @@ -53,19 +53,24 @@ export const ImporterInformationSubSection = buildSubSection({
title: information.labels.importer.address,
width: 'half',
required: true,
maxLength: 50,
defaultValue: (application: Application) =>
getValueViaPath(
application.externalData,
'identity.data.address.streetAddress',
'',
) as string,
}),
buildTextField({
buildSelectField({
id: 'importerInformation.importer.postCode',
title: information.labels.importer.postCode,
width: 'half',
required: true,
variant: 'number',
options: () => {
return postalCodes.map((code) => {
return { value: `${code}`, label: `${code}` }
})
},
defaultValue: (application: Application) =>
getValueViaPath(
application.externalData,
Expand All @@ -90,6 +95,7 @@ export const ImporterInformationSubSection = buildSubSection({
title: information.labels.importer.email,
width: 'half',
variant: 'email',
maxLength: 250,
required: true,
defaultValue: (application: Application) =>
getValueViaPath(
Expand All @@ -98,72 +104,30 @@ export const ImporterInformationSubSection = buildSubSection({
'',
) as string,
}),
buildDescriptionField({
id: 'importerInformation.description',
title: information.labels.importer.isOwnerOtherThenImporter,
marginTop: 4,
titleVariant: 'h5',
}),
buildRadioField({
id: 'importerInformation.isOwnerOtherThanImporter',
title: '',
width: 'half',
defaultValue: NO,
options: [
{
value: NO,
label: information.labels.radioButtons.radioOptionNo,
},
{
value: YES,
label: information.labels.radioButtons.radioOptionYes,
},
],
}),
buildTextField({
id: 'importerInformation.owner.name',
title: information.labels.owner.name,
width: 'half',
required: true,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildTextField({
id: 'importerInformation.owner.nationalId',
title: information.labels.owner.nationalId,
width: 'half',
required: true,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildTextField({
id: 'importerInformation.owner.address',
title: information.labels.owner.address,
width: 'half',
required: true,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildTextField({
id: 'importerInformation.owner.postCode',
title: information.labels.owner.postCode,
variant: 'number',
width: 'half',
required: true,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildPhoneField({
id: 'importerInformation.owner.phone',
title: information.labels.owner.phone,
width: 'half',
required: true,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildTextField({
id: 'importerInformation.owner.email',
title: information.labels.owner.email,
width: 'half',
variant: 'email',
required: true,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildCustomField(
{
id: 'importerInformation.custom',
title: '',
component: 'ChangeAnswers',
},
{
sectionName: 'ownerInformation',
questionName: 'isOwnerOtherThanImporter',
person: 'owner',
},
),
buildCustomField(
{
id: 'importerInformation.custom2',
title: '',
component: 'ChangeAnswers',
},
{
sectionName: 'operatorInformation',
questionName: 'hasOperator',
person: 'operator',
},
),
],
}),
],
Expand Down
Loading
Loading