Skip to content

Commit

Permalink
feat(income-plan): Update updateValueObj in incomeType (#15999)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
veronikasif and kodiakhq[bot] authored Sep 13, 2024
1 parent 8b22584 commit f257ea7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,18 @@ export const IncomePlanForm: Form = buildForm({
width: 'half',
isSearchable: true,
updateValueObj: {
valueModifier: (_) => '',
valueModifier: (application, activeField) => {
const options = getTypesOptions(
application.externalData,
activeField?.incomeCategory,
)

return (
options.find(
(option) => option.value === activeField?.incomeType,
)?.value ?? ''
)
},
watchValues: 'incomeCategory',
},
options: (application, activeField) => {
Expand All @@ -129,7 +140,7 @@ export const IncomePlanForm: Form = buildForm({
placeholder: incomePlanFormMessage.incomePlan.selectCurrency,
isSearchable: true,
updateValueObj: {
valueModifier: (activeField) => {
valueModifier: (_, activeField) => {
const defaultCurrency =
activeField?.incomeType === FOREIGN_BASIC_PENSION ||
activeField?.incomeType === FOREIGN_PENSION ||
Expand Down Expand Up @@ -186,7 +197,7 @@ export const IncomePlanForm: Form = buildForm({
displayInTable: false,
currency: true,
updateValueObj: {
valueModifier: (activeField) => {
valueModifier: (_, activeField) => {
const unevenAndEmploymentIncome =
activeField?.unevenIncomePerYear?.[0] !== YES ||
(activeField?.incomeCategory !== INCOME &&
Expand Down Expand Up @@ -227,7 +238,7 @@ export const IncomePlanForm: Form = buildForm({
displayInTable: false,
currency: true,
updateValueObj: {
valueModifier: (activeField) => {
valueModifier: (_, activeField) => {
const unevenAndEmploymentIncome =
activeField?.unevenIncomePerYear?.[0] !== YES ||
(activeField?.incomeCategory !== INCOME &&
Expand Down Expand Up @@ -270,7 +281,7 @@ export const IncomePlanForm: Form = buildForm({
return activeField?.income === RatioType.MONTHLY
},
updateValueObj: {
valueModifier: (activeField) => {
valueModifier: (_, activeField) => {
if (
activeField?.income === RatioType.MONTHLY &&
activeField?.incomeCategory === INCOME &&
Expand Down
5 changes: 4 additions & 1 deletion libs/application/types/src/lib/Fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export type TableRepeaterItem = {
activeField?: Record<string, string>,
) => boolean)
updateValueObj?: {
valueModifier: (activeField?: Record<string, string>) => unknown
valueModifier: (
application: Application,
activeField?: Record<string, string>,
) => unknown
watchValues:
| string
| string[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export const Item = ({
? !watchedValues.every((value) => value === undefined)
: true)
) {
const finalValue = updateValueObj.valueModifier(activeValues)
const finalValue = updateValueObj.valueModifier(
application,
activeValues,
)
setValue(id, finalValue)
}
}
Expand Down

0 comments on commit f257ea7

Please sign in to comment.