Skip to content

Commit

Permalink
code rabbit comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stjanilofts committed Oct 30, 2024
1 parent 35fc794 commit 25e9e21
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ const AdvancedLicense: FC<React.PropsWithChildren<FieldBaseProps>> = ({
const requiredAgeText =
s1 &&
s2 &&
formatMessage(m[`applicationForAdvancedAgeRequired`])
?.replace('%1', s1)
?.replace('%2', String(s2))
formatMessage(m[`applicationForAdvancedAgeRequired`], {
licenses: s1,
age: String(s2),
})

return (
<Box marginTop={index === 0 ? 2 : 5} marginBottom={5}>
<Box
key={`license-group-${index}`}
marginTop={index === 0 ? 2 : 5}
marginBottom={5}
>
{requiredAgeText && (
<Box marginBottom={2}>
<Text variant="medium" as="div">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getForm = ({
),
]
: []),
sectionAdvancedLicenseSelection,
...(allowAdvanced ? [sectionAdvancedLicenseSelection] : []),
sectionDigitalLicenseInfo,
sectionRequirements,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const sectionAdvancedLicenseSelection = buildSubSection({
'applicationFor',
)

return applicationFor === LicenseTypes.B_ADVANCED
return applicationFor != null && applicationFor === LicenseTypes.B_ADVANCED
},
children: [
buildMultiField({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const dataSchema = z.object({
certificate: z.array(z.enum([YES, NO])).nonempty(),
applicationFor: z.enum([B_FULL, B_TEMP, BE, B_FULL_RENEWAL_65, B_ADVANCED]),
advancedLicense: z
.array(z.enum(Object.keys(AdvancedLicense) as [string, ...string[]]))
.array(z.enum(Object.values(AdvancedLicense) as [string, ...string[]]))
.nonempty(),
email: z.string().email(),
phone: z.string().refine((v) => isValidPhoneNumber(v)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,8 @@ export const m = defineMessages({
},
applicationForAdvancedAgeRequired: {
id: 'dl.application:applicationForAdvancedAgeFor',
defaultMessage: 'Réttindaaldur fyrir %1 er %2 ára',
description: 'Required age for %1 is %2 years',
defaultMessage: 'Réttindaaldur fyrir {licenses} er {age} ára',
description: 'Required age for {licenses} is {age} years',
},
applicationForAdvancedLicenseTitleC1: {
id: 'dl.application:applicationForAdvancedLicenseTitleC1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ export const hasHealthRemarks = (externalData: ExternalData) => {
}

export const joinWithAnd = (arr: string[], andString = 'og'): string => {
if (arr.length === 0) return ''
if (arr.length === 1) return arr[0]
if (arr.length === 2) return arr.join(` ${andString} `)
const validStrings = arr.filter(
(str) => typeof str === 'string' && str.trim().length > 0,
)

if (validStrings.length === 0) return ''
if (validStrings.length === 1) return validStrings[0]
if (validStrings.length === 2) return validStrings.join(` ${andString} `)

return `${arr.slice(0, -1).join(', ')}, ${andString} ${arr[arr.length - 1]}`
return `${validStrings.slice(0, -1).join(', ')}, ${andString} ${
validStrings[validStrings.length - 1]
}`
}

0 comments on commit 25e9e21

Please sign in to comment.