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(transfer-of-machine-ownership): seller cant be buyer #16130

Merged
merged 3 commits into from
Sep 25, 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
@@ -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