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

chore(financial-aid): refactor custom components out #15549

Merged
merged 34 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4078d6a
chore: refactor custom components out
jonnigs Jul 26, 2024
7b5027f
feat: add variables to text
jonnigs Jul 29, 2024
c75df9a
feat: add more variables to messages and other fixes
jonnigs Jul 29, 2024
6057865
feat: make bankAccount shared field
jonnigs Jul 30, 2024
c3362dc
chore: remove spaces
jonnigs Jul 30, 2024
90a06d2
Merge branch 'main' into feat/custom-components-financial-aid
jonnigs Jul 30, 2024
45bec07
Merge branch 'main' into feat/custom-components-financial-aid
jonnigs Jul 31, 2024
7c5b276
chore: make codgen run
jonnigs Sep 9, 2024
bb83ac1
fix: add back in and fix the add-files-while-processing functionality
jonnigs Sep 11, 2024
4e47867
fix: coderabbit comments
jonnigs Sep 11, 2024
10e5ddd
Merge branch 'main' into feat/custom-components-financial-aid
jonnigs Sep 12, 2024
a917b87
fix: pr comments
jonnigs Sep 12, 2024
38f091e
Merge branch 'main' into feat/custom-components-financial-aid
jonnigs Oct 1, 2024
f118765
Merge branch 'main' into feat/custom-components-financial-aid
jonnigs Oct 14, 2024
38229d7
fix: double definition
jonnigs Oct 14, 2024
c5950ab
chore: refactor out FAApplication and FAFieldBaseProps
jonnigs Oct 15, 2024
65852ff
chore: small refactor and lint
jonnigs Oct 15, 2024
8c482e4
chore: validating the schema
jonnigs Oct 16, 2024
ec65cb8
fix: use of getValueViaPath
jonnigs Oct 16, 2024
24769cc
chore: type getValueViaPath
jonnigs Oct 16, 2024
8488a51
chore: more getValueViaPath typing
jonnigs Oct 16, 2024
8f2154b
chore: more typimg
jonnigs Oct 16, 2024
e6d19b4
chore: typing and changing imports
jonnigs Oct 16, 2024
e33b762
fix: getValueViaPath path
jonnigs Oct 16, 2024
5bf7a5d
fix: typo
jonnigs Oct 16, 2024
2e2fd9e
chore: use the more common nameing
jonnigs Oct 16, 2024
8d5017f
Update libs/application/templates/financial-aid/src/forms/Application…
jonnigs Oct 16, 2024
4b30ccd
fix: duplicate id
jonnigs Oct 16, 2024
1f0f3f2
chore: remove unneccesary type cohersion
jonnigs Oct 16, 2024
1a26503
chore: remove hasSpouse2
jonnigs Oct 16, 2024
c208197
chore: remove comment, type casting
jonnigs Oct 16, 2024
a5cbe7b
fix: chore remove duplicate const definition
jonnigs Oct 16, 2024
3afe31f
chore: pr comment
jonnigs Oct 17, 2024
0ca4f15
Merge branch 'main' into feat/custom-components-financial-aid
kodiakhq[bot] Oct 17, 2024
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
Expand Up @@ -22,7 +22,7 @@ const AidAmountModal = ({
onVisibilityChange,
calculations,
}: Props) => {
const closeModal = (): void => {
const closeModal = () => {
onVisibilityChange(false)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo, useContext } from 'react'
import React, { useState, useMemo } from 'react'
import cn from 'classnames'
import format from 'date-fns/format'

Expand Down
45 changes: 45 additions & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
StaticTableField,
HiddenInputWithWatchedValueField,
HiddenInputField,
AccordionField,
BankAccountField,
SliderField,
} from '@island.is/application/types'

Expand Down Expand Up @@ -449,6 +451,49 @@ export const buildKeyValueField = (data: {
}
}

export const buildAccordionField = (
data: Omit<AccordionField, 'type' | 'component' | 'children'>,
): AccordionField => {
const {
accordionItems,
title,
titleVariant,
id,
marginTop,
marginBottom,
condition,
} = data
return {
children: undefined,
id,
title,
titleVariant,
marginTop,
marginBottom,
accordionItems,
condition,
type: FieldTypes.ACCORDION,
component: FieldComponents.ACCORDION,
}
}

export const buildBankAccountField = (
data: Omit<BankAccountField, 'type' | 'component' | 'children'>,
): BankAccountField => {
const { title, id, marginBottom, marginTop, titleVariant } = data

return {
children: undefined,
id,
title,
marginBottom,
marginTop,
titleVariant,
type: FieldTypes.BANK_ACCOUNT,
component: FieldComponents.BANK_ACCOUNT,
}
}

export const buildSubmitField = (data: {
id: string
title: FormText
Expand Down
15 changes: 15 additions & 0 deletions libs/application/core/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ export const coreDefaultFieldMessages = defineMessages({
defaultMessage: 'Veljið skjöl til að hlaða upp',
description: 'Default file upload button label',
},
defaultBankAccountBankNumber: {
id: 'application.system:core.default.bankAccount.bankNumber',
defaultMessage: 'Bankanúmer',
description: 'Bank account bank number',
},
defaultBankAccountLedger: {
id: 'application.system:core.default.bankAccount.ledger',
defaultMessage: 'Höfuðbók',
description: 'Bank account ledger',
},
defaultBankAccountAccountNumber: {
id: 'application.system:core.default.bankAccount.accountNumber',
defaultMessage: 'Reikningsnúmer',
description: 'Bank account account number',
},
defaultDownloadButtonTitle: {
id: 'application.system:core.default.pdfLinkButtonField.downloadButtonTitle',
defaultMessage: 'Hlaða niður skjali',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Injectable } from '@nestjs/common'

import {
FinancialAidAnswers,
ApproveOptions,
ChildrenSchoolInfo,
CurrentApplication,
FAApplication,
FinancialAidExternalData,
findFamilyStatus,
TaxData,
} from '@island.is/application/templates/financial-aid'
Expand All @@ -12,6 +14,7 @@ import { AuthMiddleware } from '@island.is/auth-nest-tools'
import {
ApplicationState,
FileType,
PersonalTaxReturn,
UserType,
} from '@island.is/financial-aid/shared/lib'
import {
Expand All @@ -24,15 +27,17 @@ import {
import { TemplateApiModuleActionProps } from '../../../types'
import { BaseTemplateApiService } from '../../base-template-api.service'
import {
Application,
ApplicationAnswerFile,
ApplicationTypes,
} from '@island.is/application/types'
import { FetchError } from '@island.is/clients/middlewares'
import { messages } from '@island.is/application/templates/financial-aid'
import { TemplateApiError } from '@island.is/nest/problem'
import { getValueViaPath } from '@island.is/application/core'

type Props = Omit<TemplateApiModuleActionProps, 'application'> & {
application: FAApplication
application: Application
}

@Injectable()
Expand Down Expand Up @@ -75,15 +80,26 @@ export class FinancialAidService extends BaseTemplateApiService {
auth,
}: Props): Promise<CurrentApplication> {
const { id, answers, externalData } = application
const answersSchema = answers as FinancialAidAnswers
const externalDataSchema =
externalData as unknown as FinancialAidExternalData
const currentApplicationId = getValueViaPath(
externalData,
'currentApplication.data.currentApplicationId',
) as string | undefined

if (externalData.currentApplication.data?.currentApplicationId) {
const childrenSchoolInfo = getValueViaPath(
answers,
'childrenSchoolInfo',
) as Array<ChildrenSchoolInfo>

if (currentApplicationId) {
return {
currentApplicationId:
externalData.currentApplication.data.currentApplicationId,
currentApplicationId,
}
}
const children = answers.childrenSchoolInfo
? answers.childrenSchoolInfo.map((child) => {
? childrenSchoolInfo.map((child) => {
return {
name: child.fullName,
nationalId: child.nationalId,
Expand All @@ -108,40 +124,38 @@ export class FinancialAidService extends BaseTemplateApiService {
})
}

const personalTaxReturn = getValueViaPath(
externalData,
'taxData.data.municipalitiesPersonalTaxReturn.personalTaxReturn',
) as PersonalTaxReturn | undefined

const spouseTaxReturn = getValueViaPath(
externalData,
'taxDataSpouse.data.municipalitiesPersonalTaxReturn.personalTaxReturn',
) as PersonalTaxReturn | undefined

const spouseTaxFiles = () => {
if (
externalData?.taxDataSpouse?.data?.municipalitiesPersonalTaxReturn
?.personalTaxReturn == null
) {
if (spouseTaxReturn == null) {
return []
}
return [
externalData?.taxDataSpouse?.data?.municipalitiesPersonalTaxReturn
?.personalTaxReturn,
]
return [spouseTaxReturn]
}

const applicantTaxFiles = () => {
if (
externalData?.taxData?.data?.municipalitiesPersonalTaxReturn
?.personalTaxReturn == null
) {
if (personalTaxReturn == null) {
return []
}
return [
externalData?.taxData?.data?.municipalitiesPersonalTaxReturn
?.personalTaxReturn,
]
return [personalTaxReturn]
}

const directTaxPayments = () => {
if (externalData?.taxDataSpouse?.data) {
externalData?.taxData?.data?.municipalitiesDirectTaxPayments?.directTaxPayments.concat(
externalData?.taxDataSpouse?.data.municipalitiesDirectTaxPayments
?.directTaxPayments,
if (externalDataSchema?.taxDataSpouse?.data) {
externalDataSchema?.taxData?.data?.municipalitiesDirectTaxPayments?.directTaxPayments.concat(
externalDataSchema?.taxDataSpouse?.data
.municipalitiesDirectTaxPayments?.directTaxPayments,
)
}
return externalData?.taxData?.data?.municipalitiesDirectTaxPayments?.directTaxPayments.map(
return externalDataSchema?.taxData?.data?.municipalitiesDirectTaxPayments?.directTaxPayments.map(
(d) => {
d.userType = application.assignees.includes(auth.nationalId)
? UserType.SPOUSE
Expand All @@ -151,59 +165,77 @@ export class FinancialAidService extends BaseTemplateApiService {
)
}

const files = formatFiles(answers.taxReturnFiles, FileType.TAXRETURN)
.concat(formatFiles(answers.incomeFiles, FileType.INCOME))
.concat(formatFiles(answers.spouseIncomeFiles, FileType.SPOUSEFILES))
.concat(formatFiles(answers.spouseTaxReturnFiles, FileType.SPOUSEFILES))
const files = formatFiles(
answersSchema?.taxReturnFiles ?? [],
FileType.TAXRETURN,
)
.concat(formatFiles(answersSchema.incomeFiles ?? [], FileType.INCOME))
.concat(
formatFiles(
answersSchema.spouseIncomeFiles ?? [],
FileType.SPOUSEFILES,
),
)
.concat(
formatFiles(
answersSchema.spouseTaxReturnFiles ?? [],
FileType.SPOUSEFILES,
),
)
.concat(formatFiles(spouseTaxFiles(), FileType.SPOUSEFILES))
.concat(formatFiles(applicantTaxFiles(), FileType.TAXRETURN))
.concat(formatFiles(answers.childrenFiles, FileType.CHILDRENFILES))
.concat(
formatFiles(answersSchema.childrenFiles ?? [], FileType.CHILDRENFILES),
)

const newApplication = {
name: externalData.nationalRegistry.data.fullName,
nationalId: externalData.nationalRegistry.data.nationalId,
phoneNumber: answers.contactInfo.phone,
email: answers.contactInfo.email,
homeCircumstances: answers.homeCircumstances.type,
homeCircumstancesCustom: answers.homeCircumstances.custom,
student: Boolean(answers.student.isStudent === ApproveOptions.Yes),
studentCustom: answers.student.custom,
hasIncome: Boolean(answers.income === ApproveOptions.Yes),
name: externalDataSchema.nationalRegistry.data.fullName,
nationalId: externalDataSchema.nationalRegistry.data.nationalId,
phoneNumber: answersSchema.contactInfo.phone,
email: answersSchema.contactInfo.email,
homeCircumstances: answersSchema.homeCircumstances.type,
homeCircumstancesCustom: answersSchema.homeCircumstances.custom,
student: Boolean(answersSchema.student.isStudent === ApproveOptions.Yes),
studentCustom: answersSchema.student.custom,
hasIncome: Boolean(answersSchema.income.type === ApproveOptions.Yes),
usePersonalTaxCredit: Boolean(
answers.personalTaxCredit === ApproveOptions.Yes,
answersSchema.personalTaxCredit.type === ApproveOptions.Yes,
),
bankNumber: answers.bankInfo.bankNumber,
ledger: answers.bankInfo.ledger,
accountNumber: answers.bankInfo.accountNumber,
employment: answers.employment.type,
employmentCustom: answers.employment.custom,
formComment: answers.formComment,
bankNumber: answersSchema.bankInfo.accountNumber,
ledger: answersSchema.bankInfo.accountNumber,
accountNumber: answersSchema.bankInfo.accountNumber,
employment: answersSchema.employment.type,
employmentCustom: answersSchema.employment.custom,
formComment: answersSchema.formComment,
state: ApplicationState.NEW,
files: files,
children: children,
childrenComment: answers.childrenComment,
children,
childrenComment: answersSchema.childrenComment,
spouseNationalId:
externalData.nationalRegistrySpouse.data?.nationalId ||
answers.relationshipStatus?.spouseNationalId,
externalDataSchema.nationalRegistrySpouse.data?.nationalId ||
answersSchema.relationshipStatus?.spouseNationalId,
spouseEmail:
answers.spouseContactInfo?.email ||
answers.spouse?.email ||
answers.relationshipStatus?.spouseEmail,
spousePhoneNumber: answers.spouseContactInfo?.phone,
answersSchema.spouseContactInfo?.email ||
answersSchema.spouse?.email ||
answersSchema.relationshipStatus?.spouseEmail,
spousePhoneNumber: answersSchema.spouseContactInfo?.phone,
spouseName:
externalData.nationalRegistrySpouse.data?.name || answers.spouseName,
spouseFormComment: answers.spouseFormComment,
familyStatus: findFamilyStatus(answers, externalData),
streetName: externalData.nationalRegistry.data.address?.streetAddress,
postalCode: externalData.nationalRegistry.data.address?.postalCode,
city: externalData.nationalRegistry.data.address?.locality,
externalDataSchema.nationalRegistrySpouse.data?.name ||
answersSchema.spouseName,
spouseFormComment: answersSchema.spouseFormComment,
familyStatus: findFamilyStatus(answersSchema, externalData),
streetName:
externalDataSchema.nationalRegistry.data.address?.streetAddress,
postalCode: externalDataSchema.nationalRegistry.data.address?.postalCode,
city: externalDataSchema.nationalRegistry.data.address?.locality,
municipalityCode:
externalData.nationalRegistry.data.address?.municipalityCode,
externalDataSchema.nationalRegistry.data.address?.municipalityCode,
directTaxPayments: directTaxPayments(),
hasFetchedDirectTaxPayment:
externalData?.taxData?.data?.municipalitiesDirectTaxPayments?.success,
externalDataSchema?.taxData?.data?.municipalitiesDirectTaxPayments
?.success,
spouseHasFetchedDirectTaxPayment:
externalData?.taxDataSpouse?.data?.municipalitiesDirectTaxPayments
externalDataSchema?.taxDataSpouse?.data?.municipalitiesDirectTaxPayments
?.success,
applicationSystemId: id,
}
Expand Down Expand Up @@ -243,8 +275,10 @@ export class FinancialAidService extends BaseTemplateApiService {
auth,
application,
}: Props): Promise<MunicipalityModel | null> {
const municiplaityCode =
application.externalData.nationalRegistry.data.address?.municipalityCode
const municiplaityCode = getValueViaPath(
application.externalData,
'nationalRegistry.data.address.municipalityCode',
) as string
if (municiplaityCode == null) {
return null
}
Expand Down Expand Up @@ -287,23 +321,26 @@ export class FinancialAidService extends BaseTemplateApiService {
application,
}: Props): Promise<{ success: boolean }> {
const { answers, externalData } = application
const answersSchema = answers as unknown as FinancialAidAnswers
const externalDataSchema =
externalData as unknown as FinancialAidExternalData
try {
return await this.applicationApiWithAuth(
auth,
).applicationControllerSendSpouseEmail({
spouseEmailDto: {
name: externalData.nationalRegistry.data.fullName,
email: answers.contactInfo.email,
name: externalDataSchema.nationalRegistry.data.fullName,
email: answersSchema.contactInfo.email,
spouseName:
externalData.nationalRegistrySpouse.data?.name ||
answers.spouseName ||
externalDataSchema.nationalRegistrySpouse.data?.name ||
answersSchema.spouseName ||
'',
spouseEmail:
answers.spouse?.email ||
answers.relationshipStatus.spouseEmail ||
answersSchema.spouse?.email ||
answersSchema.relationshipStatus.spouseEmail ||
'',
municipalityCode:
externalData.municipality.data?.municipalityId || '',
externalDataSchema.municipality.data?.municipalityId || '',
created: application.created,
applicationSystemId: application.id,
},
Expand Down
Loading
Loading