diff --git a/src/components/sections/compensation-calculator/CompensationCalculator.tsx b/src/components/sections/compensation-calculator/CompensationCalculator.tsx index 65ad1a246..cbb7e4897 100644 --- a/src/components/sections/compensation-calculator/CompensationCalculator.tsx +++ b/src/components/sections/compensation-calculator/CompensationCalculator.tsx @@ -5,12 +5,13 @@ import LinkButton from "src/components/linkButton/LinkButton"; import Text from "src/components/text/Text"; import { cnIf } from "src/utils/css"; import { getHref } from "src/utils/link"; -import { LocaleDocument } from "studio/lib/interfaces/locale"; import { CompensationCalculatorSection } from "studio/lib/interfaces/pages"; -import { LOCALE_QUERY } from "studio/lib/queries/locale"; -import { loadStudioQuery } from "studio/lib/store"; -import { getHandbookLinksFromCompensationPage, getSalaryByYear } from "./api"; +import { + getHandbookLinksFromCompensationPage, + getLatestSalaries, + getLocale, +} from "./api"; import Calculator from "./Calculator"; import styles from "./compensation-calculator.module.css"; @@ -23,10 +24,9 @@ export default async function CompensationCalculator({ section, language, }: CompensationCalculatorProps) { - const salariesRes = getSalaryByYear(2024, language); - const localeRes = loadStudioQuery(LOCALE_QUERY).then( - (d) => d.data, - ); + const salariesRes = getLatestSalaries(); + const localeRes = getLocale(); + const handbookLinksRes = await getHandbookLinksFromCompensationPage(language); const calculatorBgClassname = cnIf({ diff --git a/src/components/sections/compensation-calculator/api.ts b/src/components/sections/compensation-calculator/api.ts index 30ed9ac2c..c5435c05a 100644 --- a/src/components/sections/compensation-calculator/api.ts +++ b/src/components/sections/compensation-calculator/api.ts @@ -1,5 +1,7 @@ import { isSalariesType } from "studio/components/salariesInput/utils/parseSalaries"; +import { LocaleDocument } from "studio/lib/interfaces/locale"; import { ILink } from "studio/lib/interfaces/navigation"; +import { LOCALE_QUERY } from "studio/lib/queries/locale"; import { COMPENSATIONS_HANDBOOK_LINKS, COMPENSATIONS_SALARY_BY_YEAR, @@ -26,19 +28,19 @@ export async function getHandbookLinksFromCompensationPage( return ResultOk(res.data.handbookLinks); } -export async function getSalaryByYear( - year: number, - language: string, -): Promise> { +export async function getLocale() { + const res = await loadStudioQuery(LOCALE_QUERY); + return res.data; +} + +export async function getLatestSalaries(): Promise< + Result +> { const res = await loadStudioQuery<{ - slug: string; salariesByLocation: { yearlySalaries: { salaries: string } }; }>( COMPENSATIONS_SALARY_BY_YEAR, - { - year, - language, - }, + {}, { cache: "force-cache", next: { @@ -52,7 +54,7 @@ export async function getSalaryByYear( res.data.salariesByLocation.yearlySalaries.salaries, ); - if (!isSalariesType(parsedSalaries) || !parsedSalaries[year]) { + if (!isSalariesType(parsedSalaries)) { return ResultError("Parsed salaries data was not valid"); } diff --git a/studio/lib/queries/specialPages.ts b/studio/lib/queries/specialPages.ts index 0cd9b4fd2..2c040affa 100644 --- a/studio/lib/queries/specialPages.ts +++ b/studio/lib/queries/specialPages.ts @@ -26,20 +26,12 @@ export const COMPENSATIONS_PAGE_BY_SLUG_QUERY = groq` }, } `; -export const COMPENSATIONS_SALARIES = groq` - *[_type == "compensations"][0] { - "slug": ${translatedFieldFragment("slug")}, - "salariesByLocation": salariesByLocation[] { - ... - }, - } -`; // Just select the first location and the first year.. -// @TODO: make this a bit more robust. +// @TODO: Check if we need to make this more robust, +// but yearlySalaries is sorted by year so [0] should be the latest export const COMPENSATIONS_SALARY_BY_YEAR = groq` *[_type == "compensations"][0] { - "slug": ${translatedFieldFragment("slug")}, "salariesByLocation": salariesByLocation[0] { "yearlySalaries": yearlySalaries[0] { ...