Skip to content

Commit

Permalink
fix(transfer-of-machine-ownership): seller cant be buyer (#16130)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
sigruntg and kodiakhq[bot] authored Sep 25, 2024
1 parent 1ea2e20 commit 23d2dbd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FieldBaseProps } from '@island.is/application/types'
import { FC } from 'react'
import { doSellerAndBuyerHaveSameNationalId } from '../../utils'

export const StopBuyerIfSameAsSeller: FC<
React.PropsWithChildren<FieldBaseProps>
> = (props) => {
const { application, setBeforeSubmitCallback } = props

setBeforeSubmitCallback?.(async () => {
if (doSellerAndBuyerHaveSameNationalId(application.answers)) {
return [false, '']
}
return [true, null]
})

return <></>
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { ApplicationStatus } from './ApplicationStatus'
export { MachinesField } from './MachinesField'
export { Review } from './Review'
export { StopBuyerIfSameAsSeller } from './StopBuyerIfSameAsSeller'
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
buildAlertMessageField,
buildCustomField,
buildMultiField,
buildNationalIdWithNameField,
buildPhoneField,
buildSubSection,
buildSubmitField,
buildTextField,
} from '@island.is/application/core'
import { information } from '../../../lib/messages'
import { FormValue } from '@island.is/application/types'
import { doSellerAndBuyerHaveSameNationalId } from '../../../utils'

export const buyerSubSection = buildSubSection({
id: 'buyer',
Expand Down Expand Up @@ -35,6 +38,19 @@ export const buyerSubSection = buildSubSection({
width: 'half',
required: true,
}),
buildAlertMessageField({
id: 'buyer.alertMessage',
alertType: 'warning',
title: information.labels.buyer.alertTitle,
message: information.labels.buyer.alertMessage,
condition: (answer: FormValue) =>
doSellerAndBuyerHaveSameNationalId(answer),
}),
buildCustomField({
id: 'buyer.custom',
title: '',
component: 'StopBuyerIfSameAsSeller',
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ export const information = {
defaultMessage: 'Staðfesta',
description: 'Submit button for buyer',
},
alertTitle: {
id: 'aosh.tmo.application:information.labels.buyer.alertTitle',
defaultMessage: 'Kennitala sú sama og hjá seljanda',
description: `Buyer alert title`,
},
alertMessage: {
id: 'aosh.tmo.application:information.labels.buyer.alertMessage',
defaultMessage:
'Seljandi og kaupandi getur ekki verið sá sami. Vinsamlega skráðu nýja kennitölu.',
description: `Buyer alert message`,
},
}),
buyerOperators: defineMessages({
title: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getValueViaPath } from '@island.is/application/core'
import { FormValue } from '@island.is/application/types'

export const doSellerAndBuyerHaveSameNationalId = (answers: FormValue) => {
const buyerNationalId = getValueViaPath(
answers,
'buyer.nationalId',
'',
) as string
const sellerNationalId = getValueViaPath(
answers,
'seller.nationalId',
'',
) as string

return buyerNationalId === sellerNationalId
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { getReviewSteps } from './getReviewSteps'
export { hasReviewerApproved } from './hasReviewerApproved'
export { getApproveAnswers } from './getApproveAnswers'
export { getRejecter } from './getRejecter'
export { doSellerAndBuyerHaveSameNationalId } from './doSellerAndBuyerHaveSameNationalId'

export const getChargeItemCodes = (
application: Application<FormValue>,
Expand Down

0 comments on commit 23d2dbd

Please sign in to comment.