Skip to content

Commit

Permalink
coderabbit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stjanilofts committed Oct 7, 2024
1 parent 2a0ccd6 commit ea0a7a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ export const useEligibility = (
)
}

const hasExtendedDrivingLicense = (
currentLicense: DrivingLicense | undefined,
drivingLicenseIssued: string | undefined,
): boolean => {
if (!drivingLicenseIssued) return false

const relevantCategories = currentLicense?.categories?.filter((x) =>
codesExtendedLicenseCategories.includes(x.nr),
)

if (!relevantCategories?.length) return false

// Check if any category was issued on a different date than the 'B' license
// (indicating an extended license)
return relevantCategories.some((x) => x.issued !== drivingLicenseIssued)
}

if (usingFakeData) {
return {
loading: false,
Expand All @@ -119,10 +136,7 @@ export const useEligibility = (
}

const eligibility: ApplicationEligibilityRequirement[] =
data.drivingLicenseApplicationEligibility === undefined
? []
: (data.drivingLicenseApplicationEligibility as ApplicationEligibility)
.requirements
data.drivingLicenseApplicationEligibility?.requirements ?? []

//TODO: Remove when RLS/SGS supports health certificate in BE license
if (application.answers.applicationFor === BE) {
Expand Down Expand Up @@ -155,25 +169,12 @@ export const useEligibility = (
const licenseB = currentLicense?.categories?.find(
(license) => license.nr === 'B',
)

const drivingLicenseIssued = licenseB?.issued

let hasExtendedDrivingLicense = false

if (drivingLicenseIssued) {
const relevantCategories = currentLicense?.categories?.filter((x) =>
codesExtendedLicenseCategories.includes(x.nr),
)

if (relevantCategories?.length) {
// check if the user has any categories that indicate an extended driving license.
// if any of the issued dates are exactly the same, they were most likely created
// in 1993 (or around that time) and are not considered extended drivers licenses.
hasExtendedDrivingLicense = !relevantCategories.some(
(x) => x.issued === drivingLicenseIssued,
)
}
}
const hasExtendedLicense = hasExtendedDrivingLicense(
currentLicense,
drivingLicenseIssued,
)

const hasAnyInvalidRemarks =
currentLicense?.remarks?.some((remark) =>
Expand All @@ -186,16 +187,16 @@ export const useEligibility = (
key: RequirementKey.HasNoPhoto,
requirementMet: hasQualityPhoto,
},
...(hasExtendedLicense
? [
{
key: RequirementKey.NoExtendedDrivingLicense,
requirementMet: false,
},
]
: []),
]

if (hasExtendedDrivingLicense) {
requirements.push({
key: RequirementKey.NoExtendedDrivingLicense,
requirementMet: false,
})
}

//Add type annotations to the returned object
return {
loading: loading,
eligibility: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ export const requirementsMessages = defineMessages({
description: 'requirement unmet 65 plus renewal',
},
noExtendedDrivingLicenseDescription: {
id: 'dl.application:requirementunmet.noExtendedDrivingLicenseDescription',
id: 'dl.application:requirementunmet.noExtendedDrivingLicenseDescription#markdown',
defaultMessage: 'Ekki hægt að sækja um endurnýjun á 65+ ökuskírteini.',
description: 'requirement unmet 65 plus renewal',
},
Expand Down

0 comments on commit ea0a7a8

Please sign in to comment.