From c8331d1fe3436707f574fba2ce7f280c444a2e57 Mon Sep 17 00:00:00 2001 From: Mikael Brevik Date: Wed, 4 Dec 2024 10:42:45 +0100 Subject: [PATCH] feat: adds general handbook links to compensation site --- .../compensation-calculator/Calculator.tsx | 4 ---- .../CompensationCalculator.tsx | 11 ++++++++- .../sections/compensation-calculator/api.ts | 23 ++++++++++++++++++- studio/lib/interfaces/compensations.ts | 3 +++ studio/lib/queries/specialPages.ts | 13 +++++++++-- studio/schemas/documents/compensations.ts | 11 +++++++++ 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/components/sections/compensation-calculator/Calculator.tsx b/src/components/sections/compensation-calculator/Calculator.tsx index 48774db29..e9d7d3575 100644 --- a/src/components/sections/compensation-calculator/Calculator.tsx +++ b/src/components/sections/compensation-calculator/Calculator.tsx @@ -2,7 +2,6 @@ import { use, useState } from "react"; -import Button from "src/components/buttons/Button"; import { calculateSalary } from "src/components/compensations/utils/salary"; import InputField from "src/components/forms/inputField/InputField"; import { @@ -120,9 +119,6 @@ function SalaryCalculator({ required /> - ); } diff --git a/src/components/sections/compensation-calculator/CompensationCalculator.tsx b/src/components/sections/compensation-calculator/CompensationCalculator.tsx index 21d2735c7..3c5ba38c8 100644 --- a/src/components/sections/compensation-calculator/CompensationCalculator.tsx +++ b/src/components/sections/compensation-calculator/CompensationCalculator.tsx @@ -7,7 +7,7 @@ import { CompensationCalculatorSection } from "studio/lib/interfaces/pages"; import { LOCALE_QUERY } from "studio/lib/queries/locale"; import { loadStudioQuery } from "studio/lib/store"; -import { getSalaryByYear } from "./api"; +import { getHandbookLinksFromCompensationPage, getSalaryByYear } from "./api"; import Calculator from "./Calculator"; import styles from "./compensation-calculator.module.css"; @@ -24,6 +24,7 @@ export default async function CompensationCalculator({ const localeRes = loadStudioQuery(LOCALE_QUERY).then( (d) => d.data, ); + const handbookLinksRes = await getHandbookLinksFromCompensationPage(language); // TODO: add cn util or andIf const calculatorBgClassname = @@ -65,6 +66,14 @@ export default async function CompensationCalculator({ {section.handbookBlock.handbookDescription} + {handbookLinksRes.ok && ( +
+ {handbookLinksRes.value.map((link) => ( + + ))} +
+ )} + {section.handbookBlock.handbookLink && ( )} diff --git a/src/components/sections/compensation-calculator/api.ts b/src/components/sections/compensation-calculator/api.ts index 1f1f1f5e1..30ed9ac2c 100644 --- a/src/components/sections/compensation-calculator/api.ts +++ b/src/components/sections/compensation-calculator/api.ts @@ -1,10 +1,31 @@ import { isSalariesType } from "studio/components/salariesInput/utils/parseSalaries"; -import { COMPENSATIONS_SALARY_BY_YEAR } from "studio/lib/queries/specialPages"; +import { ILink } from "studio/lib/interfaces/navigation"; +import { + COMPENSATIONS_HANDBOOK_LINKS, + COMPENSATIONS_SALARY_BY_YEAR, +} from "studio/lib/queries/specialPages"; import { loadStudioQuery } from "studio/lib/store"; import { Result, ResultError, ResultOk } from "studio/utils/result"; import { SalaryData } from "./types"; +export async function getHandbookLinksFromCompensationPage( + language: string, +): Promise> { + const res = await loadStudioQuery<{ handbookLinks: ILink[] }>( + COMPENSATIONS_HANDBOOK_LINKS, + { language }, + { + cache: "force-cache", + next: { + revalidate: 60 * 60, + }, + }, + ); + + return ResultOk(res.data.handbookLinks); +} + export async function getSalaryByYear( year: number, language: string, diff --git a/studio/lib/interfaces/compensations.ts b/studio/lib/interfaces/compensations.ts index c5527afbd..b9cfd8e6f 100644 --- a/studio/lib/interfaces/compensations.ts +++ b/studio/lib/interfaces/compensations.ts @@ -2,6 +2,8 @@ import { PortableTextBlock, Reference } from "sanity"; import { SeoData } from "src/utils/seo"; +import { ILink } from "./navigation"; + export interface Benefit { _type: string; _key: string; @@ -86,5 +88,6 @@ export interface CompensationsPage { bonusesByLocation: BonusesByLocationPage[]; salariesByLocation: SalariesByLocation[]; showSalaryCalculator: boolean; + handbookLinks: ILink[]; seo: SeoData; } diff --git a/studio/lib/queries/specialPages.ts b/studio/lib/queries/specialPages.ts index 54bc831c4..0cd9b4fd2 100644 --- a/studio/lib/queries/specialPages.ts +++ b/studio/lib/queries/specialPages.ts @@ -1,6 +1,6 @@ import { groq } from "next-sanity"; -import { LANGUAGE_FIELD_FRAGMENT } from "./i18n"; +import { LANGUAGE_FIELD_FRAGMENT, TRANSLATED_LINK_FRAGMENT } from "./i18n"; import { translatedFieldFragment } from "./utils/i18n"; //Compensations @@ -44,9 +44,18 @@ export const COMPENSATIONS_SALARY_BY_YEAR = groq` "yearlySalaries": yearlySalaries[0] { ... } - }, + } + } +`; +export const COMPENSATIONS_HANDBOOK_LINKS = groq` + *[_type == "compensations"][0] { + "handbookLinks": handbookLinks[] { + ..., + ${TRANSLATED_LINK_FRAGMENT} + } } `; + export const COMPENSATIONS_PAGE_SITEMAP_QUERY = groq` *[_type == "compensations"][0] { _updatedAt, diff --git a/studio/schemas/documents/compensations.ts b/studio/schemas/documents/compensations.ts index 7aa300b1b..0f4f91bef 100644 --- a/studio/schemas/documents/compensations.ts +++ b/studio/schemas/documents/compensations.ts @@ -6,6 +6,7 @@ import { benefitsByLocation } from "studio/schemas/objects/compensations/benefit import { bonusesByLocation } from "studio/schemas/objects/compensations/bonusesByLocation"; import { pensionPercent } from "studio/schemas/objects/compensations/pension"; import { salariesByLocation } from "studio/schemas/objects/compensations/salariesByLocation"; +import { link } from "studio/schemas/objects/link"; import { titleSlug } from "studio/schemas/schemaTypes/slug"; import { firstTranslation } from "studio/utils/i18n"; @@ -39,6 +40,16 @@ const compensations = defineType({ bonusesByLocation, benefitsByLocation, salariesByLocation, + + defineField({ + name: "handbookLinks", + title: "Handbook Section Links", + description: + "Ordered links to sections in handbook to show important information when it comes to benefints. Used by compensation calculator module.", + type: "array", + of: [link], + }), + { name: "seo", type: "internationalizedArraySeo",