Skip to content

Commit

Permalink
fix(web): Pension calculator results - Only fetch preview if selected…
Browse files Browse the repository at this point in the history
… year is the most recent one (#16751)

* Only fetch preview if selected year is the most recent one

* Overwrite what date gets sent to backend

* Add function for comparing years

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and robertaandersen committed Nov 7, 2024
1 parent 5876c53 commit df50dff
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,14 @@ const PensionCalculatorResults: CustomScreen<PensionCalculatorResultsProps> = ({
)
}

const isSameYear = (
date1: string | null | undefined,
date2: string | null | undefined,
) => {
if (!date1 || !date2) return false
return new Date(date1).getFullYear() === new Date(date2).getFullYear()
}

PensionCalculatorResults.getProps = async ({
apolloClient,
locale,
Expand All @@ -614,6 +622,7 @@ PensionCalculatorResults.getProps = async ({
}) => {
const calculationInput = convertQueryParametersToCalculationInput(query)
const slug = extractSlug(locale, customPageData)
const dateOfCalculationsOptions = getDateOfCalculationsOptions(customPageData)
const [
{
data: { getOrganizationPage },
Expand Down Expand Up @@ -654,14 +663,17 @@ PensionCalculatorResults.getProps = async ({
}),
calculationInput.typeOfBasePension ===
SocialInsurancePensionCalculationBasePensionType.Disability &&
is2025PreviewActive(customPageData)
is2025PreviewActive(customPageData) &&
isSameYear(
dateOfCalculationsOptions?.[0]?.value,
calculationInput.dateOfCalculations,
)
? apolloClient.query<Query, QueryGetPensionCalculationArgs>({
query: GET_PENSION_CALCULATION,
variables: {
input: {
...calculationInput,
startYear: 2025,
startMonth: 9,
dateOfCalculations: new Date(2025, 8, 1).toISOString(),
typeOfBasePension:
SocialInsurancePensionCalculationBasePensionType.NewSystem,
},
Expand Down Expand Up @@ -700,7 +712,7 @@ PensionCalculatorResults.getProps = async ({
calculation: getPensionCalculation,
calculation2025: getPensionCalculation2025,
calculationInput,
dateOfCalculationsOptions: getDateOfCalculationsOptions(customPageData),
dateOfCalculationsOptions,
queryParamString: queryParams.toString(),
...getThemeConfig(
getOrganizationPage?.theme,
Expand Down

0 comments on commit df50dff

Please sign in to comment.