Skip to content

Commit

Permalink
Merge pull request #946 from DTS-STN/133488-remove-on-this-page
Browse files Browse the repository at this point in the history
133488-Remove "on this page" and ListLinks component
  • Loading branch information
Maxim-Lam authored Nov 15, 2023
2 parents c201db2 + 4eb4269 commit 7d51208
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 174 deletions.
28 changes: 0 additions & 28 deletions components/ResultsPage/ListLinks.tsx

This file was deleted.

108 changes: 0 additions & 108 deletions components/ResultsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import {
import { useTranslation } from '../Hooks'
import { BenefitCards } from './BenefitCards'
import { EstimatedTotal } from './EstimatedTotal'
import { ListLinks } from './ListLinks'
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 { flattenArray, getSortedListLinks } from './utils'

const getEligibility = (
resultsEligible: BenefitResult[],
Expand Down Expand Up @@ -81,118 +79,12 @@ const ResultsPage: React.VFC<{
result.eligibility?.result === ResultKey.INCOME_DEPENDENT
)

// FUTURE CLIENT
const futureClientEligibleArray = flattenArray(futureClientResults)

// FUTURE PARTNER
const futurePartnerEligibleArray = flattenArray(futurePartnerResults)

const getListLinks: any = () => {
const getFirstLinks = () => {
const tempLinks = []

if (resultsEligible.length !== 0) {
tempLinks.push({
text: tsln.resultsPage.yourEstimatedTotal,
url: '#estimate',
})
}

if (
resultsEligible.length === 0 &&
futureClientEligibleArray.length === 0
) {
tempLinks.push({
text: tsln.resultsPage.youAreNotEligible,
url: '#estimate',
})
}

if (futureClientEligibleArray.length !== 0) {
tempLinks.push({
text: tsln.resultsPage.futureEligible,
url: '#future-estimate',
})
}

if (isPartnered && partnerResultsEligible.length !== 0) {
tempLinks.push({
text: tsln.resultsPage.partnerEstimatedTotal,
url: '#partner-estimate',
})
}

if (
isPartnered &&
partnerResultsEligible.length === 0 &&
futurePartnerEligibleArray.length === 0
) {
tempLinks.push({
text: tsln.resultsPage.partnerNotEligible,
url: '#partner-estimate',
})
}

if (isPartnered && futurePartnerEligibleArray.length !== 0) {
tempLinks.push({
text: tsln.resultsPage.partnerFutureEligible,
url: '#future-partner-estimate',
})
}

return tempLinks
}

let listLinks: any = [
...getFirstLinks(),
{
text: tsln.resultsPage.whatYouToldUs,
url: '#answers',
},
{
text: apiTsln.benefit['oas'],
id: 'oas',
url: '#oas',
eligible: getEligibility(resultsEligible, 'oas'),
},
{
text: apiTsln.benefit['gis'],
id: 'gis',
url: '#gis',
eligible: getEligibility(resultsEligible, 'gis'),
},
{
text: apiTsln.benefit['alw'],
id: 'alw',
url: '#alw',
eligible: getEligibility(resultsEligible, 'alw'),
},
{
text: apiTsln.benefit['alws'],
id: 'alws',
url: '#alws',
eligible: getEligibility(resultsEligible, 'alws'),
},
]

// Get sorted list links based on eligibility, filtering out link items which text is empty
return getSortedListLinks(
listLinks.filter((ll) => ll.text),
futureClientEligibleArray
)
}

return (
<div className="flex flex-col space-y-12" ref={ref}>
<div className="md:grid md:grid-cols-3 md:gap-12">
<div className="col-span-2 row-span-1">
<div dangerouslySetInnerHTML={{ __html: tsln.resultsPage.general }} />

<ListLinks
title={tsln.resultsPage.onThisPage}
links={getListLinks()}
/>

{resultsEligible.length > 0 && (
<EstimatedTotal
resultsEligible={resultsEligible}
Expand Down
38 changes: 0 additions & 38 deletions components/ResultsPage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,3 @@ export function omitCommonBenefitKeys(array1, array2) {
return !array2.some((item2) => item2.benefitKey === item1.benefitKey)
})
}

export function getSortedListLinks(listLinkArray, futureClientEligibleArray) {
const sortArray = (a, b) => {
if (a.eligible == null || b.eligible == null) {
return 0
}
if (a.eligible && !b.eligible) {
return -1
}
if (!a.eligible && b.eligible) {
return 1
}

// This accounts for future planning results and preserves the order of links as they appear in the future eligible array
if (!a.eligible && !b.eligible) {
let aIndex = futureClientEligibleArray.findIndex(
(benefit) => benefit.benefitKey === a.id
)
let bIndex = futureClientEligibleArray.findIndex(
(benefit) => benefit.benefitKey === b.id
)

if (aIndex > -1 && bIndex > -1) {
return aIndex - bIndex
}
if (aIndex > -1) {
return -1
}
if (bIndex > -1) {
return 1
}
}

return 0
}

return listLinkArray.sort(sortArray)
}

0 comments on commit 7d51208

Please sign in to comment.