Skip to content

Commit

Permalink
Merge branch 'main' into fix/eigendaskipti-validation-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
berglindoma13 authored Sep 19, 2024
2 parents 50f5f6a + e9ebcaf commit a4e5484
Show file tree
Hide file tree
Showing 27 changed files with 236 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,28 @@ export const subpoena = defineMessages({
'Notaður sem texti í áfram takka á Fyrirkall skrefi í dómaraflæði í ákærum.',
},
modalTitle: {
id: 'judicial.system.core:subpoena.modal_title_v2',
defaultMessage:
'Viltu senda sækjanda {courtDateHasChanged, select, true {nýtt } other {}}boð í þingfestingu?',
id: 'judicial.system.core:subpoena.modal_title_v3',
defaultMessage: 'Viltu senda fyrirkall?',
description: 'Notaður sem titill í modal glugga á Fyrirkallsskjá í ákærum.',
},
modalText: {
id: 'judicial.system.core:subpoena.modal_message',
defaultMessage:
'Ákæra og fyrirkall verða send til ákæranda.\nÁkærða verður birt ákæran og fyrirkallið rafrænt á island.is',
description: 'Notað sem skilaboð í modal glugga á Fyrirkallsskjá í ákærum',
},
modalPrimaryButtonText: {
id: 'judicial.system.core:subpoena.modal_primary_button_text',
defaultMessage: 'Senda boð',
id: 'judicial.system.core:subpoena.modal_primary_button_text_v2',
defaultMessage: 'Já, senda núna',
description:
'Notaður sem texti í staðfesta takka í modal glugga á Fyrirkallsskjá í ákærum.',
},
modalSecondaryButtonText: {
id: 'judicial.system.core:subpoena.modal_secondary_button_text',
defaultMessage: 'Hætta við',
description:
'Notaður sem texti í hætta takka í modal glugga á Fyrirkallsskjá í ákærum.',
},
subpoenaTypeTitle: {
id: 'judicial.system.core:subpoena.subpoena_type_title',
defaultMessage: 'Tegund fyrirkalls',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,34 @@ const Subpoena: FC = () => {
})
}

const allDataSentToServer = await Promise.all(promises)

if (!allDataSentToServer.every((result) => result)) {
return
}

if (
hasSentNotification(
!hasSentNotification(
NotificationType.COURT_DATE,
workingCase.notifications,
).hasSent &&
!courtDateHasChanged
).hasSent ||
courtDateHasChanged
) {
router.push(`${destination}/${workingCase.id}`)
} else {
setNavigateTo(destination)
promises.push(
sendNotification(workingCase.id, NotificationType.COURT_DATE),
)
}

const allDataSentToServer = await Promise.all(promises)
if (!allDataSentToServer.every((result) => result)) {
return
}

router.push(`${destination}/${workingCase.id}`)
},
[
isArraignmentDone,
sendCourtDateToServer,
workingCase,
workingCase.defendants,
workingCase.notifications,
workingCase.id,
courtDateHasChanged,
updateDefendant,
sendNotification,
],
)

Expand Down Expand Up @@ -165,7 +169,11 @@ const Subpoena: FC = () => {
previousUrl={`${constants.INDICTMENTS_RECEPTION_AND_ASSIGNMENT_ROUTE}/${workingCase.id}`}
nextIsLoading={isLoadingWorkingCase}
onNextButtonClick={() => {
handleNavigationTo(constants.INDICTMENTS_DEFENDER_ROUTE)
if (isArraignmentDone) {
router.push(
`${constants.INDICTMENTS_DEFENDER_ROUTE}/${workingCase.id}`,
)
} else setNavigateTo(constants.INDICTMENTS_DEFENDER_ROUTE)
}}
nextButtonText={
isArraignmentDone
Expand All @@ -177,18 +185,16 @@ const Subpoena: FC = () => {
</FormContentContainer>
{navigateTo !== undefined && (
<Modal
title={formatMessage(strings.modalTitle, {
courtDateHasChanged,
})}
title={formatMessage(strings.modalTitle)}
text={formatMessage(strings.modalText)}
onPrimaryButtonClick={() => {
sendNotification(workingCase.id, NotificationType.COURT_DATE)
router.push(`${navigateTo}/${workingCase.id}`)
handleNavigationTo(constants.INDICTMENTS_DEFENDER_ROUTE)
}}
onSecondaryButtonClick={() => {
router.push(`${navigateTo}/${workingCase.id}`)
setNavigateTo(undefined)
}}
primaryButtonText={formatMessage(strings.modalPrimaryButtonText)}
secondaryButtonText={formatMessage(core.continue)}
secondaryButtonText={formatMessage(strings.modalSecondaryButtonText)}
isPrimaryButtonLoading={false}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const envs = {
prod: 'cdn.contentful.com',
},
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: {
dev: '20',
dev: '40',
staging: '40',
prod: '40',
},
Expand Down
4 changes: 2 additions & 2 deletions charts/islandis/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ search-indexer-service:
env:
AIR_DISCOUNT_SCHEME_FRONTEND_HOSTNAME: 'loftbru.dev01.devland.is'
APPLICATION_URL: 'http://search-indexer-service'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '20'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '40'
CONTENTFUL_ENVIRONMENT: 'master'
CONTENTFUL_HOST: 'preview.contentful.com'
CONTENTFUL_SPACE: '8k0h54kbe6bj'
Expand Down Expand Up @@ -2036,7 +2036,7 @@ search-indexer-service:
env:
AIR_DISCOUNT_SCHEME_FRONTEND_HOSTNAME: 'loftbru.dev01.devland.is'
APPLICATION_URL: 'http://search-indexer-service'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '20'
CONTENTFUL_ENTRY_FETCH_CHUNK_SIZE: '40'
CONTENTFUL_ENVIRONMENT: 'master'
CONTENTFUL_HOST: 'preview.contentful.com'
CONTENTFUL_SPACE: '8k0h54kbe6bj'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const MachineAnswersSchema = z.object({
},
{ path: ['phone'] },
),
approveExternalData: z.boolean(),
approveExternalData: z.boolean().refine((v) => v),
location: z
.object({
address: z.string().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const MachineAnswersSchema = z.object({
fateOfMachine: z.string().optional(),
}),

approveExternalData: z.boolean(),
approveExternalData: z.boolean().refine((v) => v),
})

export type MachineAnswers = z.TypeOf<typeof MachineAnswersSchema>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export const ChangeAnswers: FC<
`${sectionName}.${person}`,
) as PersonInformation

if (!personInformation) {
if (
!personInformation ||
!personInformation.address ||
!personInformation.name ||
!personInformation.nationalId ||
!personInformation.postCode
) {
setValue(`${sectionName}.${questionName}`, NO)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const formFieldMapper = ({
variant: 'number',
max: maxLength ? parseInt(maxLength, 10) : undefined,
min: 0,
step: type === 'float' ? '0.0000000001' : '1',
}}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
buildPhoneField,
buildRadioField,
buildSelectField,
buildAlertMessageField,
} from '@island.is/application/core'
import { information } from '../../../lib/messages'
import { FormValue, NO, YES } from '@island.is/application/types'
import { hasOperator } from '../../../utils/hasOperator'
import { postalCodes } from '@island.is/shared/utils'
import { doOwnerAndOperatorHaveSameNationalId } from '../../../utils'

export const OperatorInformationSubSection = buildSubSection({
id: 'operatorInformation',
Expand Down Expand Up @@ -88,6 +90,14 @@ export const OperatorInformationSubSection = buildSubSection({
maxLength: 250,
condition: (answer: FormValue) => hasOperator(answer),
}),
buildAlertMessageField({
id: 'operatorInformation.alertMessage',
alertType: 'warning',
title: information.labels.operator.alertTitle,
message: information.labels.operator.alertMessage,
condition: (answer: FormValue) =>
doOwnerAndOperatorHaveSameNationalId(answer),
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import {
buildRadioField,
buildSelectField,
buildCustomField,
buildAlertMessageField,
} from '@island.is/application/core'
import { information } from '../../../lib/messages'
import { FormValue, NO, YES } from '@island.is/application/types'
import { isOwnerOtherThanImporter } from '../../../utils/isOwnerOtherThanImporter'
import {
isOwnerOtherThanImporter,
doOwnerAndImporterHaveSameNationalId,
} from '../../../utils'
import { postalCodes } from '@island.is/shared/utils'

export const OwnerInformationSubSection = buildSubSection({
Expand Down Expand Up @@ -89,6 +93,14 @@ export const OwnerInformationSubSection = buildSubSection({
maxLength: 250,
condition: (answer: FormValue) => isOwnerOtherThanImporter(answer),
}),
buildAlertMessageField({
id: 'ownerInformation.alertMessage',
alertType: 'warning',
title: information.labels.owner.alertTitle,
message: information.labels.owner.alertMessage,
condition: (answer: FormValue) =>
doOwnerAndImporterHaveSameNationalId(answer),
}),
buildCustomField(
{
id: 'ownerInformation.custom',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { NO, YES } from '@island.is/application/types'
import { z } from 'zod'
import { NEW, USED } from '../shared/types'
import * as kennitala from 'kennitala'
import { parsePhoneNumberFromString } from 'libphonenumber-js'

const emailRegex =
/^[\w!#$%&'*+/=?`{|}~^-]+(?:\.[\w!#$%&'*+/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i
const isValidEmail = (value: string) => emailRegex.test(value)
export const isValidPhoneNumber = (phoneNumber: string) => {
const phone = parsePhoneNumberFromString(phoneNumber, 'IS')
return phone && phone.isValid()
}

const PersonInformationSchema = z.object({
name: z.string().min(1),
Expand All @@ -10,8 +19,8 @@ const PersonInformationSchema = z.object({
.refine((nationalId) => nationalId && kennitala.isValid(nationalId)),
address: z.string().min(1),
postCode: z.string().min(1),
phone: z.string().min(1),
email: z.string().min(1),
phone: z.string().refine((v) => isValidPhoneNumber(v)),
email: z.string().refine((v) => isValidEmail(v)),
})

const RemovablePersonInformationSchema = z.object({
Expand Down Expand Up @@ -50,7 +59,7 @@ const TechInfoSchema = z.object({
})

export const NewMachineAnswersSchema = z.object({
approveExternalData: z.boolean(),
approveExternalData: z.boolean().refine((v) => v),
importerInformation: z.object({
importer: PersonInformationSchema,
}),
Expand Down Expand Up @@ -103,7 +112,12 @@ export const NewMachineAnswersSchema = z.object({
.refine(
({ isOwnerOtherThanImporter, owner }) => {
if (isOwnerOtherThanImporter === NO) return true
return owner && owner.phone && owner.phone.length > 0
return (
owner &&
owner.phone &&
owner.phone.length > 0 &&
isValidPhoneNumber(owner.phone)
)
},
{
path: ['owner', 'phone'],
Expand All @@ -112,7 +126,12 @@ export const NewMachineAnswersSchema = z.object({
.refine(
({ isOwnerOtherThanImporter, owner }) => {
if (isOwnerOtherThanImporter === NO) return true
return owner && owner.email && owner.email.length > 0
return (
owner &&
owner.email &&
owner.email.length > 0 &&
isValidEmail(owner.email)
)
},
{
path: ['owner', 'email'],
Expand Down Expand Up @@ -167,7 +186,12 @@ export const NewMachineAnswersSchema = z.object({
.refine(
({ hasOperator, operator }) => {
if (hasOperator === NO) return true
return operator && operator.phone && operator.phone.length > 0
return (
operator &&
operator.phone &&
operator.phone.length > 0 &&
isValidPhoneNumber(operator.phone)
)
},
{
path: ['operator', 'phone'],
Expand All @@ -176,7 +200,12 @@ export const NewMachineAnswersSchema = z.object({
.refine(
({ hasOperator, operator }) => {
if (hasOperator === NO) return true
return operator && operator.email && operator.email.length > 0
return (
operator &&
operator.email &&
operator.email.length > 0 &&
isValidEmail(operator.email)
)
},
{
path: ['operator', 'email'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ export const information = {
defaultMessage: 'Netfang',
description: `Owner email label`,
},
alertTitle: {
id: 'aosh.rnm.application:information.labels.otherOwner.alertTitle',
defaultMessage: 'Kennitala sú sama og hjá innflytjanda',
description: `Owner alert title`,
},
alertMessage: {
id: 'aosh.rnm.application:information.labels.otherOwner.alertMessage',
defaultMessage:
'Kennitalan sem þú skráðir fyrir eiganda er sú sama og hjá innflytjanda, vertu viss um að þú hafir skráð inn rétta kennitölu.',
description: `Owner alert message`,
},
}),
operator: defineMessages({
sectionTitle: {
Expand Down Expand Up @@ -160,6 +171,17 @@ export const information = {
defaultMessage: 'Netfang',
description: `Operator email label`,
},
alertTitle: {
id: 'aosh.rnm.application:information.labels.operator.alertTitle',
defaultMessage: 'Kennitala sú sama og hjá eiganda',
description: `Operator alert title`,
},
alertMessage: {
id: 'aosh.rnm.application:information.labels.operator.alertMessage',
defaultMessage:
'Kennitalan sem þú skráðir fyrir umráðarmann er sú sama og hjá eiganda, vertu viss um að þú hafir skráð inn rétta kennitölu.',
description: `Operator alert message`,
},
}),
radioButtons: defineMessages({
radioOptionYes: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getValueViaPath } from '@island.is/application/core'
import { FormValue, NO, YES, YesOrNo } from '@island.is/application/types'

export const doOwnerAndImporterHaveSameNationalId = (answers: FormValue) => {
const isOwnerOtherThanImporter = getValueViaPath(
answers,
'ownerInformation.isOwnerOtherThanImporter',
NO,
) as YesOrNo
const ownerNationalId = getValueViaPath(
answers,
'ownerInformation.owner.nationalId',
'',
) as string
const importerNationalId = getValueViaPath(
answers,
'importerInformation.importer.nationalId',
'',
) as string

return (
isOwnerOtherThanImporter === YES && ownerNationalId === importerNationalId
)
}
Loading

0 comments on commit a4e5484

Please sign in to comment.