Skip to content

Commit

Permalink
fix: some variables were zero because of incomplete ahjo process; ref…
Browse files Browse the repository at this point in the history
…actor logic
  • Loading branch information
sirtawast committed Nov 22, 2024
1 parent 4b03f4e commit b6c0c2a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ const InstalmentAccordionSections: React.FC<Props> = ({ data }) => {

return (
<>
<$Section className="">
<$Section>
<$CalculatorTableRow>
<$ViewField>{t(`${translationsBase}.firstInstalment`)}</$ViewField>
{data.pendingInstalment &&
formatFloatToCurrency(amounts.firstInstalment, 'EUR', 'fi-FI', 0)}
{!data.pendingInstalment &&
formatFloatToCurrency(
data.calculatedBenefitAmount,
'EUR',
'fi-FI',
0
)}
<$RowWrap>
{renderPaymentTagPerStatus(t, data.talpaStatus)}
<div>
{formatFloatToCurrency(
amounts.firstInstalment,
'EUR',
'fi-FI',
0
)}
</div>
</$RowWrap>
</$CalculatorTableRow>
</$Section>

Expand All @@ -79,25 +81,23 @@ const InstalmentAccordionSections: React.FC<Props> = ({ data }) => {
data.pendingInstalment?.status as INSTALMENT_STATUSES
)}

{(isSecondInstalmentReduced || !areInstalmentsPaid) && (
{isSecondInstalmentReduced && (
<>
<div
style={{
textDecoration:
areInstalmentsPaid && isSecondInstalmentReduced
? 'line-through'
: 'none',
textDecoration: areInstalmentsPaid
? 'line-through'
: 'none',
}}
>
{isSecondInstalmentReduced &&
formatFloatToCurrency(
data.pendingInstalment?.amount,
'EUR',
'fi-FI',
0
)}
{formatFloatToCurrency(
amounts.secondInstalmentMax,
'EUR',
'fi-FI',
0
)}
</div>
{isSecondInstalmentReduced && <IconArrowRight />}
<IconArrowRight />
</>
)}

Expand Down Expand Up @@ -162,7 +162,7 @@ const InstalmentAccordionSections: React.FC<Props> = ({ data }) => {
{amounts.secondInstalment - amounts.alterations < 0 &&
areInstalmentsPaid && (
<>
<$Section className="">
<$Section>
<$CalculatorTableRow>
<$ViewField isBold>
{data.pendingInstalment?.status ===
Expand All @@ -173,7 +173,7 @@ const InstalmentAccordionSections: React.FC<Props> = ({ data }) => {
{formatFloatToCurrency(amounts.total, 'EUR', 'fi-FI', 0)}
</$CalculatorTableRow>
</$Section>
<$Section className="">
<$Section>
<$CalculatorTableRow>
<$ViewField isBold>
<$Wrapper>
Expand All @@ -197,7 +197,7 @@ const InstalmentAccordionSections: React.FC<Props> = ({ data }) => {
</>
)}

<$Section className="">
<$Section>
<$CalculatorTableRow>
<$ViewField isBold>
{t(`${translationsBase}.totalAfterRecoveries`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ type Props = {
const useInstalmentAccordionSections = (data: Application): Props => {
const amounts = {
firstInstalment: data.pendingInstalment
? data.calculatedBenefitAmount - data.pendingInstalment.amount
: data.calculatedBenefitAmount,
? Math.max(
0,
parseInt(data.calculation.calculatedBenefitAmount, 10) -
data.pendingInstalment.amount
)
: parseInt(data.calculation.calculatedBenefitAmount, 10),
secondInstalment: data.pendingInstalment?.amountAfterRecoveries || 0,
secondInstalmentMax: data.pendingInstalment?.amount || 0,
total: 0,
Expand All @@ -32,9 +36,11 @@ const useInstalmentAccordionSections = (data: Application): Props => {
?.filter((obj) => obj.state === ALTERATION_STATE.HANDLED)
.reduce((prev, cur) => prev + parseInt(cur.recoveryAmount, 10), 0) || 0,
};

amounts.total = amounts.firstInstalment + amounts.secondInstalment;
amounts.totalAfterRecoveries =
data.calculatedBenefitAmount - amounts.alterations;
parseInt(data.calculation?.calculatedBenefitAmount, 10) -
amounts.alterations;

const isSecondInstalmentReduced =
formatFloatToCurrency(amounts.secondInstalment, null, 'fi-FI', 0) !==
Expand Down

0 comments on commit b6c0c2a

Please sign in to comment.