Skip to content

Commit

Permalink
adding custom changeanswers
Browse files Browse the repository at this point in the history
  • Loading branch information
sigruntg committed Sep 13, 2024
1 parent bb9e869 commit 30252cd
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class RegisterNewMachineTemplateService extends BaseTemplateApiService {
})

await this.workMachineClientService.addNewMachine(auth, {
xCorrelationID: application.id,
machineRegistrationCreateDto: {
importer: {
nationalId: answers.importerInformation.importer.nationalId,
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)
}

return <></>
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export const MachineType: FC<React.PropsWithChildren<FieldBaseProps>> = (
setBeforeSubmitCallback?.(async () => {
// Call updateApplication for basicInformation.type and basicInformation.model
// Get information for basicInformation here and updateApplication
if (modelFromAnswers === model && typeFromAnswers === type) {
return [true, null]
}
let response = undefined
try {
response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { MachineType } from './MachineType'
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 @@ -5,6 +5,7 @@ import {
buildPhoneField,
getValueViaPath,
buildSelectField,
buildCustomField,
} from '@island.is/application/core'
import { information } from '../../../lib/messages'
import { Application } from '@island.is/api/schema'
Expand Down Expand Up @@ -103,6 +104,30 @@ export const ImporterInformationSubSection = buildSubSection({
'',
) as string,
}),
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
buildPhoneField,
buildRadioField,
buildSelectField,
buildCustomField,
} from '@island.is/application/core'
import { information } from '../../../lib/messages'
import { FormValue, NO, YES } from '@island.is/application/types'
Expand Down Expand Up @@ -88,6 +89,18 @@ export const OwnerInformationSubSection = buildSubSection({
maxLength: 250,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildCustomField(
{
id: 'ownerInformation.custom',
title: '',
component: 'ChangeAnswers',
},
{
sectionName: 'operatorInformation',
questionName: 'hasOperator',
person: 'operator',
},
),
],
}),
],
Expand Down

0 comments on commit 30252cd

Please sign in to comment.