From 1a3e5b2000ffaa7c3171852927549cd207180df8 Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Tue, 16 Apr 2024 13:00:24 -0400 Subject: [PATCH 01/12] Partial check in next steps --- components/Forms/Button.tsx | 3 + components/ResultsPage/BenefitCard.tsx | 35 ++- components/ResultsPage/BenefitCards.tsx | 13 +- components/ResultsPage/NextSteps.tsx | 199 ++++++--------- i18n/api/en.ts | 20 +- i18n/api/fr.ts | 7 +- i18n/api/index.ts | 2 + utils/api/benefits/oasBenefit.ts | 316 ++++++++++++------------ utils/api/fieldsHandler.ts | 41 +-- 9 files changed, 314 insertions(+), 322 deletions(-) diff --git a/components/Forms/Button.tsx b/components/Forms/Button.tsx index e1e88bd2c..fa4369ea0 100644 --- a/components/Forms/Button.tsx +++ b/components/Forms/Button.tsx @@ -6,6 +6,7 @@ interface ButtonProps { style: 'primary' | 'secondary' | 'supertask' | 'danger' | 'link' custom?: string href?: string + imgHref?: string text: string type?: ButtonType locale?: string @@ -31,6 +32,7 @@ export const Button: React.FC = ({ style, custom = '', href, + imgHref, text, type = 'button', locale, @@ -59,6 +61,7 @@ export const Button: React.FC = ({ aria-label={ariaLabel} {...attributes} > + {imgHref && alt} {text} ) diff --git a/components/ResultsPage/BenefitCard.tsx b/components/ResultsPage/BenefitCard.tsx index 35530981a..499cc1b63 100644 --- a/components/ResultsPage/BenefitCard.tsx +++ b/components/ResultsPage/BenefitCard.tsx @@ -1,3 +1,4 @@ +import { Button } from '../Forms/Button' import Image from 'next/image' import React from 'react' import { NextStepText } from '../../utils/api/definitions/types' @@ -54,11 +55,18 @@ export const BenefitCard: React.VFC<{ className="my-6 py-6 px-8 border border-[#6F6F6F] rounded" data-cy={benefitKey} > -
+ {/* + + TO-DO: + - flex-wrap + + + */} +

{benefitName}

@@ -85,13 +93,13 @@ export const BenefitCard: React.VFC<{ {nextStepText.nextStepTitle && (
-

{nextStepText.nextStepTitle} -

+

*/}

{links && links.map(({ text, url, icon, alt, action }, index) => ( -

-
+
+ {/*
{alt} -
+
*/}
diff --git a/components/ResultsPage/BenefitCards.tsx b/components/ResultsPage/BenefitCards.tsx index b6e45d429..0f5cbd860 100644 --- a/components/ResultsPage/BenefitCards.tsx +++ b/components/ResultsPage/BenefitCards.tsx @@ -120,7 +120,14 @@ export const BenefitCards: React.VFC<{ tsln ) } else if (benefitKey === BenefitKey.alw) { - getAlwNextSteps(result, inputAge, nextStepText, apiTsln, tsln) + getAlwNextSteps( + result, + partnerResults, + inputAge, + nextStepText, + apiTsln, + tsln + ) } else if (benefitKey === BenefitKey.alws) { getAlwsNextSteps(result, inputAge, nextStepText, apiTsln, tsln) } @@ -199,8 +206,8 @@ export const BenefitCards: React.VFC<{ __html: result.cardDetail.mainText, }} /> -
{OASdeferralTable}
-
{oasApply(result.benefitKey, result)}
+ {/*
{OASdeferralTable}
*/} + {/*
{oasApply(result.benefitKey, result)}
*/}
) diff --git a/components/ResultsPage/NextSteps.tsx b/components/ResultsPage/NextSteps.tsx index 1012ede41..df35fed05 100644 --- a/components/ResultsPage/NextSteps.tsx +++ b/components/ResultsPage/NextSteps.tsx @@ -14,102 +14,37 @@ export function getOasNextSteps( ) { if (result.eligibility.result === ResultKey.ELIGIBLE) { nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - - if (result.entitlement.clawback > 0) { - if (!receivingOAS && inputAge > 64) { - nextStepText.nextStepContent += `${apiTsln.detail.oas.youShouldHaveReceivedLetter} ${apiTsln.detail.oas.applyOnline}` - } - - if ( - result.eligibility.reason === ResultReason.AGE_70_AND_OVER && - !receivingOAS - ) { - nextStepText.nextStepContent += `

${apiTsln.detail.oas.over70}

` - } - - //code for future --start-- - if (inputAge < 64) { - nextStepText.nextStepContent += apiTsln.detail.oas.youWillReceiveLetter - } else if (inputAge === 64) { - nextStepText.nextStepContent += `${apiTsln.detail.oas.youShouldHaveReceivedLetter} ${apiTsln.detail.oas.ifYouDidnt}` - } else if ( - (result.eligibility.reason === ResultReason.AGE_65_TO_69 || - result.eligibility.reason === ResultReason.AGE_70_AND_OVER) && - result.entitlement.result > 0 && - receivingOAS - ) { - //TODO duplicating the code here, will refactor later TODO + if (receivingOAS) { + if (result.entitlement.result === 0) { + nextStepText.nextStepContent += `

${apiTsln.detail.thisEstimateWhenZero}

` + } else if (result.entitlement.result > 0) { nextStepText.nextStepContent += `

${apiTsln.detail.thisEstimate}

` - } else { - !receivingOAS - ? (nextStepText.nextStepContent += `

${apiTsln.detail.oas.serviceCanadaReviewYourPayment}

`) - : '' - } - //code for future --end-- - } else if ( - (result.eligibility.reason === ResultReason.AGE_65_TO_69 || - result.eligibility.reason === ResultReason.AGE_70_AND_OVER) && - result.entitlement.result > 0 && - receivingOAS - ) { - nextStepText.nextStepContent += `

${apiTsln.detail.thisEstimate}

` - } else if ( - (result.eligibility.reason === ResultReason.AGE_65_TO_69 || - result.eligibility.reason === ResultReason.AGE_70_AND_OVER || - result.eligibility.reason === ResultReason.INCOME) && - result.entitlement.result === 0 && - receivingOAS - ) { - nextStepText.nextStepContent += `

${apiTsln.detail.thisEstimateWhenZero}

` - } else if (result.eligibility.reason === ResultReason.AGE_65_TO_69) { - //code for future --start-- - if (inputAge < 64) { - nextStepText.nextStepContent += apiTsln.detail.oas.youWillReceiveLetter - } else if (inputAge === 64) { - nextStepText.nextStepContent += `${apiTsln.detail.oas.youShouldHaveReceivedLetter} ${apiTsln.detail.oas.ifYouDidnt}` - } else { - // default when 65-69 - !receivingOAS - ? (nextStepText.nextStepContent += `${apiTsln.detail.oas.youShouldHaveReceivedLetter} ${apiTsln.detail.oas.applyOnline}`) - : '' } - //code for future --end-- - } else if ( - result.eligibility.reason === ResultReason.AGE_70_AND_OVER && - receivingOAS - ) { - nextStepText.nextStepContent += `

${apiTsln.detail.thisEstimate}

` - } else if ( - result.eligibility.reason === ResultReason.AGE_70_AND_OVER && - !receivingOAS - ) { - nextStepText.nextStepContent += apiTsln.detail.oas.over70 - } else if (result.entitlement.clawback === 0) { - //code for future --start-- - if (inputAge < 64) { - nextStepText.nextStepContent += apiTsln.detail.oas.youWillReceiveLetter - } else if (inputAge === 64) { - nextStepText.nextStepContent += `${apiTsln.detail.oas.youShouldHaveReceivedLetter} ${apiTsln.detail.oas.ifYouDidnt}` + } else { + if (inputAge > 69) { + nextStepText.nextStepContent += `

${apiTsln.detail.oas.over70}

` + nextStepText.nextStepContent += `

${ + apiTsln.detail.oas.serviceCanadaReviewYourPayment + }

${ + result.entitlement.result === 0 + ? apiTsln.detail.oas.automaticallyBePaid + : '' + }

` } else { - !receivingOAS - ? (nextStepText.nextStepContent += `${apiTsln.detail.oas.serviceCanadaReviewYourPayment}`) - : '' + nextStepText.nextStepContent += `${apiTsln.detail.oas.youWillReceiveLetter}` + // ifYouDidnt: + if (inputAge < 65) { + } else if (inputAge > 64 && inputAge < 70) { + nextStepText.nextStepContent += ` ${apiTsln.detail.oas.ifYouDidnt}` + } + nextStepText.nextStepContent += `

${apiTsln.detail.futureDeferralOptions}

` + nextStepText.nextStepContent += `

${apiTsln.detail.youCanAply}

` - result.eligibility.reason === ResultReason.INCOME - ? (nextStepText.nextStepContent += - ' ' + apiTsln.detail.oas.automaticallyBePaid) - : '' + if (result.entitlement.result == 0) { + nextStepText.nextStepContent += `

${apiTsln.detail.onceEnrolled}

` + } } - //code for future --end-- } - } else if ( - result.eligibility.result === ResultKey.INELIGIBLE && - result.eligibility.reason === ResultReason.AGE_YOUNG_64 - ) { - nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - nextStepText.nextStepContent += - apiTsln.detail.oas.youShouldHaveReceivedLetter - nextStepText.nextStepContent += ` ${apiTsln.detail.oas.ifNotReceiveLetter64}` } return nextStepText @@ -122,30 +57,25 @@ export function getGisNextSteps( apiTsln: Translations, tsln: WebTranslations ) { - if ( - result.eligibility.result === ResultKey.ELIGIBLE || - result.eligibility.result === ResultKey.INCOME_DEPENDENT - ) { + if (result.eligibility.result === ResultKey.ELIGIBLE) { nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - if (result.eligibility.reason === ResultReason.INCOME) { - nextStepText.nextStepContent = tsln.resultsPage.nextStepGis + if (!receivingOAS) { + nextStepText.nextStepContent += `

${apiTsln.detail.gis.youCanApplyGis}

` if (result.entitlement.result === 0) { - if (receivingOAS) { - nextStepText.nextStepContent = apiTsln.detail.gis.ifYouApply - nextStepText.nextStepContent += `

${apiTsln.detail.gis.ifYouAlreadyApplied}

` - } else - nextStepText.nextStepContent += `

${apiTsln.detail.gis.ifYouApply}

` + nextStepText.nextStepContent += `

${apiTsln.detail.gis.ifYouApply}

` + } + } else { + if (result.entitlement.result > 0) { + nextStepText.nextStepContent += `

${apiTsln.detail.gis.canApplyOnline}

` + } else { + nextStepText.nextStepContent += `

${apiTsln.detail.gis.ifYouApply}

` } - } else if (result.entitlement.result > 0 && receivingOAS) { - nextStepText.nextStepContent = - apiTsln.detail.gis.canApplyOnline + - `

${apiTsln.detail.gis.ifYouAlreadyReceive}

` - } else if (result.entitlement.result > 0 && !receivingOAS) { - nextStepText.nextStepContent = tsln.resultsPage.nextStepGis - } else if (result.entitlement.result <= 0 && receivingOAS) { - nextStepText.nextStepContent = apiTsln.detail.gis.ifYouApply nextStepText.nextStepContent += `

${apiTsln.detail.gis.ifYouAlreadyApplied}

` } + } else { + if (result.eligibility.result === ResultReason.LIVING_COUNTRY) { + nextStepText.nextStepContent += `

${apiTsln.detail.mustBeInCanada}

` + } } return nextStepText @@ -154,30 +84,51 @@ export function getGisNextSteps( // export function getAlwNextSteps( result: any, + partnerResults: any, inputAge: number, nextStepText: NextStepText, apiTsln: Translations, tsln: WebTranslations ) { - if (result.eligibility.result === ResultKey.ELIGIBLE) { - const ifYouApplyText = - apiTsln.detail.alwIfYouApply + - `${numberToStringCurrency( - legalValues.alw.alwIncomeLimit, - apiTsln._language, - { rounding: 0 } - )}.` + // if (result.eligibility.result === ResultKey.ELIGIBLE) { + // const ifYouApplyText = + // apiTsln.detail.alwIfYouApply + + // `${numberToStringCurrency( + // legalValues.alw.alwIncomeLimit, + // apiTsln._language, + // { rounding: 0 } + // )}.` - if (inputAge < 60) { - nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + // if (inputAge < 60) { + // nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + // nextStepText.nextStepContent += apiTsln.detail.alwsApply + // if (result.entitlement.result === 0) { + // nextStepText.nextStepContent += ifYouApplyText + // } + // } else if (result.entitlement.result === 0) { + // nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + // nextStepText.nextStepContent += ifYouApplyText + // } + // } + const ifYouApplyText = + apiTsln.detail.alwIfYouApply + + `${numberToStringCurrency( + legalValues.alw.alwIncomeLimit, + apiTsln._language, + { rounding: 0 } + )}.` + nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + + if ( + result.eligibility.result === ResultKey.ELIGIBLE || + result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + ) { + if (result.entitlement.result > 0) { nextStepText.nextStepContent += apiTsln.detail.alwsApply - if (result.entitlement.result === 0) { - nextStepText.nextStepContent += ifYouApplyText - } - } else if (result.entitlement.result === 0) { - nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + } else { nextStepText.nextStepContent += ifYouApplyText } + } else { } return nextStepText diff --git a/i18n/api/en.ts b/i18n/api/en.ts index da012f2e1..c78a6886d 100644 --- a/i18n/api/en.ts +++ b/i18n/api/en.ts @@ -350,9 +350,11 @@ const en: Translations = { sinceYouAreSixty: "Since you're {CURRENT_AGE}, you can start receiving your payments right away or wait for up to {WAIT_MONTHS} more {MONTH_MONTHS}.", futureDeferralOptions: - "You can start receiving your payments at {EARLIEST_ELIGIBLE_AGE} or wait until you're 70.", + "If you're automatically enrolled, you can start receiving payments the month after you turn 65 unless you request a deferral.", youCanAply: - 'You can apply 11 months before the date you want your payments to start.', + "If you're not enrolled, you can apply up to 11 months before you want your payements to start. ", + onceEnrolled: + "Once you’re enroled, your payment amount will be reviewed each year based on your income tax return. You'll automatically be paid if your income qualifies.", delayMonths: 'You can delay your pension for up to {DELAY_MONTHS} more {MONTH_MONTHS}.', eligibleWhen60ApplyNow: @@ -401,7 +403,7 @@ const en: Translations = { alwEligibleIncomeTooHigh: "You're likely eligible for this benefit, but you and your partner’s combined income is too high to receive a monthly payment at this time.", alwIfYouApply: - "If you apply, Service Canada will review your income tax return every year. You'll automatically be paid if your combined income is less than ", + "If you apply, Service Canada will review your income tax return every year. You'll automatically be paid if your couple's income is less than ", alwsIfYouApply: "If you apply, Service Canada will review your income tax return every year. You'll automatically be paid if your income is less than ", afsNotEligible: @@ -436,17 +438,17 @@ const en: Translations = { futureEligibleIncomeTooHigh: 'You may be eligible once you turn 65. Since your income is too high, you may not receive a monthly payment.', serviceCanadaReviewYourPayment: - 'If you apply, Service Canada will review your payment amount each year based on your income tax return.', + 'If you apply, your payement will be reviewed each year based on your income tax return.', automaticallyBePaid: "You'll automatically be paid if your income qualifies.", youWillReceiveLetter: - 'You should receive a letter about your enrolment status the month after you turn 64.', + 'Your enrollement status should be confirmed by mail the month after you turn 64.', youShouldReceiveLetter: - 'You should receive a letter about your enrolment status the month after you turn 64.', + 'Your enrollement status should be confirmed by mail the month after you turn 64.', youShouldHaveReceivedLetter: 'You should have received a letter about your enrolment status the month after you turned 64.', ifYouDidnt: - "If you didn't, contact us to find out if you need to apply.", + "If you didn't receive a letter, contact us to find out if you need to apply.", applyOnline: "If you didn't, you can apply online.", over70: "If you're over the age of 70 and are not receiving an Old Age Security pension, apply now.", @@ -460,6 +462,8 @@ const en: Translations = { 'You may be able to receive payment for up to the last 11 months.', }, gis: { + youCanApplyGis: + 'You can apply for the Guaranteed Income Supplement when you apply for the Old Age Security pension.', eligibleDependingOnIncomeNoEntitlement: 'You could likely receive this benefit if {INCOME_SINGLE_OR_COMBINED} is less than {INCOME_LESS_THAN}. Provide {YOUR_OR_COMPLETE} to get a monthly payment estimate.', incomeTooHigh: @@ -468,7 +472,7 @@ const en: Translations = { 'You may be eligible once you turn 65. If your income stays the same, you may not receive a monthly payment.', ifYouApply: "If you apply, Service Canada will review your income tax return every year. You'll automatically be paid if your income qualifies.", - canApplyOnline: 'You can apply for this benefit online.', + canApplyOnline: 'You can apply for this benefit.', ifYouAlreadyApplied: 'If you already applied for the Guaranteed Income Supplement, you can confirm that your information is up to date in your {MY_SERVICE_CANADA}.', ifYouAlreadyReceive: diff --git a/i18n/api/fr.ts b/i18n/api/fr.ts index a7c011590..263c69fc6 100644 --- a/i18n/api/fr.ts +++ b/i18n/api/fr.ts @@ -361,6 +361,8 @@ const fr: Translations = { "Vous pouvez commencer à recevoir vos paiements à {EARLIEST_ELIGIBLE_AGE} ans ou attendre d'avoir 70 ans.", youCanAply: 'Vous pouvez présenter votre demande 11 mois avant la date à laquelle vous aimeriez recevoir votre premier paiement.', + onceEnrolled: + 'Quand vous serez inscrit, le montant de votre paiement sera révisé chaque année en fonction de votre déclaration de revenus. Vous recevrez automatiquement des paiements si votre revenu est admissible.', delayMonths: 'Vous pouvez reporter votre pension pour encore {DELAY_MONTHS} mois.', eligibleWhen60ApplyNow: @@ -470,6 +472,8 @@ const fr: Translations = { 'Vous pourriez recevoir un paiement pour un maximum des 11 derniers mois.', }, gis: { + youCanApplyGis: + 'Vous pouvez faire une demande pour le Supplément de revenu garanti lorsque vous présentez votre demande pour la pension de la Sécurité de la vieillesse.', eligibleDependingOnIncomeNoEntitlement: 'Vous pourriez probablement recevoir cette prestation si {INCOME_SINGLE_OR_COMBINED} est moins que {INCOME_LESS_THAN}. Fournissez {YOUR_OR_COMPLETE} pour obtenir une estimation de paiement mensuel.', incomeTooHigh: @@ -478,8 +482,7 @@ const fr: Translations = { 'Vous pourriez être admissible lorsque vous aurez 65 ans. Si votre revenu reste le même, vous ne recevrez peut-être pas de paiement mensuel.', ifYouApply: 'Si vous présentez une demande, Service Canada révisera votre déclaration de revenus chaque année. Vous recevrez automatiquement des paiements si votre revenu est admissible.', - canApplyOnline: - 'Vous pouvez faire une demande pour cette prestation en ligne.', + canApplyOnline: 'Vous pouvez faire une demande pour cette prestation.', ifYouAlreadyApplied: 'Si vous avez déjà fait une demande pour le Supplément de revenu garanti, vous pouvez confirmer que vos renseignements sont à jour dans votre compte {MY_SERVICE_CANADA}.', ifYouAlreadyReceive: diff --git a/i18n/api/index.ts b/i18n/api/index.ts index 26b0c3a0d..7c7d26e5d 100644 --- a/i18n/api/index.ts +++ b/i18n/api/index.ts @@ -66,6 +66,7 @@ export interface Translations { sinceYouAreSixty: string futureDeferralOptions: string youCanAply: string + onceEnrolled: string delayMonths: string eligibleWhen60ApplyNow: string eligibleWhen65ApplyNow: string @@ -124,6 +125,7 @@ export interface Translations { receivePayment: string } gis: { + youCanApplyGis: string eligibleDependingOnIncomeNoEntitlement: string incomeTooHigh: string futureEligibleIncomeTooHigh: string diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index 04348a6e3..d6c096228 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -443,40 +443,40 @@ export class OasBenefit extends BaseBenefit { ) return cardCollapsedText - if (this.partner && this.entitlement.result !== 0) { - if ( - // eslint-disable-next-line prettier/prettier - this.input.partnerBenefitStatus.value === - PartnerBenefitStatus.OAS_GIS || - this.input.partnerBenefitStatus.value === PartnerBenefitStatus.HELP_ME - ) { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerEligible - ) - } else { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerEligibleButAnsweredNo - ) - } - - return cardCollapsedText - } - - // getCardText reset the eligibility reason - if (this.eligibility.reason === ResultReason.INCOME) - return cardCollapsedText - - // increase at 75 - if (this.currentEntitlementAmount !== this.age75EntitlementAmount) { - if (!this.future) { - cardCollapsedText.push( - this.translations.detailWithHeading.oasIncreaseAt75 - ) - } - } else - cardCollapsedText.push( - this.translations.detailWithHeading.oasIncreaseAt75Applied - ) + // if (this.partner && this.entitlement.result !== 0) { + // if ( + // // eslint-disable-next-line prettier/prettier + // this.input.partnerBenefitStatus.value === + // PartnerBenefitStatus.OAS_GIS || + // this.input.partnerBenefitStatus.value === PartnerBenefitStatus.HELP_ME + // ) { + // cardCollapsedText.push( + // this.translations.detailWithHeading.partnerEligible + // ) + // } else { + // cardCollapsedText.push( + // this.translations.detailWithHeading.partnerEligibleButAnsweredNo + // ) + // } + + // return cardCollapsedText + // } + + // // getCardText reset the eligibility reason + // if (this.eligibility.reason === ResultReason.INCOME) + // return cardCollapsedText + + // // increase at 75 + // if (this.currentEntitlementAmount !== this.age75EntitlementAmount) { + // if (!this.future) { + // cardCollapsedText.push( + // this.translations.detailWithHeading.oasIncreaseAt75 + // ) + // } + // } else + // cardCollapsedText.push( + // this.translations.detailWithHeading.oasIncreaseAt75Applied + // ) // deferral // if (this.deferralIncrease) @@ -492,130 +492,130 @@ export class OasBenefit extends BaseBenefit { } protected getCardText(): string { - // overwrite eligibility detail if income too high - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - this.entitlement.type === EntitlementResultType.NONE - ) { - //this.eligibility.result = ResultKey.INELIGIBLE - this.eligibility.reason = ResultReason.INCOME - this.eligibility.detail = this.future - ? this.translations.detail.futureEligibleIncomeTooHigh - : this.translations.detail.eligibleIncomeTooHigh - this.entitlement.autoEnrollment = this.getAutoEnrollment() - } - - // INTRO 1 - general eligibility already in the detail - let text = this.eligibility.detail - - // INTRO 2 - "expect to receive" variation - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - this.eligibility.reason !== ResultReason.INCOME && - this.entitlement.result > 0 - ) { - if (this.future) { - if (!this.input.livedOnlyInCanada) { - text += ` ${this.translations.detail.futureExpectToReceivePartial1}` - if ( - this.formAge != this.input.age && - this.formYearsInCanada <= 40 && - this.formYearsInCanada != this.input.yearsInCanadaSince18 - ) { - text += `${this.translations.detail.futureExpectToReceivePartial2}` - } - text += ` ${this.translations.detail.futureExpectToReceivePartial3}` - } else { - text += ` ${this.translations.detail.futureExpectToReceive}` - } - } else { - text += ` ${this.translations.detail.expectToReceive}` - } - } - - // special case - if (this.eligibility.result === ResultKey.INCOME_DEPENDENT) { - text += `

${this.translations.detail.oas.dependOnYourIncome}

` - } - - // special case - if ( - this.eligibility.result === ResultKey.INELIGIBLE && - this.eligibility.reason === ResultReason.AGE_YOUNG - ) { - text += this.translations.nextStepTitle - //text += `

${this.translations.detail.oas.youShouldReceiveLetter}

` - text += `

${this.translations.detail.oas.youShouldHaveReceivedLetter}

` - } - - if (this.eligibility.reason !== ResultReason.INCOME) { - const clawbackValue = this.entitlement.clawback - - if (!this.partner && this.input.livingCountry.canada) { - text += - clawbackValue > 0 - ? this.future - ? `
${this.translations.detail.futureOasClawbackInCanada}
` - : `
${this.translations.detail.oasClawbackInCanada}
` - : '' - } else { - text += - clawbackValue > 0 - ? `
${this.translations.detail.oasClawbackNotInCanada}
` - : '' - } - } - - // RETROACTIVE PAY - if ( - !this.future && - this.eligibility.result === ResultKey.ELIGIBLE && - !this.partner && - (!this.input.receiveOAS || this.deferral) && - (this.input.age > 70 || this.inputAge > 70) && - this.eligibility.reason !== ResultReason.INCOME - ) { - // if (this.inputAge !== this.input.age) { - // Retroactive pay - text += `

${this.translations.detail.retroactivePay}

` - text += `

${this.translations.detail.oas.receivePayment}

` - // } - } - - // DEFERRAL - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - !this.partner && - (!this.input.receiveOAS || this.deferral) && - this.input.age < 70 && - this.inputAge < 70 - ) { - // your Deferral Options - - // if income too high - if (this.eligibility.reason === ResultReason.INCOME) { - if (!this.future) { - text += `

${this.translations.detail.yourDeferralOptions}

` - text += this.translations.detail.delayMonths - } - } - - // normal case - if (this.entitlement.result > 0) { - text += `

${this.translations.detail.yourDeferralOptions}

` - if (this.future) { - // can also check if this.entitlement.clawback === 0 - text += this.translations.detail.futureDeferralOptions - } else { - text += this.translations.detail.sinceYouAreSixty - - if (!this.deferral && this.input.yearsInCanadaSince18 < 40) { - text += `

${this.translations.detail.oas.chooseToDefer}

` - } - } - } - } - + // // overwrite eligibility detail if income too high + // if ( + // this.eligibility.result === ResultKey.ELIGIBLE && + // this.entitlement.type === EntitlementResultType.NONE + // ) { + // //this.eligibility.result = ResultKey.INELIGIBLE + // this.eligibility.reason = ResultReason.INCOME + // this.eligibility.detail = this.future + // ? this.translations.detail.futureEligibleIncomeTooHigh + // : this.translations.detail.eligibleIncomeTooHigh + // this.entitlement.autoEnrollment = this.getAutoEnrollment() + // } + + // // INTRO 1 - general eligibility already in the detail + // let text = this.eligibility.detail + + // // INTRO 2 - "expect to receive" variation + // if ( + // this.eligibility.result === ResultKey.ELIGIBLE && + // this.eligibility.reason !== ResultReason.INCOME && + // this.entitlement.result > 0 + // ) { + // if (this.future) { + // if (!this.input.livedOnlyInCanada) { + // text += ` ${this.translations.detail.futureExpectToReceivePartial1}` + // if ( + // this.formAge != this.input.age && + // this.formYearsInCanada <= 40 && + // this.formYearsInCanada != this.input.yearsInCanadaSince18 + // ) { + // text += `${this.translations.detail.futureExpectToReceivePartial2}` + // } + // text += ` ${this.translations.detail.futureExpectToReceivePartial3}` + // } else { + // text += ` ${this.translations.detail.futureExpectToReceive}` + // } + // } else { + // text += ` ${this.translations.detail.expectToReceive}` + // } + // } + + // // special case + // if (this.eligibility.result === ResultKey.INCOME_DEPENDENT) { + // text += `

${this.translations.detail.oas.dependOnYourIncome}

` + // } + + // // special case + // if ( + // this.eligibility.result === ResultKey.INELIGIBLE && + // this.eligibility.reason === ResultReason.AGE_YOUNG + // ) { + // text += this.translations.nextStepTitle + // //text += `

${this.translations.detail.oas.youShouldReceiveLetter}

` + // text += `

${this.translations.detail.oas.youShouldHaveReceivedLetter}

` + // } + + // if (this.eligibility.reason !== ResultReason.INCOME) { + // const clawbackValue = this.entitlement.clawback + + // if (!this.partner && this.input.livingCountry.canada) { + // text += + // clawbackValue > 0 + // ? this.future + // ? `
${this.translations.detail.futureOasClawbackInCanada}
` + // : `
${this.translations.detail.oasClawbackInCanada}
` + // : '' + // } else { + // text += + // clawbackValue > 0 + // ? `
${this.translations.detail.oasClawbackNotInCanada}
` + // : '' + // } + // } + + // // RETROACTIVE PAY + // if ( + // !this.future && + // this.eligibility.result === ResultKey.ELIGIBLE && + // !this.partner && + // (!this.input.receiveOAS || this.deferral) && + // (this.input.age > 70 || this.inputAge > 70) && + // this.eligibility.reason !== ResultReason.INCOME + // ) { + // // if (this.inputAge !== this.input.age) { + // // Retroactive pay + // text += `

${this.translations.detail.retroactivePay}

` + // text += `

${this.translations.detail.oas.receivePayment}

` + // // } + // } + + // // DEFERRAL + // if ( + // this.eligibility.result === ResultKey.ELIGIBLE && + // !this.partner && + // (!this.input.receiveOAS || this.deferral) && + // this.input.age < 70 && + // this.inputAge < 70 + // ) { + // // your Deferral Options + + // // if income too high + // if (this.eligibility.reason === ResultReason.INCOME) { + // if (!this.future) { + // text += `

${this.translations.detail.yourDeferralOptions}

` + // text += this.translations.detail.delayMonths + // } + // } + + // // normal case + // if (this.entitlement.result > 0) { + // text += `

${this.translations.detail.yourDeferralOptions}

` + // if (this.future) { + // // can also check if this.entitlement.clawback === 0 + // text += this.translations.detail.futureDeferralOptions + // } else { + // text += this.translations.detail.sinceYouAreSixty + + // if (!this.deferral && this.input.yearsInCanadaSince18 < 40) { + // text += `

${this.translations.detail.oas.chooseToDefer}

` + // } + // } + // } + // } + let text = null return text } diff --git a/utils/api/fieldsHandler.ts b/utils/api/fieldsHandler.ts index 5d6d6e1c6..40f6f4025 100644 --- a/utils/api/fieldsHandler.ts +++ b/utils/api/fieldsHandler.ts @@ -312,19 +312,22 @@ export class FieldsHandler { textToProcess: string, benefitResult?: BenefitResult ): string { - const re: RegExp = new RegExp(/{(\w*?)}/g) - const matches: IterableIterator = - textToProcess.matchAll(re) - for (const match of matches) { - const key: string = match[1] - const replacementRule = textReplacementRules[key] - if (!replacementRule) - throw new Error(`no text replacement rule for ${key}`) - textToProcess = textToProcess.replace( - `{${key}}`, - replacementRule(benefitHandlerInstance, benefitResult) - ) + if (textToProcess) { + const re: RegExp = new RegExp(/{(\w*?)}/g) + const matches: IterableIterator = + textToProcess.matchAll(re) + for (const match of matches) { + const key: string = match[1] + const replacementRule = textReplacementRules[key] + if (!replacementRule) + throw new Error(`no text replacement rule for ${key}`) + textToProcess = textToProcess.replace( + `{${key}}`, + replacementRule(benefitHandlerInstance, benefitResult) + ) + } } + return textToProcess } @@ -419,12 +422,14 @@ export class FieldsHandler { * Accepts a string, generally containing newlines (\n), and capitalizes the first character of each line. */ static capitalizeEachLine(s: string): string { - const lines: string[] = s.split('\n') - return lines - .reduce((result, line) => { - return result + this.capitalizeFirstChar(line) + '\n' - }, '') - .trim() + if (s) { + const lines: string[] = s.split('\n') + return lines + .reduce((result, line) => { + return result + this.capitalizeFirstChar(line) + '\n' + }, '') + .trim() + } } /** From 6987ece185d88c347d33001a4924c976d10b27f0 Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Tue, 28 May 2024 07:58:52 -0400 Subject: [PATCH 02/12] Summary + next steps done --- components/Forms/Button.tsx | 2 +- components/ResultsPage/BenefitCard.tsx | 30 +- components/ResultsPage/BenefitCards.tsx | 4 +- components/ResultsPage/EstimatedTotal.tsx | 42 +-- components/ResultsPage/EstimatedTotalItem.tsx | 6 +- .../ResultsPage/FutureBenefitEstimate.tsx | 294 ++++++++++++++++++ .../ResultsPage/FutureSummaryEstimates.tsx | 92 ++++++ components/ResultsPage/NextSteps.tsx | 65 ++-- components/ResultsPage/SummaryEstimates.tsx | 64 ++++ components/ResultsPage/WillBeEligible.tsx | 18 +- components/ResultsPage/index.tsx | 77 ++--- i18n/api/en.ts | 27 ++ i18n/api/fr.ts | 29 +- i18n/api/index.ts | 24 ++ i18n/web/en.ts | 7 +- i18n/web/fr.ts | 9 +- i18n/web/index.ts | 6 + utils/api/benefits/_base.ts | 6 +- utils/api/benefits/alwBenefit.ts | 45 --- utils/api/benefits/gisBenefit.ts | 42 --- utils/api/benefits/oasBenefit.ts | 128 -------- 21 files changed, 641 insertions(+), 376 deletions(-) create mode 100644 components/ResultsPage/FutureBenefitEstimate.tsx create mode 100644 components/ResultsPage/FutureSummaryEstimates.tsx create mode 100644 components/ResultsPage/SummaryEstimates.tsx diff --git a/components/Forms/Button.tsx b/components/Forms/Button.tsx index fa4369ea0..ad1bf8c99 100644 --- a/components/Forms/Button.tsx +++ b/components/Forms/Button.tsx @@ -48,7 +48,7 @@ export const Button: React.FC = ({ return href ? ( - {text} + {imgHref && alt} {text} ) : ( diff --git a/components/ResultsPage/BenefitCard.tsx b/components/ResultsPage/BenefitCard.tsx index 499cc1b63..f0677b7d4 100644 --- a/components/ResultsPage/BenefitCard.tsx +++ b/components/ResultsPage/BenefitCard.tsx @@ -3,6 +3,7 @@ import Image from 'next/image' import React from 'react' import { NextStepText } from '../../utils/api/definitions/types' import { CustomCollapse } from './CustomCollapse' +import { Router, useRouter } from 'next/router' const AA_BUTTON_CLICK_ATTRIBUTE = 'ESDC-EDSC:Canadian OAS Benefits Est. Result card link click' @@ -39,10 +40,8 @@ export const BenefitCard: React.VFC<{ @@ -50,6 +49,8 @@ export const BenefitCard: React.VFC<{ ) + const router = useRouter() + return (
- {/*

- {nextStepText.nextStepTitle} -

*/}

(

- {/*
- {alt} -
*/}
- {/* - {text} - */} + />
diff --git a/components/ResultsPage/BenefitCards.tsx b/components/ResultsPage/BenefitCards.tsx index 0f5cbd860..77f05e332 100644 --- a/components/ResultsPage/BenefitCards.tsx +++ b/components/ResultsPage/BenefitCards.tsx @@ -172,9 +172,7 @@ export const BenefitCards: React.VFC<{ result.eligibility.result === ResultKey.INCOME_DEPENDENT const eligibleText = eligibility - ? future - ? apiTsln.result.willBeEligible - : apiTsln.result.eligible + ? apiTsln.result.eligible : apiTsln.result.ineligible const nextStepText = getNextStepText(result.benefitKey, result) diff --git a/components/ResultsPage/EstimatedTotal.tsx b/components/ResultsPage/EstimatedTotal.tsx index a29c2233c..e4ed49147 100644 --- a/components/ResultsPage/EstimatedTotal.tsx +++ b/components/ResultsPage/EstimatedTotal.tsx @@ -25,17 +25,12 @@ export const EstimatedTotal: React.VFC<{ const language = useRouter().locale as Language - const getText = (type) => { - switch (type) { - case 'header': - return partner - ? tsln.resultsPage.partnerEstimatedTotal - : tsln.resultsPage.yourEstimatedTotal - case 'intro': - return partner - ? tsln.resultsPage.basedOnPartnerInfoTotal - : tsln.resultsPage.basedOnYourInfoTotal - } + const buildSummaryString = (partner) => { + return `${!partner ? apiTrans.detail.you : apiTrans.detail.yourPartner} ${ + apiTrans.detail.youCouldReceive + } ${numberToStringCurrency(entitlementSum, language)} ${ + apiTrans.detail.youCouldReceivePerMonth + }` } // If partner answers "No" to receiving OAS, the amounts should not show @@ -48,22 +43,10 @@ export const EstimatedTotal: React.VFC<{ return ( <> -

- {entitlementSum != 0 ? ( - - ) : ( - - )} - {getText('header')} -

-
-

+

+ {buildSummaryString(partner)} +
    {resultsEligible.map((benefit) => ( @@ -75,13 +58,6 @@ export const EstimatedTotal: React.VFC<{ /> ))}
- - {entitlementSum != 0 && resultsEligible.length > 1 && ( -

- {partner ? tsln.resultsPage.partnerTotal : tsln.resultsPage.total} - {numberToStringCurrency(entitlementSum, language)}. -

- )}
) diff --git a/components/ResultsPage/EstimatedTotalItem.tsx b/components/ResultsPage/EstimatedTotalItem.tsx index f20f3beea..5c33604b4 100644 --- a/components/ResultsPage/EstimatedTotalItem.tsx +++ b/components/ResultsPage/EstimatedTotalItem.tsx @@ -40,10 +40,8 @@ export const EstimatedTotalItem: React.VFC<{ return (
  • - - {displayAmount && - numberToStringCurrency(result.entitlement.result, tsln._language)} - + {displayAmount && + numberToStringCurrency(result.entitlement.result, tsln._language)} {displayBenefitName(heading, result.entitlement.result, displayAmount)}
  • ) diff --git a/components/ResultsPage/FutureBenefitEstimate.tsx b/components/ResultsPage/FutureBenefitEstimate.tsx new file mode 100644 index 000000000..db39bafb0 --- /dev/null +++ b/components/ResultsPage/FutureBenefitEstimate.tsx @@ -0,0 +1,294 @@ +import { result } from 'lodash' +import next from 'next' +import Image from 'next/image' +import { useRouter } from 'next/router' +import { P } from 'pino' +import { useState } from 'react' +import { getTranslations, numberToStringCurrency } from '../../i18n/api' +import { WebTranslations } from '../../i18n/web' +import Results from '../../pages/results' +import { + BenefitKey, + Language, + ResultKey, + ResultReason, +} from '../../utils/api/definitions/enums' +import { BenefitResult } from '../../utils/api/definitions/types' +import { useTranslation } from '../Hooks' +import { DeferralTable } from './DeferralTable' +import { EstimatedTotalItem } from './EstimatedTotalItem' + +export const FutureBenefitEstimate: React.VFC<{ + partnerNoOAS?: boolean + futureBenefits?: any + futurePartnerBenefits?: any + multipleResults?: boolean + eligibleOAS?: boolean + resultObj: BenefitResult + index: number + key?: any +}> = ({ + partnerNoOAS, + futureBenefits, + futurePartnerBenefits, + multipleResults, + eligibleOAS, + index, + key, + resultObj, +}) => { + const tsln = useTranslation() + const apiTrans = getTranslations(tsln._language) + const language = useRouter().locale as Language + + const age = Object.keys(resultObj)[0] + const benefitType = Object.keys(resultObj[Object.keys(resultObj)[0]]) + + // const onlyOASGIS = Object.keys(resultObj[Object.keys(resultObj)[0]]).filter( + // (key) => key === 'oas' || key === 'gis' + // ) + + // // show if some are non zero + // const nonZeroExist = onlyOASGIS.some( + // (key) => resultObj[age][key].entitlement?.result > 0 + // ) + const partner = futurePartnerBenefits.includes(resultObj) + + const resultsArray: BenefitResult[] = Object.keys(resultObj[age]).map( + (value) => resultObj[age][value] + ) + + let eligible = resultsArray.filter( + (result) => + result.eligibility?.result === ResultKey.ELIGIBLE || + result.eligibility?.result === ResultKey.INCOME_DEPENDENT + ) + + // If partner answers "No" to receiving OAS, the amounts should not show + if (partner && partnerNoOAS) { + eligible = eligible.map((benefit) => { + return { + ...benefit, + entitlement: { ...benefit.entitlement, result: 0 }, + } + }) + } + + const eligibleTotalAmount = eligible.reduce( + (sum, obj) => sum + obj.entitlement.result, + 0 + ) + + //check if current resultObj is the first Oas and Gis estimation + const isFirstOasGis = (partner, resultObj) => { + let isFirst = false + + const resultArray = partner ? futurePartnerBenefits : futureBenefits + + for (let i = 0; i < resultArray.length; i++) { + const obj = resultArray[i] + if ( + Object.keys(obj[Object.keys(obj)[0]]).includes('oas') && + Object.keys(obj[Object.keys(obj)[0]]).includes('gis') + ) { + // Check if it's the same object + if (JSON.stringify(obj) === JSON.stringify(resultObj)) { + // console.log(' is first') + isFirst = true + } + break + } + } + return isFirst + } + + //check if current resultObj is the last Oas and Gis estimation + const isLastOasGis = (partner, resultObj) => { + let isLast = false + + const resultArray = partner ? futurePartnerBenefits : futureBenefits + + for (let i = resultArray.length - 1; i >= 0; i--) { + const obj = resultArray[i] + if ( + Object.keys(obj[Object.keys(obj)[0]]).includes('oas') && + Object.keys(obj[Object.keys(obj)[0]]).includes('gis') + ) { + // Check if it's the same object + if (JSON.stringify(obj) === JSON.stringify(resultObj)) { + isLast = true + } + break + } + } + + return isLast + } + + // build the string to display current estimation + const getSummaryBenefitStr = (eligibleAmt) => { + let text + + let isPartnerStr = partner + ? apiTrans.detail.yourPartner + : apiTrans.detail.you + + //ALW & ALWS + if (!benefitType.includes('oas') || !benefitType.includes('gis')) { + if ( + resultObj[age][benefitType[0]].eligibility.result === ResultKey.ELIGIBLE + ) { + text = `${apiTrans.detail.youCouldReceiveFrom} ${age} ${ + apiTrans.detail.youCouldReceiveTo + } 65${language == 'fr' ? ' ans' : ''},` + } else { + text = `${apiTrans.detail.youCouldReceiveUntil} ${age}${ + language == 'fr' ? ' ans' : '' + },` + } + text += ` ${isPartnerStr} ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //OAS GIS ESTIMATE + else { + const firstOasGis = isFirstOasGis(partner, resultObj) + const lastOasGis = isLastOasGis(partner, resultObj) + // console.log(resultObj) + // console.log(futureBenefits) + + const arrayofben = partner ? futurePartnerBenefits : futureBenefits + + //NOT FIRST ESTIMATE + if (!firstOasGis) { + const previousBenefitResult = + arrayofben[arrayofben.indexOf(resultObj) - 1] + console.log('previous one', previousBenefitResult) + const previousBenefitTotal = + previousBenefitResult[Object.keys(previousBenefitResult)[0]]['oas'] + .entitlement.result + + previousBenefitResult[Object.keys(previousBenefitResult)[0]]['gis'] + + //IF ESTIMATE IS THE SAME AS LAST + if (previousBenefitTotal === eligibleTotalAmount) { + text = `${ + partner + ? apiTrans.detail.yourEstimateIsStillPartner + : apiTrans.detail.yourEstimateIsStill + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } else { + //NOT THE LAST ESTIMATE + if (!lastOasGis) { + text += 'middle' + const nextBenefitResult = + arrayofben[arrayofben.indexOf(resultObj) + 1] + console.log('next one', nextBenefitResult) + + const nextBenefitTotal = + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] + .entitlement.result + + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['gis'] + .entitlement.result + + console.log(Object.keys(nextBenefitResult)[0]) + //CHECK IF NEXT RESULT IS THE SAME + //I4 + if (eligibleTotalAmount !== nextBenefitTotal) { + text = `${apiTrans.detail.youCouldReceiveFrom} ${age} ${ + apiTrans.detail.youCouldReceiveTo + } ${Object.keys(nextBenefitResult)[0]}${ + language == 'fr' ? ' ans' : '' + },` + text += ` ${isPartnerStr} ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //I6 + else { + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${ + partner ? apiTrans.detail.yourPartner : apiTrans.detail.you + } ${apiTrans.detail.youCouldContinueReceiving} ${eligibleAmt} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } + } + //LAST ESTIMATE + else { + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${partner ? apiTrans.detail.yourPartner : apiTrans.detail.you} ${ + apiTrans.detail.youCouldContinueReceiving + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + } + } + //FIRST ESTIMATE + else { + //IS ALSO THE LAST + if (lastOasGis) { + //DIsplay I5 + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${partner ? apiTrans.detail.yourPartner : apiTrans.detail.you} ${ + apiTrans.detail.youCouldContinueReceiving + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //NOT THE LAST + else { + //NEXT ESTIMATE THE SAME -> I5 + const nextBenefitResult = + arrayofben[arrayofben.indexOf(resultObj) + 1] + console.log('next one', nextBenefitResult) + + const nextBenefitTotal = + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] + .entitlement.result + + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['gis'] + .entitlement.result + if (nextBenefitTotal === eligibleTotalAmount) { + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${partner ? apiTrans.detail.yourPartner : apiTrans.detail.you} ${ + apiTrans.detail.youCouldContinueReceiving + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //ELSE -> I3 + else { + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${partner ? apiTrans.detail.yourPartner : apiTrans.detail.you} ${ + apiTrans.detail.youCouldReceive + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + } + } + } + + return text + } + + return ( +
    +
    + +

    + + +

      + {eligible.map((benefit) => ( + + ))} +
    +
    +
    + ) +} diff --git a/components/ResultsPage/FutureSummaryEstimates.tsx b/components/ResultsPage/FutureSummaryEstimates.tsx new file mode 100644 index 000000000..9717caa2c --- /dev/null +++ b/components/ResultsPage/FutureSummaryEstimates.tsx @@ -0,0 +1,92 @@ +import { useRouter } from 'next/router' +import { getTranslations } from '../../i18n/api' +import { WebTranslations } from '../../i18n/web' +import { Language } from '../../utils/api/definitions/enums' +import { useTranslation } from '../Hooks' +import { FutureBenefitEstimate } from './FutureBenefitEstimate' + +export const FutureSummaryEstimates: React.VFC<{ + futureResults: any + futurePartnerResults: any + partner?: boolean + partnerNoOAS: boolean + multipleResults: boolean + eligibleOAS: boolean + userAge: any +}> = ({ + futureResults, + futurePartnerResults, + partner = false, + partnerNoOAS, + multipleResults, + eligibleOAS, + userAge, +}) => { + const tsln = useTranslation() + const apiTrans = getTranslations(tsln._language) + const language = useRouter().locale as Language + + const multipleOAS_GIS = + futureResults.filter((obj) => !!obj[Object.keys(obj)[0]]['oas']).length > 1 + + let arr1 + let arr2 + futurePartnerResults = futurePartnerResults ? futurePartnerResults : [] + + if (futureResults.length < futurePartnerResults) { + partner = true + arr1 = futurePartnerResults + arr2 = futureResults + } else { + arr1 = futureResults + arr2 = futurePartnerResults + } + + const results = arr1.map((obj1, index) => [ + obj1, + arr2[index] ? arr2[index] : null, + ]) + const currentYear = new Date().getFullYear() + + const headingYears = arr1.map((item) => { + const age = parseInt(Object.keys(item)[0]) + return currentYear + (age - Math.round(userAge)) + }) + + const getHeadingYear = (year, index) => { + let yearStr + if (index == 0) { + yearStr = year + } else { + yearStr = + language == 'fr' + ? `${apiTrans.detail.lastYearEligible} ${year}` + : `${year} ${apiTrans.detail.lastYearEligible}` + } + return yearStr + } + + return ( +
    + {results.map((innerArray, index) => ( +
    +

    {getHeadingYear(headingYears[index], index)}

    + {innerArray.map((resultObj, innerIndex) => { + if (resultObj != null) { + return ( + + ) + } else { + return <> + } + })} +
    + ))} +
    + ) +} diff --git a/components/ResultsPage/NextSteps.tsx b/components/ResultsPage/NextSteps.tsx index df35fed05..8c30c12eb 100644 --- a/components/ResultsPage/NextSteps.tsx +++ b/components/ResultsPage/NextSteps.tsx @@ -90,26 +90,6 @@ export function getAlwNextSteps( apiTsln: Translations, tsln: WebTranslations ) { - // if (result.eligibility.result === ResultKey.ELIGIBLE) { - // const ifYouApplyText = - // apiTsln.detail.alwIfYouApply + - // `${numberToStringCurrency( - // legalValues.alw.alwIncomeLimit, - // apiTsln._language, - // { rounding: 0 } - // )}.` - - // if (inputAge < 60) { - // nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - // nextStepText.nextStepContent += apiTsln.detail.alwsApply - // if (result.entitlement.result === 0) { - // nextStepText.nextStepContent += ifYouApplyText - // } - // } else if (result.entitlement.result === 0) { - // nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - // nextStepText.nextStepContent += ifYouApplyText - // } - // } const ifYouApplyText = apiTsln.detail.alwIfYouApply + `${numberToStringCurrency( @@ -128,7 +108,19 @@ export function getAlwNextSteps( } else { nextStepText.nextStepContent += ifYouApplyText } - } else { + } else if (result.eligibility.result === ResultKey.INELIGIBLE) { + nextStepText.nextStepContent += `

    ${apiTsln.detail.alw.forIndividuals}

    ` + nextStepText.nextStepContent += `
      +
    • ${apiTsln.detail.alw.age60to64}
    • +
    • ${apiTsln.detail.alw.livingInCanada}
    • +
    • ${apiTsln.detail.alw.spouseReceives}
    • +
    ` + // if ( + // partnerResults.result.eligibility.result === ResultKey.ELIGIBLE || + // partnerResults.result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + // ) { + // nextStepText.nextStepContent += `

    ${apiTsln.detail.alw.forIndividuals}

    ` + // } } return nextStepText @@ -142,26 +134,31 @@ export function getAlwsNextSteps( apiTsln: Translations, tsln: WebTranslations ) { - if (result.eligibility.result === ResultKey.ELIGIBLE) { - const ifYouApplyText = `${ - apiTsln.detail.alwsIfYouApply - }${numberToStringCurrency( + const ifYouApplyText = + apiTsln.detail.alwIfYouApply + + `${numberToStringCurrency( legalValues.alw.afsIncomeLimit, apiTsln._language, { rounding: 0 } )}.` + nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - if (inputAge < 60) { - nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - nextStepText.nextStepContent += `${apiTsln.detail.alwsApply}` - - if (result.entitlement.result === 0) { - nextStepText.nextStepContent += ifYouApplyText - } - } else if (result.entitlement.result === 0) { - nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + if ( + result.eligibility.result === ResultKey.ELIGIBLE || + result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + ) { + if (result.entitlement.result > 0) { + nextStepText.nextStepContent += apiTsln.detail.alwsApply + } else { nextStepText.nextStepContent += ifYouApplyText } + } else if (result.eligibility.result === ResultKey.INELIGIBLE) { + nextStepText.nextStepContent += `

    ${apiTsln.detail.alw.forIndividuals}

    ` + nextStepText.nextStepContent += `
      +
    • ${apiTsln.detail.alw.age60to64}
    • +
    • ${apiTsln.detail.alw.livingInCanada}
    • +
    • ${apiTsln.detail.alw.spouseReceives}
    • +
    ` } return nextStepText diff --git a/components/ResultsPage/SummaryEstimates.tsx b/components/ResultsPage/SummaryEstimates.tsx new file mode 100644 index 000000000..7b4d863ba --- /dev/null +++ b/components/ResultsPage/SummaryEstimates.tsx @@ -0,0 +1,64 @@ +import Image from 'next/image' +import { useRouter } from 'next/router' +import { getTranslations, numberToStringCurrency } from '../../i18n/api' +import { WebTranslations } from '../../i18n/web' +import { Language, SummaryState } from '../../utils/api/definitions/enums' +import { BenefitResult } from '../../utils/api/definitions/types' +import { useTranslation } from '../Hooks' +import { EstimatedTotalItem } from './EstimatedTotalItem' + +export const SummaryEstimates: React.VFC<{ + resultsEligible: BenefitResult[] + entitlementSum: number + state: SummaryState + partner?: boolean + partnerNoOAS: boolean +}> = ({ + resultsEligible, + entitlementSum, + state, + partner = false, + partnerNoOAS, +}) => { + const tsln = useTranslation() + const apiTrans = getTranslations(tsln._language) + + const language = useRouter().locale as Language + + const buildSummaryString = (partner) => { + return `${partner ? apiTrans.detail.yourPartner : ''} ${ + apiTrans.detail.youCouldReceive + } ${numberToStringCurrency(entitlementSum, language)} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } + + // If partner answers "No" to receiving OAS, the amounts should not show + if (partner && partnerNoOAS) { + entitlementSum = 0 + resultsEligible = resultsEligible.map((benefit) => { + return { ...benefit, entitlement: { ...benefit.entitlement, result: 0 } } + }) + } + + return ( + <> +
    +
    + {buildSummaryString(partner)} +
    + +
      + {resultsEligible.map((benefit) => ( + + ))} +
    +
    + + ) +} diff --git a/components/ResultsPage/WillBeEligible.tsx b/components/ResultsPage/WillBeEligible.tsx index 7714d7cc8..ee59e56b6 100644 --- a/components/ResultsPage/WillBeEligible.tsx +++ b/components/ResultsPage/WillBeEligible.tsx @@ -1,3 +1,4 @@ +import { result } from 'lodash' import Image from 'next/image' import { useRouter } from 'next/router' import { getTranslations, numberToStringCurrency } from '../../i18n/api' @@ -51,16 +52,6 @@ export const WillBeEligible: React.VFC<{ return ( <> -

    - - {partner - ? tsln.resultsPage.partnerFutureEligible - : tsln.resultsPage.futureEligible} -

    - {futureResults.map((resultObj, idx) => { const age = Object.keys(resultObj)[0] const onlyOASGIS = Object.keys( @@ -116,6 +107,13 @@ export const WillBeEligible: React.VFC<{ }) } + const headingYear = () => { + console.log(resultObj) + console.log(futureResults) + // console.log(futurePartnerResults) + } + headingYear() + const eligibleTotalAmount = eligible.reduce( (sum, obj) => sum + obj.entitlement.result, 0 diff --git a/components/ResultsPage/index.tsx b/components/ResultsPage/index.tsx index 66372fddb..5c7bc39b4 100644 --- a/components/ResultsPage/index.tsx +++ b/components/ResultsPage/index.tsx @@ -16,11 +16,10 @@ import { import { useTranslation } from '../Hooks' import { BenefitCards } from './BenefitCards' import { EstimatedTotal } from './EstimatedTotal' -import { MayBeEligible } from './MayBeEligible' -import { WillBeEligible } from './WillBeEligible' import { YourAnswers } from './YourAnswers' import { Translations, getTranslations } from '../../i18n/api' import { FieldKey } from '../../utils/api/definitions/fields' +import { FutureSummaryEstimates } from './FutureSummaryEstimates' const getEligibility = ( resultsEligible: BenefitResult[], @@ -82,61 +81,45 @@ const ResultsPage: React.VFC<{ return (
    -
    -
    +
    + {/* Current results eligible */} +
    + {(resultsEligible.length > 0 || + partnerResultsEligible.length > 0) && ( +

    {apiTsln.detail.currentEligible}

    + )} + {resultsEligible.length > 0 && ( + + )} - {resultsEligible.length > 0 && ( - - )} + {isPartnered && partnerResultsEligible.length > 0 && ( + + )} +
    + {/* FUTURE RESULTS SUMMARY */} {futureClientResults && ( - 0} eligibleOAS={ resultsEligible.filter((obj) => obj.benefitKey === 'oas') .length > 0 } - /> - )} - - {!futureClientResults && ( - - )} - - {isPartnered && partnerResultsEligible.length > 0 && ( - - )} - - {futurePartnerResults && ( - 0} - eligibleOAS={ - partnerResultsEligible.filter((obj) => obj.benefitKey === 'oas') - .length > 0 - } - /> - )} - - {isPartnered && !futurePartnerResults && ( - )}
    diff --git a/i18n/api/en.ts b/i18n/api/en.ts index c78a6886d..be32c3e6e 100644 --- a/i18n/api/en.ts +++ b/i18n/api/en.ts @@ -428,6 +428,23 @@ const en: Translations = { "Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you won't receive some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.", oasClawbackNotInCanada: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF} and you live outside Canada, you won’t receive some or all of your Old Age Security pension due to:
    • the {LINK_RECOVERY_TAX}
    • the {LINK_NON_RESIDENT_TAX}
    ', + firstYearEligible: '{FIRST_ELIGIBLE_YEAR}', + lastYearEligible: ' onwards', + currentEligible: 'At this time', + you: 'you', + yourPartner: 'your partner', + youCouldReceive: 'could receive', + youCouldReceiveTo: 'to', + youCouldReceivePerMonth: 'per month:', + youCouldReceiveUntil: 'Until age', + youCouldReceiveFrom: 'From age ', + youCouldStartReceivingAt: 'At ', + youCouldContinueReceiving: 'could continue receiving', + youCouldStartReceiving: 'could start receiving', + yourEstimateIsStill: 'Your estimate is still', + yourEstimateIsStillPartner: `Your partner's estimate is still`, + thisEstimateIsBased: + 'This estimate is based on {YEARS_OF_RESIDENCY} years of residence in Canada.', oas: { eligibleIfIncomeIsLessThan: "You're likely eligible for this benefit if your income is less than {INCOME_LESS_THAN}. If your income is over {OAS_RECOVERY_TAX_CUTOFF}, you may have to pay {LINK_RECOVERY_TAX}.", @@ -478,6 +495,16 @@ const en: Translations = { ifYouAlreadyReceive: 'If you already receive the Guaranteed Income Supplement, you can confirm that your information is up to date in your {MY_SERVICE_CANADA}.', }, + alw: { + forIndividuals: 'This benefit is for individuals:', + age60to64: 'Age 60 to 64', + livingInCanada: 'living in Canada', + spouseReceives: + 'whose spouse or common-law partner receives the Guaranteed Income Supplement', + yourPartnerCanApply: + 'Your partner can apply 6 to 11 months before they become eligible at 65', + }, + alws: {}, }, detailWithHeading: { ifYouDeferYourPension: { diff --git a/i18n/api/fr.ts b/i18n/api/fr.ts index 263c69fc6..65f4fd0d2 100644 --- a/i18n/api/fr.ts +++ b/i18n/api/fr.ts @@ -358,7 +358,7 @@ const fr: Translations = { sinceYouAreSixty: 'Puisque vous avez {CURRENT_AGE} ans, vous pouvez commencer à recevoir vos paiements immédiatement ou attendre encore {WAIT_MONTHS} mois.', futureDeferralOptions: - "Vous pouvez commencer à recevoir vos paiements à {EARLIEST_ELIGIBLE_AGE} ans ou attendre d'avoir 70 ans.", + "Vous pouvez commencer à recevoir vos paiements à 65 ans ou attendre d'avoir 70 ans.", youCanAply: 'Vous pouvez présenter votre demande 11 mois avant la date à laquelle vous aimeriez recevoir votre premier paiement.', onceEnrolled: @@ -437,6 +437,23 @@ const fr: Translations = { "Puisque votre revenu est plus grand que {OAS_RECOVERY_TAX_CUTOFF}, vous ne recevrez pas une partie ou la totalité de votre pension de la Sécurité de la vieillesse en raison de l'{LINK_RECOVERY_TAX}.", oasClawbackNotInCanada: "Puisque votre revenu est plus grand que {OAS_RECOVERY_TAX_CUTOFF} et que vous vivez à l'extérieur du Canada, vous ne recevrez pas une partie ou la totalité de votre pension de la Sécurité de la vieillesse en raison de :
    • l'{LINK_RECOVERY_TAX};
    • l'{LINK_NON_RESIDENT_TAX}.
    ", + firstYearEligible: '{FIRST_ELIGIBLE_YEAR}', + lastYearEligible: 'À partir de ', + currentEligible: 'Présentement', + you: 'vous pourriez', + yourPartner: 'votre conjoint pourrait', + youCouldReceivePerMonth: 'par mois:', + youCouldReceiveTo: 'à', + youCouldReceive: 'recevoir', + youCouldReceiveUntil: 'Jusqu’à', + youCouldReceiveFrom: 'De', + youCouldStartReceivingAt: 'À', + youCouldContinueReceiving: 'continuer de recevoir', + youCouldStartReceiving: 'commencer à recevoir', + yourEstimateIsStill: 'Votre estimation est encore', + yourEstimateIsStillPartner: `L'estimation de votre conjoint est encore`, + thisEstimateIsBased: + 'Cette estimation est basée sur {ENTITLEMENT_AMOUNT_FOR_BENEFIT} années de résidence au Canada.', oas: { eligibleIfIncomeIsLessThan: "Vous êtes probablement admissible à cette prestation si votre revenu est moins que {INCOME_LESS_THAN}. Si votre revenu dépasse {OAS_RECOVERY_TAX_CUTOFF}, vous devrez peut-être payer de l'{LINK_RECOVERY_TAX}.", @@ -488,6 +505,16 @@ const fr: Translations = { ifYouAlreadyReceive: 'Si vous recevez déjà le Supplément de revenu garanti, vous pouvez confirmer que vos renseignements sont à jour dans votre compte {MY_SERVICE_CANADA}.', }, + alw: { + forIndividuals: 'Cette prestation est pour les personnes veuves :', + age60to64: 'âgées de 60 à 64 ans;', + livingInCanada: 'qui vivent au Canada;', + spouseReceives: + 'qui ne se sont pas remariées ou engagées dans une nouvelle union de fait.', + yourPartnerCanApply: + 'Votre conjoint peut faire une demande de 6 à 11 mois avant d’être admissible à 65 ans.', + }, + alws: {}, }, detailWithHeading: { ifYouDeferYourPension: { diff --git a/i18n/api/index.ts b/i18n/api/index.ts index 7c7d26e5d..1e6c4d807 100644 --- a/i18n/api/index.ts +++ b/i18n/api/index.ts @@ -106,6 +106,22 @@ export interface Translations { oasClawbackInCanada: string futureOasClawbackInCanada: string oasClawbackNotInCanada: string + firstYearEligible: string + lastYearEligible: string + currentEligible: string + you: string + yourPartner: string + youCouldReceive: string + youCouldReceiveTo: string + youCouldReceivePerMonth: string + youCouldReceiveUntil: string + youCouldReceiveFrom: string + youCouldStartReceivingAt: string + youCouldContinueReceiving: string + youCouldStartReceiving: string + yourEstimateIsStill: string + yourEstimateIsStillPartner: string + thisEstimateIsBased: string oas: { eligibleIfIncomeIsLessThan: string dependOnYourIncome: string @@ -134,6 +150,14 @@ export interface Translations { ifYouAlreadyApplied: string ifYouAlreadyReceive: string } + alw: { + forIndividuals: string + age60to64: string + livingInCanada: string + spouseReceives: string + yourPartnerCanApply: string + } + alws: {} } detailWithHeading: { ifYouDeferYourPension: { heading: string; text: string } diff --git a/i18n/web/en.ts b/i18n/web/en.ts index 542725752..5bed00c1c 100644 --- a/i18n/web/en.ts +++ b/i18n/web/en.ts @@ -308,9 +308,14 @@ const en: WebTranslations = { 'EC Economics and Industry;Allowances;Benefits;Survivor benefits;Finance;Personal finance;Income;Pensions;Public pensions,PE Persons;Adults;Seniors,So Society and Culture;Old age', }, resultsPage: { + yourMonEstimateHeading: 'Your monthly estimate', + changeInSituation: 'Changes in your situation may impact your results.', + youEstimateMayChange: 'Your estimate may change over time based on:', + basedYourAge: 'your age', + basedYourPartner: 'the benefits your partner receives', header: 'Table of estimated monthly amounts', general: - 'The following is only an estimate of your eligibility and monthly payments based on current rates. Amounts may increase with the cost of living. Changes in your circumstances may also impact your results.', + 'The following is only an estimate of your eligibility and monthly payments based on current rates. Amounts may increase with the cost of living.', onThisPage: 'On this page', tableHeader1: 'Benefit', tableHeader2: 'Estimated monthly amount (CAD)', diff --git a/i18n/web/fr.ts b/i18n/web/fr.ts index ea2bd4ad7..b9ad400e2 100644 --- a/i18n/web/fr.ts +++ b/i18n/web/fr.ts @@ -313,8 +313,15 @@ const fr: WebTranslations = { homeSubject: `EC Économie et industrie;Allocation;Avantages sociaux;Prestation au survivant;Finances;Finances personnelles;Revenu;Pension;Pension publique,PE Personnes;Adulte;Aîné,SO Société et culture;Vieillesse`, }, resultsPage: { + yourMonEstimateHeading: 'Votre estimation mensuelle', + changeInSituation: + 'Si votre situation change, vos résultats pourraient changer.', + youEstimateMayChange: + 'Votre estimation peut changer au fil du temps en fonction :', + basedYourAge: 'de votre âge;', + basedYourPartner: 'des prestations que votre conjoint reçoit.', header: "Tableau des résultats d'estimation", - general: `Les résultats suivants ne sont qu'une estimation de votre admissibilité et de vos paiements mensuels basée sur les montants actuels. Ceux-ci peuvent augmenter avec le coût de la vie. Des changements dans votre situation pourraient aussi modifier vos résultats`, + general: `Les résultats suivants ne sont qu'une estimation de votre admissibilité et de vos paiements mensuels basée sur les montants actuels. Ceux-ci peuvent augmenter avec le coût de la vie.`, onThisPage: 'Sur cette page', tableHeader1: 'Prestations', tableHeader2: 'Montant mensuel estimé (CAD)', diff --git a/i18n/web/index.ts b/i18n/web/index.ts index a00616aae..f6c3041ec 100644 --- a/i18n/web/index.ts +++ b/i18n/web/index.ts @@ -216,6 +216,12 @@ export type WebTranslations = { } //results page resultsPage: { + yourMonEstimateHeading: string + changeInSituation: string + youEstimateMayChange: string + basedYourAge: string + basedYourPartner: string + header: string general: string onThisPage: string diff --git a/utils/api/benefits/_base.ts b/utils/api/benefits/_base.ts index 03d474994..844126219 100644 --- a/utils/api/benefits/_base.ts +++ b/utils/api/benefits/_base.ts @@ -67,6 +67,8 @@ export abstract class BaseBenefit { return this.eligibility.result === ResultKey.ELIGIBLE } + // Remove This code + /** * The main text content that will always be visible within each benefit's card. */ @@ -93,7 +95,7 @@ export abstract class BaseBenefit { this.eligibility.result === ResultKey.ELIGIBLE && this.entitlement.result > 0 ) { - text += ` ${this.translations.detail.expectToReceive}` + // text += ` ${this.translations.detail.expectToReceive}` } if ( @@ -103,7 +105,7 @@ export abstract class BaseBenefit { ) { text += `
    ${this.translations.detail.autoEnrollTrue}
    ` } - + text = null return text } diff --git a/utils/api/benefits/alwBenefit.ts b/utils/api/benefits/alwBenefit.ts index 8e37f58a6..9a88d823a 100644 --- a/utils/api/benefits/alwBenefit.ts +++ b/utils/api/benefits/alwBenefit.ts @@ -282,51 +282,6 @@ export class AlwBenefit extends BaseBenefit { return false } - protected getCardText(): string { - let text = this.eligibility.detail - - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - this.entitlement.result > 0 - ) { - text += this.future - ? ` ${this.translations.detail.futureExpectToReceive}` - : ` ${this.translations.detail.expectToReceive}` - } - return text - } - - protected getCardCollapsedText(): CardCollapsedText[] { - let cardCollapsedText = super.getCardCollapsedText() - - if ( - this.eligibility.result !== ResultKey.ELIGIBLE && - this.eligibility.result !== ResultKey.INCOME_DEPENDENT - ) - return cardCollapsedText - - // partner is eligible, IF income was not provided the result = 0 - // when IF income > 0 AND invSeparated = true the amount is incorrectly calculated - // the correct amount is on the benefitHandler. - if (this.partner) { - if (this.entitlement.result > 0) { - if (this.eligibility.result !== ResultKey.INCOME_DEPENDENT) { - if (!this.input.invSeparated) { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerEligible - ) - } - } else { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerDependOnYourIncome - ) - } - } - } - - return cardCollapsedText - } - protected getCardLinks(): LinkWithAction[] { const links: LinkWithAction[] = [] if ( diff --git a/utils/api/benefits/gisBenefit.ts b/utils/api/benefits/gisBenefit.ts index c937e99f0..e1e29f03f 100644 --- a/utils/api/benefits/gisBenefit.ts +++ b/utils/api/benefits/gisBenefit.ts @@ -267,48 +267,6 @@ export class GisBenefit extends BaseBenefit { return links } - protected getCardText(): string { - /** - * The following IF block is a copy from benefitHandler.translateResults, - * the issue is that cardDetail object is updated only once if undefined, and could have the wrong information. - * overwrite eligibility.detail and autoEnrollment when entitlement.type = none. - */ - - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - this.entitlement.type === EntitlementResultType.NONE - ) { - //this.eligibility.result = ResultKey.INELIGIBLE - this.eligibility.reason = ResultReason.INCOME - this.eligibility.detail = this.future - ? this.translations.detail.gis.futureEligibleIncomeTooHigh - : this.translations.detail.gis.incomeTooHigh - this.entitlement.autoEnrollment = this.getAutoEnrollment() - } - - // another hack, to avoid adding message expectToReceive - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - this.eligibility.reason === ResultReason.INCOME && - this.entitlement.result > 0 - ) { - return this.eligibility.detail - } - - let text = this.eligibility.detail - - if ( - this.eligibility.result === ResultKey.ELIGIBLE && - this.entitlement.result > 0 - ) { - text += this.future - ? ` ${this.translations.detail.futureExpectToReceive}` - : ` ${this.translations.detail.expectToReceive}` - } - - return text - } - public updateCollapsedText(): CardCollapsedText[] { return this.getCardCollapsedText() } diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index d6c096228..6c59e3321 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -491,134 +491,6 @@ export class OasBenefit extends BaseBenefit { return cardCollapsedText } - protected getCardText(): string { - // // overwrite eligibility detail if income too high - // if ( - // this.eligibility.result === ResultKey.ELIGIBLE && - // this.entitlement.type === EntitlementResultType.NONE - // ) { - // //this.eligibility.result = ResultKey.INELIGIBLE - // this.eligibility.reason = ResultReason.INCOME - // this.eligibility.detail = this.future - // ? this.translations.detail.futureEligibleIncomeTooHigh - // : this.translations.detail.eligibleIncomeTooHigh - // this.entitlement.autoEnrollment = this.getAutoEnrollment() - // } - - // // INTRO 1 - general eligibility already in the detail - // let text = this.eligibility.detail - - // // INTRO 2 - "expect to receive" variation - // if ( - // this.eligibility.result === ResultKey.ELIGIBLE && - // this.eligibility.reason !== ResultReason.INCOME && - // this.entitlement.result > 0 - // ) { - // if (this.future) { - // if (!this.input.livedOnlyInCanada) { - // text += ` ${this.translations.detail.futureExpectToReceivePartial1}` - // if ( - // this.formAge != this.input.age && - // this.formYearsInCanada <= 40 && - // this.formYearsInCanada != this.input.yearsInCanadaSince18 - // ) { - // text += `${this.translations.detail.futureExpectToReceivePartial2}` - // } - // text += ` ${this.translations.detail.futureExpectToReceivePartial3}` - // } else { - // text += ` ${this.translations.detail.futureExpectToReceive}` - // } - // } else { - // text += ` ${this.translations.detail.expectToReceive}` - // } - // } - - // // special case - // if (this.eligibility.result === ResultKey.INCOME_DEPENDENT) { - // text += `

    ${this.translations.detail.oas.dependOnYourIncome}

    ` - // } - - // // special case - // if ( - // this.eligibility.result === ResultKey.INELIGIBLE && - // this.eligibility.reason === ResultReason.AGE_YOUNG - // ) { - // text += this.translations.nextStepTitle - // //text += `

    ${this.translations.detail.oas.youShouldReceiveLetter}

    ` - // text += `

    ${this.translations.detail.oas.youShouldHaveReceivedLetter}

    ` - // } - - // if (this.eligibility.reason !== ResultReason.INCOME) { - // const clawbackValue = this.entitlement.clawback - - // if (!this.partner && this.input.livingCountry.canada) { - // text += - // clawbackValue > 0 - // ? this.future - // ? `
    ${this.translations.detail.futureOasClawbackInCanada}
    ` - // : `
    ${this.translations.detail.oasClawbackInCanada}
    ` - // : '' - // } else { - // text += - // clawbackValue > 0 - // ? `
    ${this.translations.detail.oasClawbackNotInCanada}
    ` - // : '' - // } - // } - - // // RETROACTIVE PAY - // if ( - // !this.future && - // this.eligibility.result === ResultKey.ELIGIBLE && - // !this.partner && - // (!this.input.receiveOAS || this.deferral) && - // (this.input.age > 70 || this.inputAge > 70) && - // this.eligibility.reason !== ResultReason.INCOME - // ) { - // // if (this.inputAge !== this.input.age) { - // // Retroactive pay - // text += `

    ${this.translations.detail.retroactivePay}

    ` - // text += `

    ${this.translations.detail.oas.receivePayment}

    ` - // // } - // } - - // // DEFERRAL - // if ( - // this.eligibility.result === ResultKey.ELIGIBLE && - // !this.partner && - // (!this.input.receiveOAS || this.deferral) && - // this.input.age < 70 && - // this.inputAge < 70 - // ) { - // // your Deferral Options - - // // if income too high - // if (this.eligibility.reason === ResultReason.INCOME) { - // if (!this.future) { - // text += `

    ${this.translations.detail.yourDeferralOptions}

    ` - // text += this.translations.detail.delayMonths - // } - // } - - // // normal case - // if (this.entitlement.result > 0) { - // text += `

    ${this.translations.detail.yourDeferralOptions}

    ` - // if (this.future) { - // // can also check if this.entitlement.clawback === 0 - // text += this.translations.detail.futureDeferralOptions - // } else { - // text += this.translations.detail.sinceYouAreSixty - - // if (!this.deferral && this.input.yearsInCanadaSince18 < 40) { - // text += `

    ${this.translations.detail.oas.chooseToDefer}

    ` - // } - // } - // } - // } - let text = null - return text - } - protected getCardLinks(): LinkWithAction[] { const links: LinkWithAction[] = [] if ( From 590d66ebe070df08d068f5ccd33d93f197535ac4 Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Tue, 25 Jun 2024 08:11:11 -0400 Subject: [PATCH 03/12] Fixed Summary Estimates headers --- components/ResultsPage/EstimatedTotal.tsx | 59 +++- components/ResultsPage/Estimation.tsx | 323 ++++++++++++++++++ .../ResultsPage/FutureBenefitEstimate.tsx | 5 +- .../ResultsPage/FutureSummaryEstimates.tsx | 8 +- components/ResultsPage/SummaryEstimates.tsx | 191 ++++++++--- components/ResultsPage/index.tsx | 144 +++++--- i18n/api/fr.ts | 2 +- 7 files changed, 640 insertions(+), 92 deletions(-) create mode 100644 components/ResultsPage/Estimation.tsx diff --git a/components/ResultsPage/EstimatedTotal.tsx b/components/ResultsPage/EstimatedTotal.tsx index e4ed49147..9e76f1f7a 100644 --- a/components/ResultsPage/EstimatedTotal.tsx +++ b/components/ResultsPage/EstimatedTotal.tsx @@ -1,10 +1,18 @@ import Image from 'next/image' import { useRouter } from 'next/router' +import { Summary } from 'prom-client' import { getTranslations, numberToStringCurrency } from '../../i18n/api' import { WebTranslations } from '../../i18n/web' -import { Language, SummaryState } from '../../utils/api/definitions/enums' +import { + BenefitKey, + Language, + ResultKey, + SummaryState, +} from '../../utils/api/definitions/enums' import { BenefitResult } from '../../utils/api/definitions/types' import { useTranslation } from '../Hooks' +import { CustomCollapse } from './CustomCollapse' +import { DeferralTable } from './DeferralTable' import { EstimatedTotalItem } from './EstimatedTotalItem' export const EstimatedTotal: React.VFC<{ @@ -34,11 +42,21 @@ export const EstimatedTotal: React.VFC<{ } // If partner answers "No" to receiving OAS, the amounts should not show - if (partner && partnerNoOAS) { - entitlementSum = 0 - resultsEligible = resultsEligible.map((benefit) => { - return { ...benefit, entitlement: { ...benefit.entitlement, result: 0 } } - }) + // if (partner && partnerNoOAS) { + // entitlementSum = 0 + // resultsEligible = resultsEligible.map((benefit) => { + // return { ...benefit, entitlement: { ...benefit.entitlement, result: 0 } } + // }) + // } + + const getDeferralTable = (benefitKey, result, future): any => { + console.log(result.cardDetail.meta?.tableData) + return benefitKey === BenefitKey.oas && + result.eligibility.result === ResultKey.ELIGIBLE && + result.entitlement.result > 0 && + result.cardDetail.meta?.tableData !== null ? ( + + ) : null } return ( @@ -54,10 +72,37 @@ export const EstimatedTotal: React.VFC<{ key={benefit.benefitKey} heading={apiTrans.benefit[benefit.benefitKey]} result={benefit} - displayAmount={partner && partnerNoOAS ? false : true} + displayAmount={true} /> ))} + {/* {resultsEligible.map((benefit) => { + const collapsedDetails = benefit.cardDetail?.collapsedText + + return ( + <> + {collapsedDetails && + collapsedDetails.map((detail, index) => ( + +

    + {getDeferralTable(benefit.benefitKey, benefit, true) && + // detail.heading === + // apiTrans.detailWithHeading.yourDeferralOptions + // .heading && + getDeferralTable(benefit.benefitKey, benefit, true)} + + ))} + + ) + })} */}

    ) diff --git a/components/ResultsPage/Estimation.tsx b/components/ResultsPage/Estimation.tsx new file mode 100644 index 000000000..ffb34db9a --- /dev/null +++ b/components/ResultsPage/Estimation.tsx @@ -0,0 +1,323 @@ +import Image from 'next/image' +import { useRouter } from 'next/router' +import { Summary } from 'prom-client' +import { getTranslations, numberToStringCurrency } from '../../i18n/api' +import { WebTranslations } from '../../i18n/web' +import { + BenefitKey, + Language, + ResultKey, + SummaryState, +} from '../../utils/api/definitions/enums' +import { + BenefitResult, + BenefitResultsObject, +} from '../../utils/api/definitions/types' +import { useTranslation } from '../Hooks' +import { CustomCollapse } from './CustomCollapse' +import { DeferralTable } from './DeferralTable' +import { EstimatedTotalItem } from './EstimatedTotalItem' + +export const Estimation: React.VFC<{ + partner + resultObject + resultArray + age +}> = ({ partner, resultObject, resultArray, age }) => { + const tsln = useTranslation() + const apiTrans = getTranslations(tsln._language) + age = Math.round(age) + + const language = useRouter().locale as Language + + const benefitAge = Object.keys(resultObject)[0] + const benefitType = Object.keys(resultObject[Object.keys(resultObject)[0]]) + + let estimateIsSame = false + + const benefitObject: BenefitResultsObject = + resultObject[Object.keys(resultObject)[0]] + + const resultsArray: BenefitResult[] = Object.keys( + resultObject[benefitAge] + ).map((value) => resultObject[benefitAge][value]) + + let eligible = resultsArray.filter( + (result) => + result.eligibility?.result === ResultKey.ELIGIBLE || + result.eligibility?.result === ResultKey.INCOME_DEPENDENT + ) + + const eligibleTotalAmount = eligible.reduce( + (sum, obj) => sum + obj.entitlement.result, + 0 + ) + + let benefitResultArray: BenefitResult[] = [] + for (const prop in resultArray) { + if (prop) { + if (resultArray[prop]) { + benefitResultArray.push( + resultArray[prop][Object.keys(resultArray[prop])[0]] + ) + } + } + } + + const isFirstOasGis = () => { + let isFirst = false + // const resultArray = + + for (let i = 0; i < benefitResultArray.length; i++) { + const obj = benefitResultArray[i] + if ( + Object.keys(obj[Object.keys(obj)[0]]).includes('oas') && + Object.keys(obj[Object.keys(obj)[0]]).includes('gis') + ) { + console.log(obj) + console.log(benefitObject) + // Check if it's the same object + if (JSON.stringify(obj) === JSON.stringify(resultObject)) { + isFirst = true + } + break + } + } + return isFirst + } + + const isLastOasGis = () => { + let isLast = false + + for (let i = benefitResultArray.length - 1; i >= 0; i--) { + const obj = benefitResultArray[i] + if ( + Object.keys(obj[Object.keys(obj)[0]]).includes('oas') && + Object.keys(obj[Object.keys(obj)[0]]).includes('gis') + ) { + // Check if it's the same object + if (JSON.stringify(obj) === JSON.stringify(resultObject)) { + isLast = true + } + break + } + } + + return isLast + } + + //BUILD THE SUMMARY STRINGS FOR EACH BENFIT + const buildSummaryString = () => { + let text = '' + + console.log('age') + console.log(age) + console.log(benefitAge) + age = benefitAge == '0' ? age : benefitAge + let isPartnerStr = partner + ? apiTrans.detail.yourPartner + : apiTrans.detail.you + + const firstOasGis = isFirstOasGis() + const lastOasGis = isLastOasGis() + + const eligibleAmt = numberToStringCurrency(eligibleTotalAmount, language) + + const arrayofben = benefitResultArray + + //ALW & ALWS + if (!benefitType.includes('oas') || !benefitType.includes('gis')) { + //CURRENT ELIGIBLE + if (benefitAge == '0') { + text = `${apiTrans.detail.youCouldReceiveUntil} ${age}${ + language == 'fr' ? ' ans' : '' + },` + } + //FUTURE ELIGIBLE + else { + text = `${apiTrans.detail.youCouldReceiveFrom} ${age} ${ + apiTrans.detail.youCouldReceiveTo + } 65${language == 'fr' ? ' ans' : ''},` + } + text += ` ${isPartnerStr} ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //OAS AND GIS BENEFIT + else { + //FIRST OAS AND GIS + if (firstOasGis) { + //IS CURRENTLY AVAILABLE + if (benefitAge == '0') { + //FIRST AND LAST + //I1 + if (lastOasGis) { + text += `${ + partner ? apiTrans.detail.yourPartner : apiTrans.detail.you + } ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } + //FIRST NOT LAST + else { + const nextBenefitResult = + arrayofben[arrayofben.indexOf(resultObject) + 1] + console.log('next one', nextBenefitResult) + + const nextBenefitTotal = + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] + .entitlement.result + + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['gis'] + .entitlement.result + const nextBenefitAge = Object.keys(nextBenefitResult)[0] + + //IS NEXT RESULT THE SAME + //I1 & I2 + if (eligibleTotalAmount !== nextBenefitTotal) { + text = `${ + apiTrans.detail.youCouldReceiveUntil + } ${nextBenefitAge}${language == 'fr' ? ' ans' : ''}, ${ + partner ? apiTrans.detail.yourPartner : apiTrans.detail.you + } ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } + text = `${ + partner ? apiTrans.detail.yourPartner : apiTrans.detail.you + } ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } + } + + //FUTURE + else { + //LAST ESTIMATE + if (lastOasGis) { + //I5 + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${partner ? apiTrans.detail.yourPartner : apiTrans.detail.you} ${ + apiTrans.detail.youCouldStartReceiving + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //NOT LAST + else { + const nextBenefitResult = + arrayofben[arrayofben.indexOf(resultObject) + 1] + console.log('next one', nextBenefitResult) + + const nextBenefitTotal = + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] + .entitlement.result + + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['gis'] + .entitlement.result + const nextBenefitAge = Object.keys(nextBenefitResult)[0] + + //NEXT SAME + if (eligibleTotalAmount == nextBenefitTotal) { + text = `${apiTrans.detail.youCouldStartReceivingAt} ${age}${ + language == 'fr' ? ' ans' : '' + }, ${ + partner ? apiTrans.detail.yourPartner : apiTrans.detail.you + } ${apiTrans.detail.youCouldStartReceiving} ${eligibleAmt} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } + //NEXT NOT SAME + else { + text = `${apiTrans.detail.youCouldReceiveFrom} ${age} ${ + apiTrans.detail.youCouldReceiveTo + } ${Object.keys(nextBenefitResult)[0]}${ + language == 'fr' ? ' ans' : '' + },` + text += ` ${isPartnerStr} ${apiTrans.detail.youCouldReceive} ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + } + } + } + //NOT FIRST + else { + const previousBenefitResult = + arrayofben[arrayofben.indexOf(resultObject) - 1] + console.log('previous one', previousBenefitResult) + const previousBenefitTotal = + previousBenefitResult[Object.keys(previousBenefitResult)[0]]['oas'] + .entitlement.result + + previousBenefitResult[Object.keys(previousBenefitResult)[0]]['gis'] + .entitlement.result + + //PREVIOUS THE SAME + if (previousBenefitTotal === eligibleTotalAmount) { + estimateIsSame = true + text = `${ + partner + ? apiTrans.detail.yourEstimateIsStillPartner + : apiTrans.detail.yourEstimateIsStill + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + //PREVIOUS NOT THE SAME + else { + //IS LAST + if (lastOasGis) { + text = `${apiTrans.detail.youCouldStartReceivingAt} ${benefitAge}${ + language == 'fr' ? ' ans' : '' + }, ${partner ? apiTrans.detail.yourPartner : apiTrans.detail.you} ${ + apiTrans.detail.youCouldContinueReceiving + } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } else { + const nextBenefitResult = + arrayofben[arrayofben.indexOf(resultObject) + 1] + console.log('next one', nextBenefitResult) + + const nextBenefitTotal = + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] + .entitlement.result + + nextBenefitResult[Object.keys(nextBenefitResult)[0]]['gis'] + .entitlement.result + const nextBenefitAge = Object.keys(nextBenefitResult)[0] + + if (eligibleTotalAmount == nextBenefitTotal) { + text = `${ + apiTrans.detail.youCouldStartReceivingAt + } ${benefitAge}${language == 'fr' ? ' ans' : ''}, ${ + partner ? apiTrans.detail.yourPartner : apiTrans.detail.you + } ${apiTrans.detail.youCouldContinueReceiving} ${eligibleAmt} ${ + apiTrans.detail.youCouldReceivePerMonth + }` + } else { + text = `${apiTrans.detail.youCouldReceiveFrom} ${age} ${ + apiTrans.detail.youCouldReceiveTo + } ${nextBenefitAge}${language == 'fr' ? ' ans' : ''},` + text += ` ${isPartnerStr} ${apiTrans.detail.continueReceiving} ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` + } + } + } + } + } + + return text + } + + return ( +
    + +

    + + +

      + {!estimateIsSame && + eligible.map((benefit, index) => ( + + ))} +
    +
    + ) +} diff --git a/components/ResultsPage/FutureBenefitEstimate.tsx b/components/ResultsPage/FutureBenefitEstimate.tsx index db39bafb0..64fa55708 100644 --- a/components/ResultsPage/FutureBenefitEstimate.tsx +++ b/components/ResultsPage/FutureBenefitEstimate.tsx @@ -58,12 +58,15 @@ export const FutureBenefitEstimate: React.VFC<{ (value) => resultObj[age][value] ) + console.log(resultsArray) let eligible = resultsArray.filter( (result) => result.eligibility?.result === ResultKey.ELIGIBLE || result.eligibility?.result === ResultKey.INCOME_DEPENDENT ) + console.log(eligible) + // If partner answers "No" to receiving OAS, the amounts should not show if (partner && partnerNoOAS) { eligible = eligible.map((benefit) => { @@ -152,7 +155,7 @@ export const FutureBenefitEstimate: React.VFC<{ else { const firstOasGis = isFirstOasGis(partner, resultObj) const lastOasGis = isLastOasGis(partner, resultObj) - // console.log(resultObj) + console.log(resultObj) // console.log(futureBenefits) const arrayofben = partner ? futurePartnerBenefits : futureBenefits diff --git a/components/ResultsPage/FutureSummaryEstimates.tsx b/components/ResultsPage/FutureSummaryEstimates.tsx index 9717caa2c..16af8ba39 100644 --- a/components/ResultsPage/FutureSummaryEstimates.tsx +++ b/components/ResultsPage/FutureSummaryEstimates.tsx @@ -33,7 +33,7 @@ export const FutureSummaryEstimates: React.VFC<{ let arr2 futurePartnerResults = futurePartnerResults ? futurePartnerResults : [] - if (futureResults.length < futurePartnerResults) { + if (futureResults.length < futurePartnerResults.length) { partner = true arr1 = futurePartnerResults arr2 = futureResults @@ -42,10 +42,15 @@ export const FutureSummaryEstimates: React.VFC<{ arr2 = futurePartnerResults } + console.log(futureResults) + console.log(futurePartnerResults) + const results = arr1.map((obj1, index) => [ obj1, arr2[index] ? arr2[index] : null, ]) + + console.log(results) const currentYear = new Date().getFullYear() const headingYears = arr1.map((item) => { @@ -72,6 +77,7 @@ export const FutureSummaryEstimates: React.VFC<{

    {getHeadingYear(headingYears[index], index)}

    {innerArray.map((resultObj, innerIndex) => { + console.log(resultObj) if (resultObj != null) { return ( = ({ - resultsEligible, - entitlementSum, - state, - partner = false, - partnerNoOAS, -}) => { + headings + userResults + partnerResults + userAge + partnerAge +}> = ({ headings, userResults, partnerResults, userAge, partnerAge }) => { const tsln = useTranslation() const apiTrans = getTranslations(tsln._language) const language = useRouter().locale as Language - const buildSummaryString = (partner) => { - return `${partner ? apiTrans.detail.yourPartner : ''} ${ - apiTrans.detail.youCouldReceive - } ${numberToStringCurrency(entitlementSum, language)} ${ - apiTrans.detail.youCouldReceivePerMonth - }` - } + const currentYear = new Date().getFullYear() - // If partner answers "No" to receiving OAS, the amounts should not show - if (partner && partnerNoOAS) { - entitlementSum = 0 - resultsEligible = resultsEligible.map((benefit) => { - return { ...benefit, entitlement: { ...benefit.entitlement, result: 0 } } - }) + const getDeferralTable = (benefitKey, result, future): any => { + console.log(result.cardDetail.meta?.tableData) + return benefitKey === BenefitKey.oas && + result.eligibility.result === ResultKey.ELIGIBLE && + result.entitlement.result > 0 && + result.cardDetail.meta?.tableData !== null ? ( + + ) : null } return ( <> -
    -
    - {buildSummaryString(partner)} -
    - -
      - {resultsEligible.map((benefit) => ( - - ))} -
    -
    + {headings.map((year, index) => { + const userResult = userResults + ? userResults.some((obj) => year in obj) + : null + + const partnerResult = partnerResults + ? partnerResults.some((obj) => year in obj) + : null + let heading + + if (year == currentYear) { + heading = apiTrans.detail.currentEligible + } else if (index < headings.length - 1) { + heading = year + } else { + heading = + language == 'fr' + ? `${apiTrans.detail.lastYearEligible} ${year}` + : `${year} ${apiTrans.detail.lastYearEligible}` + } + + const userObj = userResult + ? userResults.find((obj) => year in obj) + : null + + const partnerObj = partnerResult + ? partnerResults.find((obj) => year in obj) + : null + + const userResultObject = userObj + ? userObj[Object.keys(userObj)[0]] + : null + + const partnerResultObject = partnerObj + ? partnerObj[Object.keys(partnerObj)[0]] + : null + + let eligible + if (userResultObject) { + const benefitAge = Object.keys(userResultObject)[0] + + const resultsArray: BenefitResult[] = Object.keys( + userResultObject[benefitAge] + ).map((value) => userResultObject[benefitAge][value]) + + eligible = resultsArray.filter( + (result) => + result.eligibility?.result === ResultKey.ELIGIBLE || + result.eligibility?.result === ResultKey.INCOME_DEPENDENT + ) + } + + return ( +
    +

    + {heading} +

    +
    + {userResult && ( + + )} + + {partnerResult && ( + + )} + + {eligible && + eligible.map((benefit) => { + const collapsedDetails = benefit.cardDetail?.collapsedText + + return ( + <> + {collapsedDetails && + collapsedDetails.map((detail, index) => ( + +

    + {getDeferralTable( + benefit.benefitKey, + benefit, + true + ) && + // detail.heading === + // apiTrans.detailWithHeading.yourDeferralOptions + // .heading && + getDeferralTable( + benefit.benefitKey, + benefit, + true + )} + + ))} + + ) + })} +

    + {headings.length > 1 && + index < year.length && + index != headings.length - 1 &&
    } +
    + ) + })} ) } diff --git a/components/ResultsPage/index.tsx b/components/ResultsPage/index.tsx index 5c7bc39b4..71ba97306 100644 --- a/components/ResultsPage/index.tsx +++ b/components/ResultsPage/index.tsx @@ -20,6 +20,7 @@ import { YourAnswers } from './YourAnswers' import { Translations, getTranslations } from '../../i18n/api' import { FieldKey } from '../../utils/api/definitions/fields' import { FutureSummaryEstimates } from './FutureSummaryEstimates' +import { SummaryEstimates } from './SummaryEstimates' const getEligibility = ( resultsEligible: BenefitResult[], @@ -51,6 +52,11 @@ const ResultsPage: React.VFC<{ inputs.find((input) => input.key === FieldKey.MARITAL_STATUS)['value'] === MaritalStatus.PARTNERED + const userAge = inputs.find((input) => input.key === FieldKey.AGE)['value'] + const partnerAge = isPartnered + ? inputs.find((input) => input.key === FieldKey.PARTNER_AGE)['value'] + : null + const partnerNoOAS = inputs.find((input) => input.key === FieldKey.PARTNER_BENEFIT_STATUS)?.[ 'value' @@ -78,49 +84,109 @@ const ResultsPage: React.VFC<{ result.eligibility?.result === ResultKey.INCOME_DEPENDENT ) + const userResultObject = + resultsEligible.length > 0 + ? resultsEligible.reduce((acc, item) => { + // Use the value of benefitKey as the key in the resulting object + acc[item.benefitKey] = item + return acc + }, {}) + : null + + const partnerResultObject = + partnerResultsEligible.length > 0 + ? partnerResultsEligible.reduce((acc, item) => { + // Use the value of benefitKey as the key in the resulting object + acc[item.benefitKey] = item + return acc + }, {}) + : null + + let userObj = {} + // userObj['0'] = userResultObject + if (userResultObject) { + userObj['0'] = userResultObject + } else { + userObj = null + } + const userArr = userObj ? [userObj] : [] + + let partnerObj = {} + // partnerObj['0'] = partnerResultObject + if (partnerResultObject) { + partnerObj['0'] = partnerResultObject + } else { + partnerObj = null + } + const partnerArr = partnerObj ? [partnerObj] : [] + + const userArrNew = userArr.concat(futureClientResults) + const partnerArrNew = partnerArr.concat(futurePartnerResults) + + const currentYear = new Date().getFullYear() + + const newestUser = userArrNew.map((item, index) => { + if (item) { + const age = Number(Object.keys(item)[0]) + const headingYear = currentYear + (age - Math.round(Number(userAge))) + let key + if (age == 0) { + key = currentYear + } else { + key = headingYear + } + return { [key]: item } + } + }) + + const newestPartner = isPartnered + ? partnerArrNew.map((item, index) => { + if (item) { + const age = Number(Object.keys(item)[0]) + const headingYear = + currentYear + (age - Math.round(Number(partnerAge))) + // console.log(headingYear) + let key + if (age == 0) { + key = currentYear + } else { + key = headingYear + } + return { [key]: item } + } + }) + : null + + const userKeys = newestUser.flatMap((obj) => { + // Check if the object is not null or undefined before extracting keys + return obj ? Object.keys(obj) : [] + }) + + const partnerKeys = isPartnered + ? newestPartner.flatMap((obj) => { + // Check if the object is not null or undefined before extracting keys + return obj ? Object.keys(obj) : [] + }) + : [] + + const arr1 = userKeys.length > partnerKeys.length ? userKeys : partnerKeys + const arr2 = arr1 == partnerKeys ? userKeys : partnerKeys + + const headings = [...new Set([...arr1, ...arr2])] + return (
    - {/* Current results eligible */} -
    - {(resultsEligible.length > 0 || - partnerResultsEligible.length > 0) && ( -

    {apiTsln.detail.currentEligible}

    - )} - {resultsEligible.length > 0 && ( - - )} - - {isPartnered && partnerResultsEligible.length > 0 && ( - - )} -
    - - {/* FUTURE RESULTS SUMMARY */} - {futureClientResults && ( - 0} - eligibleOAS={ - resultsEligible.filter((obj) => obj.benefitKey === 'oas') - .length > 0 - } - userAge={inputs[0].value} - /> + {/* Summary Estimates section */} + {headings && ( + )}
    diff --git a/i18n/api/fr.ts b/i18n/api/fr.ts index 65f4fd0d2..96a70e90e 100644 --- a/i18n/api/fr.ts +++ b/i18n/api/fr.ts @@ -385,7 +385,7 @@ const fr: Translations = { conditional: 'Vous pourriez être admissible à cette prestation. Nous vous invitons à communiquer avec Service Canada pour obtenir une meilleure évaluation.', partnerContinues: 'Si votre conjoint continue de recevoir à', - continueReceiving: 'Si vous continuez de recevoir à', + continueReceiving: 'continuez de recevoir à', dependingOnAgreement: "Vous pourriez être admissible à cette prestation, selon l'accord que le Canada a avec ce pays. Nous vous invitons à communiquer avec Service Canada pour obtenir une meilleure évaluation.", dependingOnAgreementWhen60: From 67ae8cc819e80b49c98742ac52ec1b03b4ef18ff Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Fri, 5 Jul 2024 12:01:07 -0400 Subject: [PATCH 04/12] Remove unused files and refs, clean up, remove console logs, add images --- components/Forms/Button.tsx | 6 +- components/ResultsPage/BenefitCard.tsx | 34 +- components/ResultsPage/CustomCollapse.tsx | 8 +- components/ResultsPage/EstimatedTotal.tsx | 109 ------- components/ResultsPage/EstimatedTotalItem.tsx | 42 ++- components/ResultsPage/Estimation.tsx | 27 +- .../ResultsPage/FutureBenefitEstimate.tsx | 297 ------------------ .../ResultsPage/FutureSummaryEstimates.tsx | 98 ------ components/ResultsPage/Intro.tsx | 40 +++ components/ResultsPage/Modal.tsx | 60 ++++ components/ResultsPage/NextSteps.tsx | 1 + components/ResultsPage/SummaryEstimates.tsx | 120 ++++--- components/ResultsPage/index.tsx | 46 ++- i18n/api/en.ts | 65 ++++ i18n/api/fr.ts | 61 ++++ i18n/api/index.ts | 24 ++ i18n/web/en.ts | 5 +- i18n/web/fr.ts | 8 +- i18n/web/index.ts | 4 +- public/moreInfo.png | Bin 0 -> 807 bytes public/openNewTabWhite.svg | 30 ++ utils/api/benefitHandler.ts | 15 +- utils/api/benefits/alwBenefit.ts | 31 ++ utils/api/benefits/gisBenefit.ts | 77 +++-- utils/api/benefits/oasBenefit.ts | 150 ++++++--- 25 files changed, 664 insertions(+), 694 deletions(-) delete mode 100644 components/ResultsPage/EstimatedTotal.tsx delete mode 100644 components/ResultsPage/FutureBenefitEstimate.tsx delete mode 100644 components/ResultsPage/FutureSummaryEstimates.tsx create mode 100644 components/ResultsPage/Intro.tsx create mode 100644 components/ResultsPage/Modal.tsx create mode 100644 public/moreInfo.png create mode 100644 public/openNewTabWhite.svg diff --git a/components/Forms/Button.tsx b/components/Forms/Button.tsx index ad1bf8c99..67db76a21 100644 --- a/components/Forms/Button.tsx +++ b/components/Forms/Button.tsx @@ -14,6 +14,7 @@ interface ButtonProps { disabled?: boolean ariaLabel?: string attributes?: any + alt?: string } type ButtonType = 'submit' | 'reset' | 'button' @@ -40,6 +41,7 @@ export const Button: React.FC = ({ disabled, ariaLabel, attributes, + alt = 'Image alt', }) => { const btnStyle = BUTTON_STYLES[style] @@ -48,7 +50,7 @@ export const Button: React.FC = ({ return href ? ( - {imgHref && alt} {text} + {imgHref && {alt}} {text} ) : ( @@ -61,7 +63,7 @@ export const Button: React.FC = ({ aria-label={ariaLabel} {...attributes} > - {imgHref && alt} + {imgHref && {alt}} {text} ) diff --git a/components/ResultsPage/BenefitCard.tsx b/components/ResultsPage/BenefitCard.tsx index f0677b7d4..16c373b05 100644 --- a/components/ResultsPage/BenefitCard.tsx +++ b/components/ResultsPage/BenefitCard.tsx @@ -1,9 +1,9 @@ import { Button } from '../Forms/Button' -import Image from 'next/image' import React from 'react' import { NextStepText } from '../../utils/api/definitions/types' -import { CustomCollapse } from './CustomCollapse' import { Router, useRouter } from 'next/router' +import { useTranslation } from '../Hooks' +import { WebTranslations } from '../../i18n/web' const AA_BUTTON_CLICK_ATTRIBUTE = 'ESDC-EDSC:Canadian OAS Benefits Est. Result card link click' @@ -50,19 +50,13 @@ export const BenefitCard: React.VFC<{ ) const router = useRouter() + const tsln = useTranslation() return (
    - {/* - - TO-DO: - - flex-wrap - - - */}

    {children}

    - {collapsedDetails && - collapsedDetails.map((detail, index) => ( - -

    - - ))} {nextStepText.nextStepTitle && (

    @@ -110,13 +90,17 @@ export const BenefitCard: React.VFC<{ className="ds-font-body ds-text-lg ds-leading-22px ds-font-medium ds-text-multi-neutrals-grey90a ds-mb-4" data-gc-analytics-customclick={`${AA_BUTTON_CLICK_ATTRIBUTE}:${action}`} > - {/* GET WHITE PNG */} +
    +
    +
    + ) +} diff --git a/components/ResultsPage/NextSteps.tsx b/components/ResultsPage/NextSteps.tsx index 8c30c12eb..8f9c8302a 100644 --- a/components/ResultsPage/NextSteps.tsx +++ b/components/ResultsPage/NextSteps.tsx @@ -74,6 +74,7 @@ export function getGisNextSteps( } } else { if (result.eligibility.result === ResultReason.LIVING_COUNTRY) { + nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle nextStepText.nextStepContent += `

    ${apiTsln.detail.mustBeInCanada}

    ` } } diff --git a/components/ResultsPage/SummaryEstimates.tsx b/components/ResultsPage/SummaryEstimates.tsx index c036d9774..e2ea0b338 100644 --- a/components/ResultsPage/SummaryEstimates.tsx +++ b/components/ResultsPage/SummaryEstimates.tsx @@ -1,22 +1,15 @@ -import { result } from 'lodash' -import Image from 'next/image' import { useRouter } from 'next/router' -import { getTranslations, numberToStringCurrency } from '../../i18n/api' +import { getTranslations } from '../../i18n/api' import { WebTranslations } from '../../i18n/web' import { BenefitKey, Language, ResultKey, - SummaryState, } from '../../utils/api/definitions/enums' -import { - BenefitResult, - BenefitResultsObject, -} from '../../utils/api/definitions/types' +import { BenefitResult } from '../../utils/api/definitions/types' import { useTranslation } from '../Hooks' import { CustomCollapse } from './CustomCollapse' import { DeferralTable } from './DeferralTable' -import { EstimatedTotalItem } from './EstimatedTotalItem' import { Estimation } from './Estimation' export const SummaryEstimates: React.VFC<{ @@ -25,7 +18,15 @@ export const SummaryEstimates: React.VFC<{ partnerResults userAge partnerAge -}> = ({ headings, userResults, partnerResults, userAge, partnerAge }) => { + maritalStatus +}> = ({ + headings, + userResults, + partnerResults, + userAge, + partnerAge, + maritalStatus, +}) => { const tsln = useTranslation() const apiTrans = getTranslations(tsln._language) @@ -33,16 +34,21 @@ export const SummaryEstimates: React.VFC<{ const currentYear = new Date().getFullYear() - const getDeferralTable = (benefitKey, result, future): any => { - console.log(result.cardDetail.meta?.tableData) + const getDeferralTable = (benefitKey, result, future, key?): any => { return benefitKey === BenefitKey.oas && result.eligibility.result === ResultKey.ELIGIBLE && result.entitlement.result > 0 && result.cardDetail.meta?.tableData !== null ? ( - + ) : null } + let collapsed = [] + return ( <> {headings.map((year, index) => { @@ -82,7 +88,7 @@ export const SummaryEstimates: React.VFC<{ ? partnerObj[Object.keys(partnerObj)[0]] : null - let eligible + let eligible = [] if (userResultObject) { const benefitAge = Object.keys(userResultObject)[0] @@ -97,18 +103,36 @@ export const SummaryEstimates: React.VFC<{ ) } + let partnerEligible = [] + if (partnerResultObject) { + const benefitAge = Object.keys(partnerResultObject)[0] + + const resultsArray: BenefitResult[] = Object.keys( + partnerResultObject[benefitAge] + ).map((value) => partnerResultObject[benefitAge][value]) + + partnerEligible = resultsArray.filter( + (result) => + result.eligibility?.result === ResultKey.ELIGIBLE || + result.eligibility?.result === ResultKey.INCOME_DEPENDENT + ) + } + + eligible = eligible.concat(partnerEligible) + return (
    -

    +

    {heading}

    -
    +
    {userResult && ( )} @@ -118,42 +142,52 @@ export const SummaryEstimates: React.VFC<{ resultObject={partnerResultObject} resultArray={partnerResults} age={partnerAge} + maritalStatus={maritalStatus} /> )} {eligible && - eligible.map((benefit) => { + eligible.map((benefit: BenefitResult) => { const collapsedDetails = benefit.cardDetail?.collapsedText return ( <> {collapsedDetails && - collapsedDetails.map((detail, index) => ( - -

    - {getDeferralTable( - benefit.benefitKey, - benefit, - true - ) && - // detail.heading === - // apiTrans.detailWithHeading.yourDeferralOptions - // .heading && - getDeferralTable( - benefit.benefitKey, - benefit, - true - )} - - ))} + collapsedDetails.map((detail, index) => { + if (!collapsed.includes(detail.heading)) { + collapsed.push(detail.heading) + return ( + +

    + {getDeferralTable( + benefit.benefitKey, + benefit, + true + ) && + detail.heading === + apiTrans.detailWithHeading + .yourDeferralOptions.heading && + getDeferralTable( + benefit.benefitKey, + benefit, + true, + index + )} + + ) + } + })} ) })} diff --git a/components/ResultsPage/index.tsx b/components/ResultsPage/index.tsx index 71ba97306..25a922e75 100644 --- a/components/ResultsPage/index.tsx +++ b/components/ResultsPage/index.tsx @@ -15,12 +15,11 @@ import { } from '../../utils/api/definitions/types' import { useTranslation } from '../Hooks' import { BenefitCards } from './BenefitCards' -import { EstimatedTotal } from './EstimatedTotal' import { YourAnswers } from './YourAnswers' import { Translations, getTranslations } from '../../i18n/api' import { FieldKey } from '../../utils/api/definitions/fields' -import { FutureSummaryEstimates } from './FutureSummaryEstimates' import { SummaryEstimates } from './SummaryEstimates' +import { Intro } from './Intro' const getEligibility = ( resultsEligible: BenefitResult[], @@ -48,11 +47,17 @@ const ResultsPage: React.VFC<{ const tsln = useTranslation() const apiTsln = getTranslations(tsln._language) const router = useRouter() + const isPartnered = inputs.find((input) => input.key === FieldKey.MARITAL_STATUS)['value'] === MaritalStatus.PARTNERED + const maritalStatus = inputs.find( + (input) => input.key === FieldKey.MARITAL_STATUS + )['value'] + const userAge = inputs.find((input) => input.key === FieldKey.AGE)['value'] + const partnerAge = isPartnered ? inputs.find((input) => input.key === FieldKey.PARTNER_AGE)['value'] : null @@ -145,7 +150,6 @@ const ResultsPage: React.VFC<{ const age = Number(Object.keys(item)[0]) const headingYear = currentYear + (age - Math.round(Number(partnerAge))) - // console.log(headingYear) let key if (age == 0) { key = currentYear @@ -172,22 +176,38 @@ const ResultsPage: React.VFC<{ const arr1 = userKeys.length > partnerKeys.length ? userKeys : partnerKeys const arr2 = arr1 == partnerKeys ? userKeys : partnerKeys + //get the headings to display user and partner results const headings = [...new Set([...arr1, ...arr2])] + //has multiple oas benefits + const multipleOAS_GIS = + userArrNew + .filter((item) => item !== null) + .filter((obj) => !!obj[Object.keys(obj)[0]]['oas']).length > 1 + return (

    -
    +
    + {/* Summary Estimates section */} - {headings && ( - - )} +
    + {headings && ( + + )} +
    diff --git a/i18n/api/en.ts b/i18n/api/en.ts index be32c3e6e..74ba00b80 100644 --- a/i18n/api/en.ts +++ b/i18n/api/en.ts @@ -346,6 +346,14 @@ const en: Translations = { eligiblePartialOas: "You're likely eligible to a partial Old Age Security pension.", yourDeferralOptions: 'Your deferral options', + deferralEligible: + "Since you're {CURRENT_AGE}, you can start receiving your payments right away or wait for up to {WAIT_MONTHS} more {MONTH_MONTHS}.", + deferralNoGis: + 'You won’t be able to receive the Guaranteed Income Supplement if you don’t receive the pension.', + deferralWillBeEligible: + 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', + deferralYearsInCanada: + "You can choose to defer your pension or increase your years of residence in Canada. To find out which option is best for you, contact us.", retroactivePay: 'Retroactive payment', sinceYouAreSixty: "Since you're {CURRENT_AGE}, you can start receiving your payments right away or wait for up to {WAIT_MONTHS} more {MONTH_MONTHS}.", @@ -547,6 +555,50 @@ const en: Translations = { heading: 'Your partner may be eligible', text: 'You can edit your answers to see what you and your partner could get if they received the Old Age Security pension.', }, + recoveryTax: { + heading: 'Recovery tax will be applied to your pension', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + recoveryTaxPartner: { + heading: "Recovery tax will be applied to your partner's pension", + text: "Since your partner's income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.", + }, + recoveryTaxBoth: { + heading: 'Recovery tax will be applied to your pensions', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + nonResidentTax: { + heading: 'Taxes will be applied to your pension', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF} and you live outside Canada, you won’t receive some or all of your Old Age Security pension due to:
    • the {LINK_RECOVERY_TAX}
    • the {LINK_NON_RESIDENT_TAX}
    ', + }, + nonResidentTaxPartner: { + heading: "Taxes will be applied to your partner's income", + text: `Since your partner's income is over {OAS_RECOVERY_TAX_CUTOFF} and you live outside Canada, you won’t receive some or all of your Old Age Security pension due to:
    • the {LINK_RECOVERY_TAX}
    • the {LINK_NON_RESIDENT_TAX}
    `, + }, + nonResidentTaxBoth: { + heading: 'Taxes will be applied to your pensions', + text: `Since you and your partner's income is over {OAS_RECOVERY_TAX_CUTOFF} and you live outside Canada, you won’t receive some or all of your Old Age Security pension due to:
    • the {LINK_RECOVERY_TAX}
    • the {LINK_NON_RESIDENT_TAX}
    `, + }, + yourDeferralOptions: { + heading: 'Your deferral options', + text: 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', + }, + deferWaitMonths: { + heading: 'Your deferral options', + text: 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', + }, + deferralDelay: { + heading: 'Your deferral options', + text: 'You can delay your pension for up to {DELAY_MONTHS} more {MONTH_MONTHS}.', + }, + retroactivePayment: { + heading: 'Retroactive payment', + text: 'You may be able to receive payment for up to the last 11 months.', + }, + mayBecomeEligible: { + heading: 'Retroactive payment', + text: 'You may be able to receive payment for up to the last 11 months.', + }, }, summaryTitle: { [SummaryState.MORE_INFO]: 'More information needed', @@ -573,6 +625,19 @@ const en: Translations = { futureHeadingAge: 'If you start receiving at age...', headingAmount: 'Your monthly payment could be...', }, + modal: { + userHeading: 'Can you receive this benefit?', + partnerHeading: 'Can your partner receive this benefit?', + userIncomeTooHigh: + 'You can apply for this benefit, but your income is too high to receive a monthly payment at this time.', + partnerIncomeTooHigh: + 'Your partner can apply for this benefit, but their income is too high to receive a monthly payment at this time.', + userCoupleIncomeTooHigh: + 'You can apply for this benefit, but your couple’s income is too high to receive a monthly payment at this time.', + partnerCoupleIncomeTooHigh: + 'Your partner can apply for this benefit, but your couple’s income is too high to receive a monthly payment at this time.', + close: 'Close', + }, links, incomeSingle: 'your income', incomeCombined: "you and your partner's combined income", diff --git a/i18n/api/fr.ts b/i18n/api/fr.ts index 96a70e90e..0a762ee7e 100644 --- a/i18n/api/fr.ts +++ b/i18n/api/fr.ts @@ -354,6 +354,10 @@ const fr: Translations = { eligiblePartialOas: 'Vous êtes probablement admissible à une pension partielle de la Sécurité de la vieillesse.', yourDeferralOptions: 'Vos options de report', + deferralEligible: '', + deferralNoGis: '', + deferralWillBeEligible: '', + deferralYearsInCanada: '', retroactivePay: 'Paiement rétroactif', sinceYouAreSixty: 'Puisque vous avez {CURRENT_AGE} ans, vous pouvez commencer à recevoir vos paiements immédiatement ou attendre encore {WAIT_MONTHS} mois.', @@ -558,6 +562,50 @@ const fr: Translations = { heading: 'Votre conjoint pourrait être admissible', text: 'Vous pouvez modifier vos réponses pour voir ce que vous et votre partenaire pourriez recevoir si votre partenaire recevait la pension de la Sécurité de la vieillesse.', }, + recoveryTax: { + heading: 'blablabla', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + recoveryTaxPartner: { + heading: 'blablabla', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + recoveryTaxBoth: { + heading: 'blablabla', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + nonResidentTax: { + heading: 'blablabla', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + nonResidentTaxPartner: { + heading: 'blablabla', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + nonResidentTaxBoth: { + heading: 'blablabla', + text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + }, + yourDeferralOptions: { + heading: 'Your deferral options', + text: 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', + }, + deferWaitMonths: { + heading: 'Your deferral options', + text: 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', + }, + deferralDelay: { + heading: 'Your deferral options', + text: 'You can delay your pension for up to {DELAY_MONTHS} more {MONTH_MONTHS}.', + }, + retroactivePayment: { + heading: 'Your deferral options', + text: 'You can delay your pension for up to {DELAY_MONTHS} more {MONTH_MONTHS}.', + }, + mayBecomeEligible: { + heading: 'Retroactive payment', + text: 'You may be able to receive payment for up to the last 11 months.', + }, }, summaryTitle: { [SummaryState.MORE_INFO]: 'Plus de renseignements sont nécessaires', @@ -587,6 +635,19 @@ const fr: Translations = { futureHeadingAge: 'Si vous commencez votre pension à...', headingAmount: 'Vous pourriez recevoir chaque mois...', }, + modal: { + userHeading: 'Est-ce que vous pouvez recevoir cette prestation?', + partnerHeading: 'Est-ce que votre conjoint peut recevoir cette prestation?', + userIncomeTooHigh: + 'Vous pouvez faire une demande pour cette prestation, mais votre revenu est trop élevé pour recevoir un paiement mensuel pour le moment.', + partnerIncomeTooHigh: + 'Votre conjoint peut faire une demande pour cette prestation, mais son revenu est trop élevé pour recevoir un paiement mensuel pour le moment.', + userCoupleIncomeTooHigh: + 'Vous pouvez faire une demande pour cette prestation, mais votre revenu de couple est trop élevé pour recevoir un paiement mensuel pour le moment.', + partnerCoupleIncomeTooHigh: + 'Votre conjoint peut faire une demande pour cette prestation, mais votre revenu de couple est trop élevé pour recevoir un paiement mensuel pour le moment.', + close: 'Fermer', + }, links, incomeSingle: 'votre revenu', incomeCombined: 'le revenu combiné de vous et votre conjoint', diff --git a/i18n/api/index.ts b/i18n/api/index.ts index 1e6c4d807..85e4705f1 100644 --- a/i18n/api/index.ts +++ b/i18n/api/index.ts @@ -62,6 +62,10 @@ export interface Translations { eligibleEntitlementUnavailable: string eligiblePartialOas: string yourDeferralOptions: string + deferralWillBeEligible: string + deferralEligible: string + deferralNoGis: string + deferralYearsInCanada: string retroactivePay: string sinceYouAreSixty: string futureDeferralOptions: string @@ -170,6 +174,17 @@ export interface Translations { partnerEligible: { heading: string; text: string } partnerDependOnYourIncome: { heading: string; text: string } partnerEligibleButAnsweredNo: { heading: string; text: string } + recoveryTax: { heading: string; text: string } + recoveryTaxPartner: { heading: string; text: string } + recoveryTaxBoth: { heading: string; text: string } + nonResidentTax: { heading: string; text: string } + nonResidentTaxPartner: { heading: string; text: string } + nonResidentTaxBoth: { heading: string; text: string } + yourDeferralOptions: { heading: string; text: string } + deferWaitMonths: { heading: string; text: string } + deferralDelay: { heading: string; text: string } + retroactivePayment: { heading: string; text: string } + mayBecomeEligible: { heading: string; text: string } } summaryTitle: { [key in SummaryState]?: string } summaryDetails: { [key in SummaryState]?: string } @@ -179,6 +194,15 @@ export interface Translations { futureHeadingAge: string headingAmount: string } + modal: { + userHeading: string + partnerHeading: string + userIncomeTooHigh: string + partnerIncomeTooHigh: string + userCoupleIncomeTooHigh: string + partnerCoupleIncomeTooHigh: string + close: string + } links: LinkDefinitions incomeSingle: string incomeCombined: string diff --git a/i18n/web/en.ts b/i18n/web/en.ts index 5bed00c1c..afd150482 100644 --- a/i18n/web/en.ts +++ b/i18n/web/en.ts @@ -310,9 +310,11 @@ const en: WebTranslations = { resultsPage: { yourMonEstimateHeading: 'Your monthly estimate', changeInSituation: 'Changes in your situation may impact your results.', - youEstimateMayChange: 'Your estimate may change over time based on:', + youEstimateMayChange: 'Your estimate may change over time based on', basedYourAge: 'your age', basedYourPartner: 'the benefits your partner receives', + ifYouChoseToDefer: + 'If you choose to defer your pension, your future estimate will be higher.', header: 'Table of estimated monthly amounts', general: 'The following is only an estimate of your eligibility and monthly payments based on current rates. Amounts may increase with the cost of living.', @@ -469,6 +471,7 @@ const en: WebTranslations = { tooltip: { moreInformation: 'More information', }, + openNewTab: 'Opens in a new tab', partnerIsNotEligible: 'Your partner is not eligible', partnerLegalStatusNotEligible: "Your partner's legal status indicates that they are not receiving the Old Age Security pension.", diff --git a/i18n/web/fr.ts b/i18n/web/fr.ts index b9ad400e2..d5cc84831 100644 --- a/i18n/web/fr.ts +++ b/i18n/web/fr.ts @@ -317,9 +317,11 @@ const fr: WebTranslations = { changeInSituation: 'Si votre situation change, vos résultats pourraient changer.', youEstimateMayChange: - 'Votre estimation peut changer au fil du temps en fonction :', - basedYourAge: 'de votre âge;', + 'Votre estimation peut changer au fil du temps en fonction ', + basedYourAge: 'de votre âge', basedYourPartner: 'des prestations que votre conjoint reçoit.', + ifYouChoseToDefer: + 'Si vous choisissez de reporter votre pension, votre estimation future sera plus élevée.', header: "Tableau des résultats d'estimation", general: `Les résultats suivants ne sont qu'une estimation de votre admissibilité et de vos paiements mensuels basée sur les montants actuels. Ceux-ci peuvent augmenter avec le coût de la vie.`, onThisPage: 'Sur cette page', @@ -485,6 +487,8 @@ const fr: WebTranslations = { tooltip: { moreInformation: "Plus d'information", }, + openNewTab: "s'ouvre dans un nouvel onglet", + partnerIsNotEligible: "Votre conjoint n'est pas admissible", partnerLegalStatusNotEligible: "Le statut légal de votre conjoint indique qu'il ne reçoit pas la pension de la Sécurité de la vieillesse.", diff --git a/i18n/web/index.ts b/i18n/web/index.ts index f6c3041ec..41d314247 100644 --- a/i18n/web/index.ts +++ b/i18n/web/index.ts @@ -221,7 +221,7 @@ export type WebTranslations = { youEstimateMayChange: string basedYourAge: string basedYourPartner: string - + ifYouChoseToDefer: string header: string general: string onThisPage: string @@ -293,6 +293,8 @@ export type WebTranslations = { moreInformation: string } + openNewTab: string + partnerIsNotEligible: string partnerLegalStatusNotEligible: string partnerYearsLivingCanadaNotEligible: string diff --git a/public/moreInfo.png b/public/moreInfo.png new file mode 100644 index 0000000000000000000000000000000000000000..c8f4526ef36b127392259c8a5c0e7cd0c81da7cc GIT binary patch literal 807 zcmV+?1K9kDP)UV7)yT#!(y)Ntcgm-YeLH%OiU@&sMKLHY!RBPYt8Qs)V9B}$P%!bc7q zasdevdzsnTjpO()?I*2buXpyFnf+!qga$nEw5Js95gCtPJLv!cV*`Zz5dNFu&9^{@ zb^A~qf#cwWA3d}~5XbPp20Ca()baG@hGGK3E8GQy;o1~_80hihbPgOv$8qrv23_0- zoX&WPV~#GGPo=PtxVWq#35YOC5=2TNGKuLD(H@`EQ56|Swx31jX7e^(B_w1pjtTvn z3w>TB<}tKcQ0yShL~;w>YvS579?WQH;5o|atlvM6~Hs|Xx z`gwIdJkBqC8p@2w@AQ4r5QAxzAou&oZ>T}An^sF z6_5}HHw6+~M|^&0=!qil2<i9UbO0f%;4XF#+p7;Y_FsCVu(yV_MY z>Bi9FXpNn>{ldTP@;irq)BlO^&uq_`qxmms@kxiSY)h2No4u_&n^3Nee2a4OUw=ix z_|ca4)+jvW*XI?RJV-|=BwZXy|9hZ+791=`dh4$AcS}Si=Uw)(v99G} + + \ No newline at end of file diff --git a/utils/api/benefitHandler.ts b/utils/api/benefitHandler.ts index 698698087..17a1f24b4 100644 --- a/utils/api/benefitHandler.ts +++ b/utils/api/benefitHandler.ts @@ -161,6 +161,7 @@ export class BenefitHandler { const clientOasNoDeferral = new OasBenefit( this.input.client, this.fields.translations, + null, false, this.future, false, @@ -174,6 +175,7 @@ export class BenefitHandler { const partnerOasNoDeferral = new OasBenefit( this.input.partner, this.fields.translations, + clientOasNoDeferral, true ) @@ -208,6 +210,7 @@ export class BenefitHandler { clientOasWithDeferral = new OasBenefit( clientOasHelper.newInput, this.fields.translations, + null, false, this.future, true, @@ -226,7 +229,10 @@ export class BenefitHandler { this.fields.translations, clientOasNoDeferral.info, false, - this.future + this.future, + null, + this.formAge, + this.formYearsInCanada ) consoleDev( @@ -339,6 +345,7 @@ export class BenefitHandler { const partnerOas = new OasBenefit( this.input.partner, this.fields.translations, + clientOas, true ) this.setValueForAllResults(allResults, 'partner', 'oas', partnerOas) @@ -456,6 +463,7 @@ export class BenefitHandler { const partnerOas = new OasBenefit( this.input.partner, this.fields.translations, + clientOas, true ) this.setValueForAllResults(allResults, 'partner', 'oas', partnerOas) @@ -480,7 +488,10 @@ export class BenefitHandler { this.fields.translations, allResults.client.oas, false, - this.future + this.future, + null, + this.formAge, + this.formYearsInCanada ) this.setValueForAllResults(allResults, 'client', 'gis', clientGis) } diff --git a/utils/api/benefits/alwBenefit.ts b/utils/api/benefits/alwBenefit.ts index 9a88d823a..a2c007bbf 100644 --- a/utils/api/benefits/alwBenefit.ts +++ b/utils/api/benefits/alwBenefit.ts @@ -295,4 +295,35 @@ export class AlwBenefit extends BaseBenefit { links.push(this.translations.links.overview[BenefitKey.alw]) return links } + + protected getCardCollapsedText(): CardCollapsedText[] { + let cardCollapsedText = super.getCardCollapsedText() + + if ( + this.eligibility.result !== ResultKey.ELIGIBLE && + this.eligibility.result !== ResultKey.INCOME_DEPENDENT + ) + return cardCollapsedText + + // partner is eligible, IF income was not provided the result = 0 + // when IF income > 0 AND invSeparated = true the amount is incorrectly calculated + // the correct amount is on the benefitHandler. + if (this.partner) { + if (this.entitlement.result > 0) { + if (this.eligibility.result !== ResultKey.INCOME_DEPENDENT) { + if (!this.input.invSeparated) { + cardCollapsedText.push( + this.translations.detailWithHeading.partnerEligible + ) + } + } else { + cardCollapsedText.push( + this.translations.detailWithHeading.partnerDependOnYourIncome + ) + } + } + } + + return cardCollapsedText + } } diff --git a/utils/api/benefits/gisBenefit.ts b/utils/api/benefits/gisBenefit.ts index e1e29f03f..34566c093 100644 --- a/utils/api/benefits/gisBenefit.ts +++ b/utils/api/benefits/gisBenefit.ts @@ -22,6 +22,8 @@ import { EntitlementFormula } from './entitlementFormula' export class GisBenefit extends BaseBenefit { partner: Boolean future: Boolean + formAge: number + formYearsInCanada: number originalInput?: ProcessedInput constructor( input: ProcessedInput, @@ -29,12 +31,16 @@ export class GisBenefit extends BaseBenefit { private oasResult: BenefitResult, partner?: Boolean, future?: Boolean, - originalInput?: ProcessedInput + originalInput?: ProcessedInput, + formAge?: number, + formYearsInCanada?: number ) { super(input, translations, BenefitKey.gis) this.partner = partner this.future = future this.originalInput = originalInput + this.formAge = formAge + this.formYearsInCanada = formYearsInCanada } protected getEligibility(): EligibilityResult { @@ -280,35 +286,48 @@ export class GisBenefit extends BaseBenefit { ) return cardCollapsedText - const inputs = this.originalInput === null ? this.input : this.originalInput - // Related to OAS Deferral, don't show if already receiving - if (inputs) { - const ageInOasRange = inputs.age >= 65 && inputs.age < 70 - if ( - this.partner !== true && - this.entitlement.result !== 0 && - ageInOasRange && - !inputs.receiveOAS && - !this.future - ) { - cardCollapsedText.push( - this.translations.detailWithHeading.ifYouDeferYourPension - ) - } - } + if (!this.partner) { + let text = '' + let heading - if (this.partner) { - if (this.input.income.provided && this.entitlement.result !== 0) { - if ( - this.input.partnerBenefitStatus.value === PartnerBenefitStatus.NONE - ) { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerEligibleButAnsweredNo - ) - } else { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerEligible - ) + if (this.oasResult.eligibility.result === ResultKey.ELIGIBLE) { + if (this.oasResult.cardDetail.meta.receiveOAS == false) { + heading = this.translations.detail.yourDeferralOptions + if (this.oasResult.entitlement.result > 0) { + if ( + this.input.age != this.originalInput?.age && + this.originalInput?.age < 70 + ) { + if (this.input.age >= 65 && this.input.age < 70) { + //CHECK IF RECEIVING OAS + text += this.translations.detail.deferralEligible + } else if (this.formAge < 65) { + text += this.translations.detail.deferralWillBeEligible + } + } + + if (text !== '') { + if (this.entitlement.result === 0) { + text += `

    ${this.translations.detail.deferralNoGis}

    ` + } else { + text += `

    ${this.translations.detail.deferralNoGis}

    ` + } + + if (!this.input.livedOnlyInCanada) { + if ( + this.formAge != this.input.age && + this.formYearsInCanada <= 40 && + this.formYearsInCanada != this.input.yearsInCanadaSince18 + ) { + text += `

    ${this.translations.detail.deferralYearsInCanada}

    ` + } + } + } + } + + if (text !== '') { + this.oasResult.cardDetail.collapsedText.push({ heading, text }) + } } } } diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index 6c59e3321..15b2506b4 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -2,6 +2,8 @@ import { Translations } from '../../../i18n/api' import { BenefitKey, EntitlementResultType, + LivingCountry, + MaritalStatus, PartnerBenefitStatus, ResultKey, ResultReason, @@ -28,9 +30,11 @@ export class OasBenefit extends BaseBenefit { inputAge: number // Age on the form. Needed as a reference when calculating eligibility for a different age ONLY for non-future benefits formAge: number formYearsInCanada: number + userOas: OasBenefit constructor( input: ProcessedInput, translations: Translations, + userOas?: OasBenefit, partner?: Boolean, future?: Boolean, deferral: boolean = false, @@ -48,6 +52,7 @@ export class OasBenefit extends BaseBenefit { this.inputAge = inputAge this.formAge = formAge this.formYearsInCanada = formYearsInCanada + this.userOas = userOas } protected getEligibility(): EligibilityResult { @@ -433,6 +438,10 @@ export class OasBenefit extends BaseBenefit { } } + public updateCollapsedText(): CardCollapsedText[] { + return this.getCardCollapsedText() + } + protected getCardCollapsedText(): CardCollapsedText[] { let cardCollapsedText = super.getCardCollapsedText() @@ -443,50 +452,103 @@ export class OasBenefit extends BaseBenefit { ) return cardCollapsedText - // if (this.partner && this.entitlement.result !== 0) { - // if ( - // // eslint-disable-next-line prettier/prettier - // this.input.partnerBenefitStatus.value === - // PartnerBenefitStatus.OAS_GIS || - // this.input.partnerBenefitStatus.value === PartnerBenefitStatus.HELP_ME - // ) { - // cardCollapsedText.push( - // this.translations.detailWithHeading.partnerEligible - // ) - // } else { - // cardCollapsedText.push( - // this.translations.detailWithHeading.partnerEligibleButAnsweredNo - // ) - // } - - // return cardCollapsedText - // } - - // // getCardText reset the eligibility reason - // if (this.eligibility.reason === ResultReason.INCOME) - // return cardCollapsedText - - // // increase at 75 - // if (this.currentEntitlementAmount !== this.age75EntitlementAmount) { - // if (!this.future) { - // cardCollapsedText.push( - // this.translations.detailWithHeading.oasIncreaseAt75 - // ) - // } - // } else - // cardCollapsedText.push( - // this.translations.detailWithHeading.oasIncreaseAt75Applied - // ) - - // deferral - // if (this.deferralIncrease) - // cardCollapsedText.push( - // this.translations.detailWithHeading.oasDeferralApplied - // ) - // else if (this.input.age >= 65 && this.input.age < 70) - // cardCollapsedText.push( - // this.translations.detailWithHeading.oasDeferralAvailable - // ) + if (this.partner) { + //EC15 + if (this.entitlement.result > 0) { + if ( + this.input.partnerBenefitStatus.value !== PartnerBenefitStatus.NONE + ) { + cardCollapsedText.push( + this.translations.detailWithHeading.partnerEligibleButAnsweredNo + ) + } + } + + if (this.userOas) { + if ( + this.eligibility.result == ResultKey.ELIGIBLE && + this.userOas.eligibility.result == ResultKey.ELIGIBLE + ) { + if (this.clawbackAmount > 0 && this.userOas.clawbackAmount > 0) { + if (this.input.livingCountry.value !== LivingCountry.CANADA) { + cardCollapsedText.push( + this.translations.detailWithHeading.nonResidentTaxBoth + ) + } else { + cardCollapsedText.push( + this.translations.detailWithHeading.recoveryTaxBoth + ) + } + } + } else { + if (this.clawbackAmount > 0) { + if (this.input.livingCountry.value !== LivingCountry.CANADA) { + cardCollapsedText.push( + this.translations.detailWithHeading.recoveryTaxPartner + ) + } else { + cardCollapsedText.push( + this.translations.detailWithHeading.nonResidentTaxPartner + ) + } + } + } + } + } + + if (!this.partner) { + if ( + this.inputAge > 64 && + this.inputAge < 75 && + this.entitlement.result > 0 + ) { + cardCollapsedText.push( + this.translations.detailWithHeading.oasIncreaseAt75 + ) + } + + //RECOVER TAX MESSAGE - if partnered better to handle it in the partnered section to access both benefits + if (this.input.maritalStatus.value != MaritalStatus.PARTNERED) { + if (this.clawbackAmount > 0) { + if (this.input.livingCountry.value !== LivingCountry.CANADA) { + cardCollapsedText.push( + this.translations.detailWithHeading.nonResidentTax + ) + } else { + cardCollapsedText.push( + this.translations.detailWithHeading.recoveryTax + ) + } + } + } + + if (this.inputAge > 74 && this.entitlement.result > 0) { + cardCollapsedText.push( + this.translations.detailWithHeading.oasIncreaseAt75Applied + ) + } + + if ( + this.entitlement.result == 0 && + this.inputAge > 64 && + this.inputAge > 70 && + !this.input.receiveOAS + ) { + cardCollapsedText.push( + this.translations.detailWithHeading.deferWaitMonths + ) + } + + if ( + this.inputAge >= 70 && + !this.input.receiveOAS && + this.entitlement.result > 0 + ) { + cardCollapsedText.push( + this.translations.detailWithHeading.retroactivePayment + ) + } + } return cardCollapsedText } From f32c5a5be48f27322d8aca08aff03803d56a3f73 Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Fri, 5 Jul 2024 13:17:27 -0400 Subject: [PATCH 05/12] Remove unused files --- components/ResultsPage/MayBeEligible.tsx | 61 --------- components/ResultsPage/WillBeEligible.tsx | 160 ---------------------- 2 files changed, 221 deletions(-) delete mode 100644 components/ResultsPage/MayBeEligible.tsx delete mode 100644 components/ResultsPage/WillBeEligible.tsx diff --git a/components/ResultsPage/MayBeEligible.tsx b/components/ResultsPage/MayBeEligible.tsx deleted file mode 100644 index 28128d6ee..000000000 --- a/components/ResultsPage/MayBeEligible.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import Image from 'next/image' -import { getTranslations } from '../../i18n/api' -import { WebTranslations } from '../../i18n/web' -import { BenefitResult } from '../../utils/api/definitions/types' -import { useTranslation } from '../Hooks' - -export const MayBeEligible: React.VFC<{ - resultsEligible: BenefitResult[] - partner?: boolean -}> = ({ resultsEligible, partner = false }) => { - const tsln = useTranslation() - const apiTrans = getTranslations(tsln._language) - const isEligible: boolean = resultsEligible.length > 0 - - // Do nothing if eligible - if (isEligible) return null - - // Displays only when not eligible - return ( - <> -

    -
    - {' '} -
    -
    - {isEligible - ? tsln.resultsPage.youMayBeEligible - : partner - ? tsln.resultsPage.partnerNotEligible - : tsln.resultsPage.youAreNotEligible} -
    -

    -
    -

    -

      - {resultsEligible.map((benefit) => ( -
    • - {apiTrans.benefit[benefit.benefitKey]} -
    • - ))} -
    -
    - - ) -} diff --git a/components/ResultsPage/WillBeEligible.tsx b/components/ResultsPage/WillBeEligible.tsx deleted file mode 100644 index ee59e56b6..000000000 --- a/components/ResultsPage/WillBeEligible.tsx +++ /dev/null @@ -1,160 +0,0 @@ -import { result } from 'lodash' -import Image from 'next/image' -import { useRouter } from 'next/router' -import { getTranslations, numberToStringCurrency } from '../../i18n/api' -import { WebTranslations } from '../../i18n/web' -import { Language, ResultKey } from '../../utils/api/definitions/enums' -import { BenefitResult } from '../../utils/api/definitions/types' -import { useTranslation } from '../Hooks' -import { EstimatedTotalItem } from './EstimatedTotalItem' - -export const WillBeEligible: React.VFC<{ - futureResults: any - partner?: boolean - partnerNoOAS: boolean - multipleResults: boolean - eligibleOAS: boolean -}> = ({ - futureResults, - partner = false, - partnerNoOAS, - multipleResults, - eligibleOAS, -}) => { - const tsln = useTranslation() - const apiTrans = getTranslations(tsln._language) - const language = useRouter().locale as Language - - const multipleOAS_GIS = - futureResults.filter((obj) => !!obj[Object.keys(obj)[0]]['oas']).length > 1 - - for (let i = futureResults.length - 1; i >= 0; i--) { - if (i > 0) { - if ( - Object.values(Object.values(Object.values(futureResults)[i])[0]) - .length != 1 - ) { - if ( - Object.values(Object.values(futureResults[i])[0])[0]?.entitlement - .result == - Object.values(Object.values(futureResults[i - 1])[0])[0] - ?.entitlement.result && - Object.values(Object.values(futureResults[i])[0])[1]?.entitlement - .result == - Object.values(Object.values(futureResults[i - 1])[0])[1] - ?.entitlement.result - ) { - futureResults.pop() - } - } - } - } - - return ( - <> - {futureResults.map((resultObj, idx) => { - const age = Object.keys(resultObj)[0] - const onlyOASGIS = Object.keys( - resultObj[Object.keys(resultObj)[0]] - ).filter((key) => key === 'oas' || key === 'gis') - - // show if some are non zero - const nonZeroExist = onlyOASGIS.some( - (key) => resultObj[age][key].entitlement?.result > 0 - ) - - // - // an overcomplicated condition for useless information - // - const mainStr = - (multipleOAS_GIS && nonZeroExist && !multipleResults && idx > 0) || - (multipleOAS_GIS && nonZeroExist && multipleResults) || - (multipleOAS_GIS && nonZeroExist && idx > 0) || - eligibleOAS - ? partner - ? apiTrans.detail.partnerContinues - : apiTrans.detail.continueReceiving - : apiTrans.at - - const partnerText = - (multipleOAS_GIS && nonZeroExist && !multipleResults && idx > 0) || - (multipleOAS_GIS && nonZeroExist && multipleResults) || - (multipleOAS_GIS && nonZeroExist && idx > 0) || - eligibleOAS - ? tsln.resultsPage.theyToReceive - : tsln.resultsPage.partnerToReceive - - const text = `${mainStr} ${Math.floor(Number(age))}${apiTrans.atAge} ${ - partner ? partnerText : tsln.resultsPage.toReceive - }` - - const resultsArray: BenefitResult[] = Object.keys(resultObj[age]).map( - (value) => resultObj[age][value] - ) - let eligible = resultsArray.filter( - (result) => - result.eligibility?.result === ResultKey.ELIGIBLE || - result.eligibility?.result === ResultKey.INCOME_DEPENDENT - ) - - // If partner answers "No" to receiving OAS, the amounts should not show - if (partner && partnerNoOAS) { - eligible = eligible.map((benefit) => { - return { - ...benefit, - entitlement: { ...benefit.entitlement, result: 0 }, - } - }) - } - - const headingYear = () => { - console.log(resultObj) - console.log(futureResults) - // console.log(futurePartnerResults) - } - headingYear() - - const eligibleTotalAmount = eligible.reduce( - (sum, obj) => sum + obj.entitlement.result, - 0 - ) - - return ( -
    -

    - -

      - {eligible.map((benefit) => ( - - ))} -
    - {eligible.length > 1 && eligibleTotalAmount > 0 && ( -

    - {partner - ? tsln.resultsPage.futurePartnerTotal - : tsln.resultsPage.futureTotal} - - {numberToStringCurrency(eligibleTotalAmount, language)} - - . -

    - )} -
    - ) - })} - - ) -} From 059968b6b34480d131de2e75a4868c41b6bef0e2 Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Wed, 18 Sep 2024 11:13:58 -0400 Subject: [PATCH 06/12] Batch 1,2,3 changes --- components/ResultsPage/BenefitCard.tsx | 13 +- components/ResultsPage/BenefitCards.tsx | 40 +++++-- components/ResultsPage/CustomCollapse.tsx | 2 +- components/ResultsPage/EstimatedTotalItem.tsx | 1 - components/ResultsPage/Estimation.tsx | 19 +-- components/ResultsPage/Intro.tsx | 5 +- components/ResultsPage/Modal.tsx | 17 +-- components/ResultsPage/NextSteps.tsx | 111 ++++++++++-------- components/ResultsPage/SummaryEstimates.tsx | 1 - components/ResultsPage/index.tsx | 15 ++- i18n/api/en.ts | 38 +++--- i18n/api/fr.ts | 91 ++++++++------ i18n/api/index.ts | 8 +- i18n/web/fr.ts | 2 +- utils/api/benefits/alwBenefit.ts | 8 ++ utils/api/benefits/gisBenefit.ts | 17 ++- utils/api/benefits/oasBenefit.ts | 51 +++++--- utils/api/definitions/enums.ts | 1 + 18 files changed, 279 insertions(+), 161 deletions(-) diff --git a/components/ResultsPage/BenefitCard.tsx b/components/ResultsPage/BenefitCard.tsx index 16c373b05..0af692158 100644 --- a/components/ResultsPage/BenefitCard.tsx +++ b/components/ResultsPage/BenefitCard.tsx @@ -4,6 +4,7 @@ import { NextStepText } from '../../utils/api/definitions/types' import { Router, useRouter } from 'next/router' import { useTranslation } from '../Hooks' import { WebTranslations } from '../../i18n/web' +import { BenefitKey } from '../../utils/api/definitions/enums' const AA_BUTTON_CLICK_ATTRIBUTE = 'ESDC-EDSC:Canadian OAS Benefits Est. Result card link click' @@ -13,6 +14,7 @@ export const BenefitCard: React.VFC<{ benefitName: string isEligible: boolean future: boolean + liveInCanada: boolean eligibleText: string collapsedDetails: any children: React.ReactNode @@ -29,6 +31,7 @@ export const BenefitCard: React.VFC<{ benefitName, isEligible, future, + liveInCanada, eligibleText, collapsedDetails, children, @@ -40,7 +43,9 @@ export const BenefitCard: React.VFC<{
    -

    {benefitName} -

    + {eligibleFlag}
    diff --git a/components/ResultsPage/BenefitCards.tsx b/components/ResultsPage/BenefitCards.tsx index 77f05e332..337b59292 100644 --- a/components/ResultsPage/BenefitCards.tsx +++ b/components/ResultsPage/BenefitCards.tsx @@ -24,10 +24,16 @@ export const BenefitCards: React.VFC<{ results: BenefitResult[] futureClientResults: any partnerResults: BenefitResult[] -}> = ({ inputAge, results, futureClientResults, partnerResults }) => { + liveInCanada?: boolean +}> = ({ + inputAge, + results, + futureClientResults, + partnerResults, + liveInCanada, +}) => { const tsln = useTranslation() const apiTsln = getTranslations(tsln._language) - const receivingOAS: boolean = results[0]?.cardDetail?.meta?.receiveOAS /** @@ -109,12 +115,20 @@ export const BenefitCards: React.VFC<{ // get... code below was moved to another file to make it a bit cleaner if (benefitKey === BenefitKey.gis) { - getGisNextSteps(result, receivingOAS, nextStepText, apiTsln, tsln) + getGisNextSteps( + result, + receivingOAS, + liveInCanada, + nextStepText, + apiTsln, + tsln + ) } else if (benefitKey === BenefitKey.oas) { getOasNextSteps( result, inputAge, receivingOAS, + liveInCanada, nextStepText, apiTsln, tsln @@ -124,12 +138,20 @@ export const BenefitCards: React.VFC<{ result, partnerResults, inputAge, + liveInCanada, nextStepText, apiTsln, tsln ) } else if (benefitKey === BenefitKey.alws) { - getAlwsNextSteps(result, inputAge, nextStepText, apiTsln, tsln) + getAlwsNextSteps( + result, + inputAge, + liveInCanada, + nextStepText, + apiTsln, + tsln + ) } nextStepText.nextStepContent = replaceTextVariables( @@ -171,9 +193,12 @@ export const BenefitCards: React.VFC<{ result.eligibility.result === ResultKey.ELIGIBLE || result.eligibility.result === ResultKey.INCOME_DEPENDENT - const eligibleText = eligibility - ? apiTsln.result.eligible - : apiTsln.result.ineligible + const eligibleText = + result.benefitKey !== BenefitKey.oas && !liveInCanada + ? apiTsln.result.almostEligible + : eligibility + ? apiTsln.result.eligible + : apiTsln.result.ineligible const nextStepText = getNextStepText(result.benefitKey, result) @@ -186,6 +211,7 @@ export const BenefitCards: React.VFC<{ benefitName={titleText} isEligible={eligibility} future={future} + liveInCanada={liveInCanada} eligibleText={eligibleText} nextStepText={nextStepText} collapsedDetails={collapsedDetails} diff --git a/components/ResultsPage/CustomCollapse.tsx b/components/ResultsPage/CustomCollapse.tsx index 371d9fd34..15ba2d7e3 100644 --- a/components/ResultsPage/CustomCollapse.tsx +++ b/components/ResultsPage/CustomCollapse.tsx @@ -10,7 +10,7 @@ export const CustomCollapse = (props) => { > diff --git a/components/ResultsPage/Estimation.tsx b/components/ResultsPage/Estimation.tsx index 8d0d6e4ab..7f17cd2b1 100644 --- a/components/ResultsPage/Estimation.tsx +++ b/components/ResultsPage/Estimation.tsx @@ -18,6 +18,7 @@ export const Estimation: React.VFC<{ }> = ({ partner, resultObject, resultArray, age, maritalStatus }) => { const tsln = useTranslation() const apiTrans = getTranslations(tsln._language) + const roundedAge = Math.trunc(Number(age)) age = Math.round(age) const language = useRouter().locale as Language @@ -62,7 +63,7 @@ export const Estimation: React.VFC<{ for (let i = 0; i < benefitResultArray.length; i++) { const obj = benefitResultArray[i] if ( - Object.keys(obj[Object.keys(obj)[0]]).includes('oas') && + Object.keys(obj[Object.keys(obj)[0]]).includes('oas') || Object.keys(obj[Object.keys(obj)[0]]).includes('gis') ) { // Check if it's the same object @@ -81,7 +82,7 @@ export const Estimation: React.VFC<{ for (let i = benefitResultArray.length - 1; i >= 0; i--) { const obj = benefitResultArray[i] if ( - Object.keys(obj[Object.keys(obj)[0]]).includes('oas') && + Object.keys(obj[Object.keys(obj)[0]]).includes('oas') || Object.keys(obj[Object.keys(obj)[0]]).includes('gis') ) { // Check if it's the same object @@ -109,10 +110,10 @@ export const Estimation: React.VFC<{ const eligibleAmt = numberToStringCurrency(eligibleTotalAmount, language) - const arrayofben = benefitResultArray + const arrayOfBen = benefitResultArray //ALW & ALWS - if (!benefitType.includes('oas') || !benefitType.includes('gis')) { + if (benefitType.includes('alw') || benefitType.includes('alws')) { //CURRENT ELIGIBLE if (benefitAge == '0') { text = `${apiTrans.detail.youCouldReceiveUntil} ${age}${ @@ -145,7 +146,7 @@ export const Estimation: React.VFC<{ //FIRST NOT LAST else { const nextBenefitResult = - arrayofben[arrayofben.indexOf(resultObject) + 1] + arrayOfBen[arrayOfBen.indexOf(resultObject) + 1] const nextBenefitTotal = nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] @@ -187,7 +188,7 @@ export const Estimation: React.VFC<{ //NOT LAST else { const nextBenefitResult = - arrayofben[arrayofben.indexOf(resultObject) + 1] + arrayOfBen[arrayOfBen.indexOf(resultObject) + 1] const nextBenefitTotal = nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] @@ -221,7 +222,7 @@ export const Estimation: React.VFC<{ //NOT FIRST else { const previousBenefitResult = - arrayofben[arrayofben.indexOf(resultObject) - 1] + arrayOfBen[arrayOfBen.indexOf(resultObject) - 1] const previousBenefitTotal = previousBenefitResult[Object.keys(previousBenefitResult)[0]]['oas'] @@ -249,7 +250,7 @@ export const Estimation: React.VFC<{ } ${eligibleAmt} ${apiTrans.detail.youCouldReceivePerMonth}` } else { const nextBenefitResult = - arrayofben[arrayofben.indexOf(resultObject) + 1] + arrayOfBen[arrayOfBen.indexOf(resultObject) + 1] const nextBenefitTotal = nextBenefitResult[Object.keys(nextBenefitResult)[0]]['oas'] @@ -277,7 +278,7 @@ export const Estimation: React.VFC<{ } } - return text + return text.charAt(0).toUpperCase() + text.slice(1) } return ( diff --git a/components/ResultsPage/Intro.tsx b/components/ResultsPage/Intro.tsx index cc4c256e1..ba3bc8d8b 100644 --- a/components/ResultsPage/Intro.tsx +++ b/components/ResultsPage/Intro.tsx @@ -8,12 +8,13 @@ export const Intro: React.VFC<{ hasMultipleOasGis: boolean }> = ({ hasPartner, userAge, estimateLength, hasMultipleOasGis }) => { const tsln = useTranslation() - return ( <>

    {tsln.resultsPage.yourMonEstimateHeading}
    - {estimateLength == 1 &&

    {tsln.resultsPage.changeInSituation}

    } + {estimateLength == 1 && ( +

    {tsln.resultsPage.changeInSituation}

    + )} {estimateLength > 1 && !hasPartner && (

    {tsln.resultsPage.youEstimateMayChange}{' '} diff --git a/components/ResultsPage/Modal.tsx b/components/ResultsPage/Modal.tsx index f3ac45d24..9b58b7209 100644 --- a/components/ResultsPage/Modal.tsx +++ b/components/ResultsPage/Modal.tsx @@ -1,3 +1,4 @@ +import { Button } from '@dts-stn/service-canada-design-system' import { getTranslations } from '../../i18n/api' import { WebTranslations } from '../../i18n/web' import { MaritalStatus } from '../../utils/api/definitions/enums' @@ -6,10 +7,9 @@ import { useTranslation } from '../Hooks' export const Modal: React.VFC<{ isOpen onClose - position partner maritalStatus -}> = ({ isOpen, onClose, position, partner, maritalStatus }) => { +}> = ({ isOpen, onClose, partner, maritalStatus }) => { const tsln = useTranslation() const apiTrans = getTranslations(tsln._language) @@ -39,7 +39,7 @@ export const Modal: React.VFC<{ onClick={onClose} >

    -
    +

    {!partner ? apiTrans.modal.userHeading @@ -47,12 +47,13 @@ export const Modal: React.VFC<{

    {getModalString()}

    - + />
    diff --git a/components/ResultsPage/NextSteps.tsx b/components/ResultsPage/NextSteps.tsx index 8f9c8302a..12551e6f3 100644 --- a/components/ResultsPage/NextSteps.tsx +++ b/components/ResultsPage/NextSteps.tsx @@ -8,6 +8,7 @@ export function getOasNextSteps( result: any, inputAge: number, receivingOAS: boolean, + liveInCanada: boolean, nextStepText: NextStepText, apiTsln: Translations, tsln: WebTranslations @@ -53,29 +54,35 @@ export function getOasNextSteps( export function getGisNextSteps( result: any, receivingOAS: boolean, + liveInCanada: boolean, nextStepText: NextStepText, apiTsln: Translations, tsln: WebTranslations ) { - if (result.eligibility.result === ResultKey.ELIGIBLE) { + if (!liveInCanada) { nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - if (!receivingOAS) { - nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.youCanApplyGis}

    ` - if (result.entitlement.result === 0) { - nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.ifYouApply}

    ` + nextStepText.nextStepContent += apiTsln.detail.mustBeInCanada + } else { + if (result.eligibility.result === ResultKey.ELIGIBLE) { + nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + if (!receivingOAS) { + nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.youCanApplyGis}

    ` + if (result.entitlement.result === 0) { + nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.ifYouApply}

    ` + } + } else { + if (result.entitlement.result > 0) { + nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.canApplyOnline}

    ` + } else { + nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.ifYouApply}

    ` + } + nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.ifYouAlreadyApplied}

    ` } } else { - if (result.entitlement.result > 0) { - nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.canApplyOnline}

    ` - } else { - nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.ifYouApply}

    ` + if (result.eligibility.result === ResultReason.LIVING_COUNTRY) { + nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle + nextStepText.nextStepContent += `

    ${apiTsln.detail.mustBeInCanada}

    ` } - nextStepText.nextStepContent += `

    ${apiTsln.detail.gis.ifYouAlreadyApplied}

    ` - } - } else { - if (result.eligibility.result === ResultReason.LIVING_COUNTRY) { - nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - nextStepText.nextStepContent += `

    ${apiTsln.detail.mustBeInCanada}

    ` } } @@ -87,6 +94,7 @@ export function getAlwNextSteps( result: any, partnerResults: any, inputAge: number, + liveInCanada: boolean, nextStepText: NextStepText, apiTsln: Translations, tsln: WebTranslations @@ -100,28 +108,32 @@ export function getAlwNextSteps( )}.` nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - if ( - result.eligibility.result === ResultKey.ELIGIBLE || - result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE - ) { - if (result.entitlement.result > 0) { - nextStepText.nextStepContent += apiTsln.detail.alwsApply - } else { - nextStepText.nextStepContent += ifYouApplyText - } - } else if (result.eligibility.result === ResultKey.INELIGIBLE) { - nextStepText.nextStepContent += `

    ${apiTsln.detail.alw.forIndividuals}

    ` - nextStepText.nextStepContent += `
      + if (!liveInCanada) { + nextStepText.nextStepContent += apiTsln.detail.mustBeInCanada + } else { + if ( + result.eligibility.result === ResultKey.ELIGIBLE || + result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + ) { + if (result.entitlement.result > 0) { + nextStepText.nextStepContent += apiTsln.detail.alwsApply + } else { + nextStepText.nextStepContent += ifYouApplyText + } + } else if (result.eligibility.result === ResultKey.INELIGIBLE) { + nextStepText.nextStepContent += `

      ${apiTsln.detail.alw.forIndividuals}

      ` + nextStepText.nextStepContent += `
      • ${apiTsln.detail.alw.age60to64}
      • ${apiTsln.detail.alw.livingInCanada}
      • ${apiTsln.detail.alw.spouseReceives}
      ` - // if ( - // partnerResults.result.eligibility.result === ResultKey.ELIGIBLE || - // partnerResults.result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE - // ) { - // nextStepText.nextStepContent += `

      ${apiTsln.detail.alw.forIndividuals}

      ` - // } + // if ( + // partnerResults.result.eligibility.result === ResultKey.ELIGIBLE || + // partnerResults.result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + // ) { + // nextStepText.nextStepContent += `

      ${apiTsln.detail.alw.forIndividuals}

      ` + // } + } } return nextStepText @@ -131,12 +143,13 @@ export function getAlwNextSteps( export function getAlwsNextSteps( result: any, inputAge: number, + liveInCanada: boolean, nextStepText: NextStepText, apiTsln: Translations, tsln: WebTranslations ) { const ifYouApplyText = - apiTsln.detail.alwIfYouApply + + apiTsln.detail.alwsIfYouApply + `${numberToStringCurrency( legalValues.alw.afsIncomeLimit, apiTsln._language, @@ -144,22 +157,26 @@ export function getAlwsNextSteps( )}.` nextStepText.nextStepTitle = tsln.resultsPage.nextStepTitle - if ( - result.eligibility.result === ResultKey.ELIGIBLE || - result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE - ) { - if (result.entitlement.result > 0) { - nextStepText.nextStepContent += apiTsln.detail.alwsApply - } else { - nextStepText.nextStepContent += ifYouApplyText - } - } else if (result.eligibility.result === ResultKey.INELIGIBLE) { - nextStepText.nextStepContent += `

      ${apiTsln.detail.alw.forIndividuals}

      ` - nextStepText.nextStepContent += `
        + if (!liveInCanada) { + nextStepText.nextStepContent += apiTsln.detail.mustBeInCanada + } else { + if ( + result.eligibility.result === ResultKey.ELIGIBLE || + result.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + ) { + if (result.entitlement.result > 0) { + nextStepText.nextStepContent += apiTsln.detail.alwsApply + } else { + nextStepText.nextStepContent += ifYouApplyText + } + } else if (result.eligibility.result === ResultKey.INELIGIBLE) { + nextStepText.nextStepContent += `

        ${apiTsln.detail.alws.forWidowedIndividuals}

        ` + nextStepText.nextStepContent += `
        • ${apiTsln.detail.alw.age60to64}
        • ${apiTsln.detail.alw.livingInCanada}
        • -
        • ${apiTsln.detail.alw.spouseReceives}
        • +
        • ${apiTsln.detail.alws.haveNotRemarried}
        ` + } } return nextStepText diff --git a/components/ResultsPage/SummaryEstimates.tsx b/components/ResultsPage/SummaryEstimates.tsx index e2ea0b338..3d7bb7da8 100644 --- a/components/ResultsPage/SummaryEstimates.tsx +++ b/components/ResultsPage/SummaryEstimates.tsx @@ -149,7 +149,6 @@ export const SummaryEstimates: React.VFC<{ {eligible && eligible.map((benefit: BenefitResult) => { const collapsedDetails = benefit.cardDetail?.collapsedText - return ( <> {collapsedDetails && diff --git a/components/ResultsPage/index.tsx b/components/ResultsPage/index.tsx index 25a922e75..35c1b973f 100644 --- a/components/ResultsPage/index.tsx +++ b/components/ResultsPage/index.tsx @@ -4,6 +4,7 @@ import { useRef } from 'react' import { FieldInput } from '../../client-state/InputHelper' import { WebTranslations } from '../../i18n/web' import { + LivingCountry, MaritalStatus, PartnerBenefitStatus, ResultKey, @@ -133,7 +134,8 @@ const ResultsPage: React.VFC<{ const newestUser = userArrNew.map((item, index) => { if (item) { const age = Number(Object.keys(item)[0]) - const headingYear = currentYear + (age - Math.round(Number(userAge))) + const headingYear = + currentYear + (Math.trunc(age) - Math.trunc(Number(userAge))) let key if (age == 0) { key = currentYear @@ -149,7 +151,7 @@ const ResultsPage: React.VFC<{ if (item) { const age = Number(Object.keys(item)[0]) const headingYear = - currentYear + (age - Math.round(Number(partnerAge))) + currentYear + (Math.trunc(age) - Math.trunc(Number(partnerAge))) let key if (age == 0) { key = currentYear @@ -192,7 +194,9 @@ const ResultsPage: React.VFC<{ element !== null).length + } hasMultipleOasGis={multipleOAS_GIS} /> {/* Summary Estimates section */} @@ -214,6 +218,7 @@ const ResultsPage: React.VFC<{
    +
    {apiTsln.nextStepTitle}
    input.key === 'age').value) @@ -221,6 +226,10 @@ const ResultsPage: React.VFC<{ results={resultsArray} futureClientResults={futureClientResults} partnerResults={partnerResultsArray} + liveInCanada={ + inputs.find((input) => input.key === 'livingCountry').value === + LivingCountry.CANADA + } />
    ", }, nonResidentTaxPartner: { - heading: 'blablabla', - text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + heading: 'Des impôts s’appliqueront à la pension de votre conjoint', + text: "Puisque le revenu de votre conjoint est plus grand que {OAS_RECOVERY_TAX_CUTOFF} et que vous vivez à l'extérieur du Canada, vous ne recevrez pas une partie ou la totalité de votre pension de la Sécurité de la vieillesse en raison de :
    • l'{LINK_RECOVERY_TAX};
    • l'{LINK_NON_RESIDENT_TAX}.
    ", }, nonResidentTaxBoth: { - heading: 'blablabla', - text: 'Since your income is over {OAS_RECOVERY_TAX_CUTOFF}, you will have to repay some or all of your Old Age Security pension due to {LINK_RECOVERY_TAX}.', + heading: 'Des impôts s’appliqueront à vos pensions', + text: "Puisque vos revenus et ceux de votre conjoint sont plus grand que {OAS_RECOVERY_TAX_CUTOFF} et que vous vivez à l'extérieur du Canada, vous ne recevrez pas une partie ou la totalité de votre pension de la Sécurité de la vieillesse en raison de :
    • l'{LINK_RECOVERY_TAX};
    • l'{LINK_NON_RESIDENT_TAX}.
    ", }, yourDeferralOptions: { - heading: 'Your deferral options', - text: 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', - }, - deferWaitMonths: { - heading: 'Your deferral options', - text: 'You can start receiving your Old Age Security pension payments at 65 or wait until you’re 70. ', + heading: 'Vos options de report', + text: "Vous pouvez commencer à recevoir vos paiements de la pension de la Sécurité de la vieillesse à 65 ans ou attendre d'avoir 70 ans.", }, deferralDelay: { - heading: 'Your deferral options', - text: 'You can delay your pension for up to {DELAY_MONTHS} more {MONTH_MONTHS}.', + heading: 'Vos options de report', + text: 'Vous pouvez reporter votre pension pour encore {DELAY_MONTHS} mois.', }, retroactivePayment: { - heading: 'Your deferral options', - text: 'You can delay your pension for up to {DELAY_MONTHS} more {MONTH_MONTHS}.', + heading: 'Vos options de report', + text: 'Vous pouvez reporter votre pension pour encore {DELAY_MONTHS} mois.', }, mayBecomeEligible: { - heading: 'Retroactive payment', - text: 'You may be able to receive payment for up to the last 11 months.', + heading: 'Paiement rétroactif', + text: 'Vous pourriez recevoir un paiement pour un maximum des 11 derniers mois.', + }, + socialSecurityEligible: { + heading: 'Vous pourriez devenir admissible plus tôt', + text: "Vous pourriez devenir admissible plus tôt parce que vous avez vécu dans un pays avec un accord de sécurité sociale avec le Canada. Ceci pourrait affecter votre estimation. Communiquez avec nous pour plus de détails.", + }, + socialSecurityEligiblePartner: { + heading: 'Votre conjoint pourrait devenir admissible plus tôt', + text: "Votre conjoint pourrait devenir admissible plus tôt parce qu’il a vécu dans un pays avec un accord de sécurité sociale avec le Canada. Ceci pourrait affecter son estimation. Communiquez avec nous pour plus de détails.", }, }, summaryTitle: { diff --git a/i18n/api/index.ts b/i18n/api/index.ts index 85e4705f1..1acf08ebe 100644 --- a/i18n/api/index.ts +++ b/i18n/api/index.ts @@ -161,7 +161,10 @@ export interface Translations { spouseReceives: string yourPartnerCanApply: string } - alws: {} + alws: { + forWidowedIndividuals: string + haveNotRemarried: string + } } detailWithHeading: { ifYouDeferYourPension: { heading: string; text: string } @@ -181,10 +184,11 @@ export interface Translations { nonResidentTaxPartner: { heading: string; text: string } nonResidentTaxBoth: { heading: string; text: string } yourDeferralOptions: { heading: string; text: string } - deferWaitMonths: { heading: string; text: string } deferralDelay: { heading: string; text: string } retroactivePayment: { heading: string; text: string } mayBecomeEligible: { heading: string; text: string } + socialSecurityEligible: { heading: string; text: string } + socialSecurityEligiblePartner: { heading: string; text: string } } summaryTitle: { [key in SummaryState]?: string } summaryDetails: { [key in SummaryState]?: string } diff --git a/i18n/web/fr.ts b/i18n/web/fr.ts index 32138dae3..45ae9107f 100644 --- a/i18n/web/fr.ts +++ b/i18n/web/fr.ts @@ -307,7 +307,7 @@ const fr: WebTranslations = { changeInSituation: 'Si votre situation change, vos résultats pourraient changer.', youEstimateMayChange: - 'Votre estimation peut changer au fil du temps en fonction ', + 'Votre estimation peut changer au fil du temps en fonction', basedYourAge: 'de votre âge', basedYourPartner: 'des prestations que votre conjoint reçoit.', ifYouChoseToDefer: diff --git a/utils/api/benefits/alwBenefit.ts b/utils/api/benefits/alwBenefit.ts index a2c007bbf..f4597369b 100644 --- a/utils/api/benefits/alwBenefit.ts +++ b/utils/api/benefits/alwBenefit.ts @@ -299,6 +299,14 @@ export class AlwBenefit extends BaseBenefit { protected getCardCollapsedText(): CardCollapsedText[] { let cardCollapsedText = super.getCardCollapsedText() + if (this.input.everLivedSocialCountry) { + cardCollapsedText.push( + this.partner + ? this.translations.detailWithHeading.socialSecurityEligiblePartner + : this.translations.detailWithHeading.socialSecurityEligible + ) + } + if ( this.eligibility.result !== ResultKey.ELIGIBLE && this.eligibility.result !== ResultKey.INCOME_DEPENDENT diff --git a/utils/api/benefits/gisBenefit.ts b/utils/api/benefits/gisBenefit.ts index 34566c093..0dd1e7f81 100644 --- a/utils/api/benefits/gisBenefit.ts +++ b/utils/api/benefits/gisBenefit.ts @@ -280,6 +280,14 @@ export class GisBenefit extends BaseBenefit { protected getCardCollapsedText(): CardCollapsedText[] { let cardCollapsedText = super.getCardCollapsedText() + if (this.input.everLivedSocialCountry) { + cardCollapsedText.push( + this.partner + ? this.translations.detailWithHeading.socialSecurityEligiblePartner + : this.translations.detailWithHeading.socialSecurityEligible + ) + } + if ( this.eligibility.result !== ResultKey.ELIGIBLE && this.eligibility.result !== ResultKey.INCOME_DEPENDENT @@ -290,7 +298,10 @@ export class GisBenefit extends BaseBenefit { let text = '' let heading - if (this.oasResult.eligibility.result === ResultKey.ELIGIBLE) { + if ( + this.oasResult.eligibility.result === ResultKey.ELIGIBLE || + this.oasResult.eligibility.result === ResultKey.WILL_BE_ELIGIBLE + ) { if (this.oasResult.cardDetail.meta.receiveOAS == false) { heading = this.translations.detail.yourDeferralOptions if (this.oasResult.entitlement.result > 0) { @@ -307,9 +318,7 @@ export class GisBenefit extends BaseBenefit { } if (text !== '') { - if (this.entitlement.result === 0) { - text += `

    ${this.translations.detail.deferralNoGis}

    ` - } else { + if (this.entitlement.result !== 0) { text += `

    ${this.translations.detail.deferralNoGis}

    ` } diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index 15b2506b4..0a0d875a9 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -445,6 +445,14 @@ export class OasBenefit extends BaseBenefit { protected getCardCollapsedText(): CardCollapsedText[] { let cardCollapsedText = super.getCardCollapsedText() + if (this.input.everLivedSocialCountry) { + cardCollapsedText.push( + this.partner + ? this.translations.detailWithHeading.socialSecurityEligiblePartner + : this.translations.detailWithHeading.socialSecurityEligible + ) + } + // if not eligible, don't bother with any of the below if ( this.eligibility.result !== ResultKey.ELIGIBLE && @@ -497,16 +505,6 @@ export class OasBenefit extends BaseBenefit { } if (!this.partner) { - if ( - this.inputAge > 64 && - this.inputAge < 75 && - this.entitlement.result > 0 - ) { - cardCollapsedText.push( - this.translations.detailWithHeading.oasIncreaseAt75 - ) - } - //RECOVER TAX MESSAGE - if partnered better to handle it in the partnered section to access both benefits if (this.input.maritalStatus.value != MaritalStatus.PARTNERED) { if (this.clawbackAmount > 0) { @@ -522,32 +520,47 @@ export class OasBenefit extends BaseBenefit { } } - if (this.inputAge > 74 && this.entitlement.result > 0) { - cardCollapsedText.push( - this.translations.detailWithHeading.oasIncreaseAt75Applied - ) - } - if ( this.entitlement.result == 0 && this.inputAge > 64 && - this.inputAge > 70 && + this.inputAge < 70 && !this.input.receiveOAS ) { cardCollapsedText.push( - this.translations.detailWithHeading.deferWaitMonths + this.translations.detailWithHeading.deferralDelay ) } if ( this.inputAge >= 70 && !this.input.receiveOAS && - this.entitlement.result > 0 + this.entitlement.result > 0 && + this.future !== true ) { cardCollapsedText.push( this.translations.detailWithHeading.retroactivePayment ) } + + if ( + this.inputAge > 74 && + this.inputAge > 64 && + this.entitlement.result > 0 + ) { + cardCollapsedText.push( + this.translations.detailWithHeading.oasIncreaseAt75Applied + ) + } + + if ( + this.inputAge > 64 && + this.inputAge < 75 && + this.entitlement.result > 0 + ) { + cardCollapsedText.push( + this.translations.detailWithHeading.oasIncreaseAt75 + ) + } } return cardCollapsedText diff --git a/utils/api/definitions/enums.ts b/utils/api/definitions/enums.ts index c05687451..382e99779 100644 --- a/utils/api/definitions/enums.ts +++ b/utils/api/definitions/enums.ts @@ -57,6 +57,7 @@ export enum ResultKey { INVALID = 'invalid', INCOME_DEPENDENT = 'incomeDependent', WILL_BE_ELIGIBLE = 'willBeEligible', + ALMOST_ELIGIBLE = 'almostEligible', } // not displayed in the UI From 0f0a18ca1973a94e32e1accfdf77cfaaed830870 Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Tue, 8 Oct 2024 11:02:59 -0400 Subject: [PATCH 07/12] ITAO fixes --- components/Forms/Button.tsx | 13 +++--- components/ResultsPage/EstimatedTotalItem.tsx | 17 ++++++- components/ResultsPage/Intro.tsx | 2 +- components/ResultsPage/Modal.tsx | 44 ++++++++++++++++++- components/ResultsPage/index.tsx | 2 +- i18n/web/en.ts | 1 + i18n/web/fr.ts | 1 + i18n/web/index.ts | 1 + 8 files changed, 71 insertions(+), 10 deletions(-) diff --git a/components/Forms/Button.tsx b/components/Forms/Button.tsx index 67db76a21..8dd01e5f0 100644 --- a/components/Forms/Button.tsx +++ b/components/Forms/Button.tsx @@ -20,12 +20,15 @@ interface ButtonProps { type ButtonType = 'submit' | 'reset' | 'button' const BUTTON_STYLES = { - primary: 'text-white bg-[#26374A] hover:bg-[#1C578A] focus:bg-[#0E62C9]', + primary: + 'text-white bg-[#26374A] hover:bg-[#1C578A] focus:bg-[#0E62C9] visited:text-white', secondary: - 'text-[#335075] bg-[#EAEBED] hover:bg-[#CFD1D5] focus:bg-[#CFD1D5]', - supertask: 'text-white bg-[#318000] hover:bg-[#1D4D00] focus:bg-[#1D4D00]', - danger: 'text-white bg-[#BC3331] hover:bg-[#942826] focus:bg-[#942826]', - link: 'text-[#2B4380] hover:text-[#0535D2] focus:text-[#0535D2]n hover:underline focus:underline', + 'text-[#335075] visited:text-[#335075] bg-[#EAEBED] hover:bg-[#CFD1D5] focus:bg-[#CFD1D5]', + supertask: + 'text-white visited:text-white bg-[#318000] hover:bg-[#1D4D00] focus:bg-[#1D4D00]', + danger: + 'text-white visited:text-white bg-[#BC3331] hover:bg-[#942826] focus:bg-[#942826]', + link: 'text-[#2B4380] visited:text-[#2B4380] hover:text-[#0535D2] focus:text-[#0535D2]n hover:underline focus:underline', } export const Button: React.FC = ({ diff --git a/components/ResultsPage/EstimatedTotalItem.tsx b/components/ResultsPage/EstimatedTotalItem.tsx index a3178c6b3..672ba26aa 100644 --- a/components/ResultsPage/EstimatedTotalItem.tsx +++ b/components/ResultsPage/EstimatedTotalItem.tsx @@ -6,6 +6,7 @@ import { BenefitResult } from '../../utils/api/definitions/types' import { useTranslation } from '../Hooks' import { Modal } from './Modal' import Image from 'next/image' +import { Button } from '../Forms/Button' export const EstimatedTotalItem: React.VFC<{ heading: string @@ -60,15 +61,27 @@ export const EstimatedTotalItem: React.VFC<{ {displayBenefitName(heading, result.entitlement.result, displayAmount)} {result.entitlement.result == 0 && ( <> - + + +

    -

    {tsln.resultsPage.yourMonEstimateHeading}
    +

    {tsln.resultsPage.yourMonEstimateHeading}

    {estimateLength == 1 && (

    {tsln.resultsPage.changeInSituation}

    )} diff --git a/components/ResultsPage/Modal.tsx b/components/ResultsPage/Modal.tsx index 9b58b7209..74171afe2 100644 --- a/components/ResultsPage/Modal.tsx +++ b/components/ResultsPage/Modal.tsx @@ -1,4 +1,5 @@ import { Button } from '@dts-stn/service-canada-design-system' +import { useEffect, useRef } from 'react' import { getTranslations } from '../../i18n/api' import { WebTranslations } from '../../i18n/web' import { MaritalStatus } from '../../utils/api/definitions/enums' @@ -12,9 +13,46 @@ export const Modal: React.VFC<{ }> = ({ isOpen, onClose, partner, maritalStatus }) => { const tsln = useTranslation() const apiTrans = getTranslations(tsln._language) + const modalRef = useRef(null); + const firstFocusableRef = useRef(null); + const closeButtonRef = useRef(null); + + useEffect(() => { + if (isOpen) { + // Focus the first focusable element when the modal opens + firstFocusableRef.current?.focus(); + + // Event listener for trapping focus + const handleKeyDown = (event) => { + if (event.key === 'Tab') { + const focusableElements = modalRef.current.querySelectorAll( + 'button, a, input, textarea, select, [tabindex]:not([tabindex="-1"])' + ); + const firstElement = focusableElements[0]; + const lastElement = + focusableElements[focusableElements.length - 1]; + + if (event.shiftKey && document.activeElement === firstElement) { + // Shift + Tab pressed on first element: move focus to the last element + event.preventDefault(); + lastElement.focus(); + } else if (!event.shiftKey && document.activeElement === lastElement) { + // Tab pressed on the last element: move focus to the first element + event.preventDefault(); + firstElement.focus(); + } + } + }; + + document.addEventListener('keydown', handleKeyDown); + return () => document.removeEventListener('keydown', handleKeyDown); + } + }, [isOpen]) if (!isOpen) return null + + const getModalString = () => { let text = '' @@ -37,9 +75,12 @@ export const Modal: React.VFC<{
    -
    +

    {!partner ? apiTrans.modal.userHeading @@ -48,6 +89,7 @@ export const Modal: React.VFC<{

    {getModalString()}

    -
    {apiTsln.nextStepTitle}
    +

    {apiTsln.nextStepTitle}

    input.key === 'age').value) diff --git a/i18n/web/en.ts b/i18n/web/en.ts index 1b4b6fcdb..d336547ea 100644 --- a/i18n/web/en.ts +++ b/i18n/web/en.ts @@ -301,6 +301,7 @@ const en: WebTranslations = { 'EC Economics and Industry;Allowances;Benefits;Survivor benefits;Finance;Personal finance;Income;Pensions;Public pensions,PE Persons;Adults;Seniors,So Society and Culture;Old age', }, resultsPage: { + moreInformation: "Plus d'information ", yourMonEstimateHeading: 'Your monthly estimate', changeInSituation: 'Changes in your situation may impact your results.', youEstimateMayChange: 'Your estimate may change over time based on', diff --git a/i18n/web/fr.ts b/i18n/web/fr.ts index 45ae9107f..cf65d0e8f 100644 --- a/i18n/web/fr.ts +++ b/i18n/web/fr.ts @@ -303,6 +303,7 @@ const fr: WebTranslations = { homeSubject: `EC Économie et industrie;Allocation;Avantages sociaux;Prestation au survivant;Finances;Finances personnelles;Revenu;Pension;Pension publique,PE Personnes;Adulte;Aîné,SO Société et culture;Vieillesse`, }, resultsPage: { + moreInformation: 'More information on', yourMonEstimateHeading: 'Votre estimation mensuelle', changeInSituation: 'Si votre situation change, vos résultats pourraient changer.', diff --git a/i18n/web/index.ts b/i18n/web/index.ts index 7c0564f07..ee8234135 100644 --- a/i18n/web/index.ts +++ b/i18n/web/index.ts @@ -209,6 +209,7 @@ export type WebTranslations = { } //results page resultsPage: { + moreInformation: string yourMonEstimateHeading: string changeInSituation: string youEstimateMayChange: string From 5447c8b76d5cf90f7657835d46861fb125d8de8c Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Tue, 8 Oct 2024 11:14:49 -0400 Subject: [PATCH 08/12] Fix lint issues --- components/ResultsPage/EstimatedTotalItem.tsx | 38 ++++++++--------- components/ResultsPage/Modal.tsx | 41 ++++++++++--------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/components/ResultsPage/EstimatedTotalItem.tsx b/components/ResultsPage/EstimatedTotalItem.tsx index 672ba26aa..e4a57ba60 100644 --- a/components/ResultsPage/EstimatedTotalItem.tsx +++ b/components/ResultsPage/EstimatedTotalItem.tsx @@ -61,26 +61,26 @@ export const EstimatedTotalItem: React.VFC<{ {displayBenefitName(heading, result.entitlement.result, displayAmount)} {result.entitlement.result == 0 && ( <> - - + style={{ + background: 'none', + border: 'none', + padding: 0, + cursor: 'pointer', + }} + aria-label={tsln.resultsPage.moreInformation + ' ' + heading} + > + {tsln.resultsPage.moreInformation + = ({ isOpen, onClose, partner, maritalStatus }) => { const tsln = useTranslation() const apiTrans = getTranslations(tsln._language) - const modalRef = useRef(null); - const firstFocusableRef = useRef(null); - const closeButtonRef = useRef(null); + const modalRef = useRef(null) + const firstFocusableRef = useRef(null) + const closeButtonRef = useRef(null) useEffect(() => { if (isOpen) { // Focus the first focusable element when the modal opens - firstFocusableRef.current?.focus(); + firstFocusableRef.current?.focus() // Event listener for trapping focus const handleKeyDown = (event) => { if (event.key === 'Tab') { const focusableElements = modalRef.current.querySelectorAll( 'button, a, input, textarea, select, [tabindex]:not([tabindex="-1"])' - ); - const firstElement = focusableElements[0]; - const lastElement = - focusableElements[focusableElements.length - 1]; + ) + const firstElement = focusableElements[0] + const lastElement = focusableElements[focusableElements.length - 1] if (event.shiftKey && document.activeElement === firstElement) { // Shift + Tab pressed on first element: move focus to the last element - event.preventDefault(); - lastElement.focus(); - } else if (!event.shiftKey && document.activeElement === lastElement) { + event.preventDefault() + lastElement.focus() + } else if ( + !event.shiftKey && + document.activeElement === lastElement + ) { // Tab pressed on the last element: move focus to the first element - event.preventDefault(); - firstElement.focus(); + event.preventDefault() + firstElement.focus() } } - }; + } - document.addEventListener('keydown', handleKeyDown); - return () => document.removeEventListener('keydown', handleKeyDown); + document.addEventListener('keydown', handleKeyDown) + return () => document.removeEventListener('keydown', handleKeyDown) } }, [isOpen]) if (!isOpen) return null - - const getModalString = () => { let text = '' @@ -80,7 +80,10 @@ export const Modal: React.VFC<{ ref={modalRef} >
    -
    +

    {!partner ? apiTrans.modal.userHeading From 5f1c268864a625c5674be1f9b3dd4270ae0630cc Mon Sep 17 00:00:00 2001 From: Maxim Lam Date: Thu, 12 Dec 2024 10:16:08 -0500 Subject: [PATCH 09/12] Checking in batch 2 & 3 revisions as well as 4 and ITAO changes --- components/ResultsPage/BenefitCard.tsx | 4 +- components/ResultsPage/BenefitCards.tsx | 13 ++- components/ResultsPage/CTA.tsx | 4 +- components/ResultsPage/Estimation.tsx | 17 +-- components/ResultsPage/Intro.tsx | 11 +- components/ResultsPage/Modal.tsx | 10 +- components/ResultsPage/NextSteps.tsx | 123 +++++++++++--------- components/ResultsPage/SummaryEstimates.tsx | 63 ++++++---- components/ResultsPage/index.tsx | 9 ++ i18n/api/en.ts | 14 ++- i18n/api/fr.ts | 10 +- i18n/api/index.ts | 2 + i18n/web/en.ts | 2 +- utils/api/benefitHandler.ts | 4 +- utils/api/benefits/gisBenefit.ts | 29 ++--- utils/api/benefits/oasBenefit.ts | 15 +-- 16 files changed, 193 insertions(+), 137 deletions(-) diff --git a/components/ResultsPage/BenefitCard.tsx b/components/ResultsPage/BenefitCard.tsx index 0af692158..27e3317d4 100644 --- a/components/ResultsPage/BenefitCard.tsx +++ b/components/ResultsPage/BenefitCard.tsx @@ -42,8 +42,8 @@ export const BenefitCard: React.VFC<{ const eligibleFlag: JSX.Element = (

    -

    +

    {heading} -

    +

    {body}

    ", + text: "Puisque le revenu de votre conjoint est plus grand que {OAS_RECOVERY_TAX_CUTOFF} et qu’il vit à l’extérieur du Canada, il ne recevra pas une partie ou la totalité de sa pension de la Sécurité de la vieillesse en raison de :
    • l'{LINK_RECOVERY_TAX};
    • l'{LINK_NON_RESIDENT_TAX}.
    ", }, nonResidentTaxBoth: { heading: 'Des impôts s’appliqueront à vos pensions', - text: "Puisque vos revenus et ceux de votre conjoint sont plus grand que {OAS_RECOVERY_TAX_CUTOFF} et que vous vivez à l'extérieur du Canada, vous ne recevrez pas une partie ou la totalité de votre pension de la Sécurité de la vieillesse en raison de :
    • l'{LINK_RECOVERY_TAX};
    • l'{LINK_NON_RESIDENT_TAX}.
    ", + text: "Puisque vos revenus et ceux de votre conjoint sont plus grand que {OAS_RECOVERY_TAX_CUTOFF} et que vous vivez à l'extérieur du Canada, vous ne recevrez pas une partie ou la totalité de vos pensions de la Sécurité de la vieillesse en raison de :
    • l'{LINK_RECOVERY_TAX};
    • l'{LINK_NON_RESIDENT_TAX}.
    ", }, yourDeferralOptions: { heading: 'Vos options de report', diff --git a/utils/api/benefitHandler.ts b/utils/api/benefitHandler.ts index 32129542c..c657b1d79 100644 --- a/utils/api/benefitHandler.ts +++ b/utils/api/benefitHandler.ts @@ -169,7 +169,8 @@ export class BenefitHandler { false, this.input.client.age, this.formAge, - this.formYearsInCanada + this.formYearsInCanada, + this.input.client.receiveOAS ) // If the client needs help, check their partner's OAS. // no defer and defer options? @@ -217,7 +218,10 @@ export class BenefitHandler { false, this.future, true, - this.input.client.age + this.input.client.age, + this.formAge, + this.formYearsInCanada, + this.input.client.receiveOAS ) consoleDev('WITH DEFERRAL', clientOasWithDeferral) diff --git a/utils/api/benefits/alwBenefit.ts b/utils/api/benefits/alwBenefit.ts index f4597369b..1341e8e3d 100644 --- a/utils/api/benefits/alwBenefit.ts +++ b/utils/api/benefits/alwBenefit.ts @@ -313,25 +313,6 @@ export class AlwBenefit extends BaseBenefit { ) return cardCollapsedText - // partner is eligible, IF income was not provided the result = 0 - // when IF income > 0 AND invSeparated = true the amount is incorrectly calculated - // the correct amount is on the benefitHandler. - if (this.partner) { - if (this.entitlement.result > 0) { - if (this.eligibility.result !== ResultKey.INCOME_DEPENDENT) { - if (!this.input.invSeparated) { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerEligible - ) - } - } else { - cardCollapsedText.push( - this.translations.detailWithHeading.partnerDependOnYourIncome - ) - } - } - } - return cardCollapsedText } } diff --git a/utils/api/benefits/gisBenefit.ts b/utils/api/benefits/gisBenefit.ts index 7ceaddb24..c95d88e63 100644 --- a/utils/api/benefits/gisBenefit.ts +++ b/utils/api/benefits/gisBenefit.ts @@ -288,6 +288,7 @@ export class GisBenefit extends BaseBenefit { ) } + //Deferral options Expand-Collapse if (!this.partner) { let text = '' let heading @@ -302,7 +303,7 @@ export class GisBenefit extends BaseBenefit { if (this.oasResult.cardDetail.meta.receiveOAS == false) { heading = this.translations.detail.yourDeferralOptions - if (this.oasResult.entitlement.result > 0) { + if (this.oasResult.entitlement.result > 0 && ageToCheck < 70) { if (this.input.age >= 65 && this.input.age < 70) { //CHECK IF RECEIVING OAS text += this.translations.detail.deferralEligible diff --git a/utils/api/benefits/oasBenefit.ts b/utils/api/benefits/oasBenefit.ts index 40896702e..2fdd478a5 100644 --- a/utils/api/benefits/oasBenefit.ts +++ b/utils/api/benefits/oasBenefit.ts @@ -31,6 +31,7 @@ export class OasBenefit extends BaseBenefit { formAge: number formYearsInCanada: number userOas: OasBenefit + formReceiving: boolean constructor( input: ProcessedInput, translations: Translations, @@ -40,7 +41,8 @@ export class OasBenefit extends BaseBenefit { deferral: boolean = false, inputAge?: number, formAge?: number, - formYearsInCanada?: number + formYearsInCanada?: number, + formReceiving?: boolean ) { super(input, translations, BenefitKey.oas) this.partner = partner @@ -53,6 +55,7 @@ export class OasBenefit extends BaseBenefit { this.formAge = formAge this.formYearsInCanada = formYearsInCanada this.userOas = userOas + this.formReceiving = formReceiving } protected getEligibility(): EligibilityResult { @@ -470,6 +473,7 @@ export class OasBenefit extends BaseBenefit { } } + //Handle EC9 - EC14 if (this.userOas) { if ( this.eligibility.result == ResultKey.ELIGIBLE && @@ -490,11 +494,11 @@ export class OasBenefit extends BaseBenefit { if (this.clawbackAmount > 0) { if (this.input.livingCountry.value !== LivingCountry.CANADA) { cardCollapsedText.push( - this.translations.detailWithHeading.recoveryTaxPartner + this.translations.detailWithHeading.nonResidentTaxPartner ) } else { cardCollapsedText.push( - this.translations.detailWithHeading.nonResidentTaxPartner + this.translations.detailWithHeading.recoveryTaxPartner ) } } @@ -529,17 +533,17 @@ export class OasBenefit extends BaseBenefit { ) } + //EC8 if ( this.inputAge >= 70 && - !this.input.receiveOAS && - this.entitlement.result > 0 && - this.future !== true + !this.formReceiving && + this.entitlement.result > 0 ) { cardCollapsedText.push( this.translations.detailWithHeading.retroactivePayment ) } - + //EC19 && EC20 const ageCalc = this.formAge ? this.formAge : this.inputAge if (ageCalc >= 75 && this.entitlement.result > 0) {