Skip to content

Commit

Permalink
start on advanced driving-license
Browse files Browse the repository at this point in the history
  • Loading branch information
stjanilofts committed Oct 30, 2024
1 parent 96b60a1 commit 5c71287
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Alert: FC<React.PropsWithChildren<Props>> = ({
}) => {
const { formatMessage } = useLocale()
const { title, type, message, heading } = field.props as Field
console.log('message', formatText(message, application, formatMessage))
// console.log('message', formatText(message, application, formatMessage))
return (
<Box justifyContent={'spaceBetween'}>
{heading && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import React, { FC, useEffect, useState } from 'react'

import { Box, Checkbox, Text } from '@island.is/island-ui/core'
import { FieldBaseProps } from '@island.is/application/types'
import { useFormContext } from 'react-hook-form'
import {
organizedAdvancedLicenseMap,
AdvancedLicense as AdvancedLicenseEnum,
} from '../../lib/constants'
import { useLocale } from '@island.is/localization'
import { m } from '../../lib/messages'
import { joinWithAnd } from '../../lib/utils'

const AdvancedLicense: FC<React.PropsWithChildren<FieldBaseProps>> = ({
application,
}) => {
console.log('application', application)

const { formatMessage } = useLocale()
const { setValue, watch } = useFormContext()

const advancedLicenseValue = watch('advancedLicense') ?? []

const [selectedLicenses, setSelectedLicenses] =
useState<Array<keyof typeof AdvancedLicenseEnum>>(advancedLicenseValue)

useEffect(() => {
if (selectedLicenses.length > 0) {
setValue('advancedLicense', selectedLicenses)
}
}, [selectedLicenses, setValue])

return (
<Box>
{Object.entries(organizedAdvancedLicenseMap).map(([, options], index) => {
const s1arr = options.map((option) => {
return option.code
})

const s1 = joinWithAnd(s1arr)

const s2 = options.find((x) => x.minAge)?.minAge

const requiredAgeText =
s1 &&
s2 &&
formatMessage(m[`applicationForAdvancedAgeRequired`])
?.replace('%1', s1)
?.replace('%2', String(s2))

return (
<Box marginTop={index === 0 ? 2 : 5} marginBottom={5}>
{requiredAgeText && (
<Box marginBottom={2}>
<Text variant="medium" as="div">
{requiredAgeText}
</Text>
</Box>
)}
{options.map((option, index) => {
const name = `field-${option.code}`

return (
<Box
key={index}
marginBottom={2}
paddingX={3}
paddingTop={2}
paddingBottom={3}
background="blue100"
borderRadius="large"
border="standard"
>
<Text as="div" marginBottom={2}>
{formatMessage(
m[`applicationForAdvancedLicenseTitle${option.code}`],
)}
</Text>
<Checkbox
label={formatMessage(
m[`applicationForAdvancedLicenseLabel${option.code}`],
)}
id={name}
name={name}
backgroundColor="blue"
labelVariant="medium"
checked={advancedLicenseValue.includes(option.code)}
onChange={(e) => {
const checked = e.target.checked
console.log('checked?', checked)

setSelectedLicenses((prev) => {
return prev.includes(option.code)
? prev
.filter((item) => item !== option.code)
.filter(
(item) => item !== option.professional?.code,
)
: [...prev, option.code]
})
}}
/>
{option?.professional && (
<Box
key={index}
marginTop={2}
paddingX={3}
paddingY={2}
background="blue100"
borderRadius="large"
border="standard"
>
<Checkbox
disabled={!selectedLicenses.includes(option?.code)}
label={formatMessage(
m[
`applicationForAdvancedLicenseLabel${option.professional.code}`
],
)}
id="hey44"
backgroundColor="blue"
labelVariant="small"
checked={advancedLicenseValue.includes(
option?.professional?.code,
)}
onChange={(e) => {
setSelectedLicenses((prev) => {
if (e.target.checked && option.professional?.code) {
return [...prev, option.professional.code]
}

return prev.filter(
(item) => item !== option.professional?.code,
)
})
}}
/>
</Box>
)}
</Box>
)
})}
</Box>
)
})}
</Box>
)
}

export { AdvancedLicense }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AdvancedLicense } from './AdvancedLicense'
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export { EligibilitySummary } from './EligibilitySummary'
export { SubmitAndDecline } from './SubmitAndDecline'
export { LinkExistingApplication } from './LinkExistingApplication'
export { PaymentPending } from './PaymentPending'
export { AdvancedLicense } from './AdvancedLicense'
export { QualityPhoto } from './QualityPhoto'
export { default as HealthRemarks } from './HealthRemarks'
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { sectionApplicationFor } from './sectionApplicationFor'
import { sectionRequirements } from './sectionRequirements'
import { sectionExistingApplication } from './sectionExistingApplication'
import { sectionDigitalLicenseInfo } from './sectionDigitalLicenseInfo'
import { sectionAdvancedLicenseSelection } from './sectionAdvancedLicenseSelection'

export const getForm = ({
allowFakeData = false,
allowPickLicense = false,
allowBELicense = false,
allow65Renewal = false,
allowAdvanced = false,
}): Form =>
buildForm({
id: 'DrivingLicenseApplicationPrerequisitesForm',
Expand All @@ -31,8 +33,15 @@ export const getForm = ({
sectionExternalData,
sectionExistingApplication,
...(allowPickLicense
? [sectionApplicationFor(allowBELicense, allow65Renewal)]
? [
sectionApplicationFor(
allowBELicense,
allow65Renewal,
allowAdvanced,
),
]
: []),
sectionAdvancedLicenseSelection,
sectionDigitalLicenseInfo,
sectionRequirements,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
buildCustomField,
buildKeyValueField,
buildMultiField,
buildRadioField,
buildSubSection,
getValueViaPath,
} from '@island.is/application/core'
import { m } from '../../lib/messages'
import { LicenseTypes } from '../../lib/constants'

export const sectionAdvancedLicenseSelection = buildSubSection({
id: 'sectionAdvancedLicenseSelection',
title: m.applicationForAdvancedLicenseTitle,
condition: (answers) => {
const applicationFor = getValueViaPath<LicenseTypes>(
answers,
'applicationFor',
)

return applicationFor === LicenseTypes.B_ADVANCED
},
children: [
buildMultiField({
id: 'advancedLicenseSelectionFields',
title: m.applicationForAdvancedLicenseTitle,
description: m.applicationForAdvancedLicenseDescription,
children: [
buildCustomField({
id: 'advancedLicense',
title: 'Advanced License',
component: 'AdvancedLicense',
}),
// buildRadioField({
// id: 'advancedLicense',
// title: '',
// backgroundColor: 'blue',
// largeButtons: true,
// options: (app) => {
// console.log(app)
// let options = []

// options = Object.values(AdvancedLicenses).map((license) => {
// return {
// label: m[`applicationForAdvancedLicenseApplyFor${license}`],
// value: AdvancedLicenses[license],
// disabled: false,
// }
// })

// return options
// },
// }),
],
}),
],
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { m } from '../../lib/messages'
import { DrivingLicense } from '../../lib/types'
import {
B_ADVANCED,
B_FULL,
B_FULL_RENEWAL_65,
B_TEMP,
Expand All @@ -17,6 +18,7 @@ import {
export const sectionApplicationFor = (
allowBELicense = false,
allow65Renewal = false,
allowAdvanced = false,
) =>
buildSubSection({
id: 'applicationFor',
Expand Down Expand Up @@ -55,6 +57,7 @@ export const sectionApplicationFor = (
)

if (fakeData?.useFakeData === 'yes') {
// console.log('using fake data', fakeData)
currentLicense = fakeData.currentLicense ?? null
categories =
fakeData.currentLicense === 'temp'
Expand Down Expand Up @@ -112,6 +115,17 @@ export const sectionApplicationFor = (
})
}

if (allowAdvanced) {
options = options.concat({
label: m.applicationForAdvancedLicenseTitle,
subLabel: m.applicationForAdvancedLicenseDescription,
value: B_ADVANCED,
disabled: !categories?.some(
(c) => c.nr.toUpperCase() === 'B' && c.validToCode !== 8,
),
})
}

return options
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export const sectionExternalData = buildSubSection({
provider: JurisdictionApi,
title: '',
}),
buildDataProviderItem({
provider: SyslumadurPaymentCatalogApi,
title: '',
}),
// buildDataProviderItem({
// provider: SyslumadurPaymentCatalogApi,
// title: '',
// }),
buildDataProviderItem({
provider: MockableSyslumadurPaymentCatalogApi,
title: '',
Expand Down
Loading

0 comments on commit 5c71287

Please sign in to comment.