Skip to content

Commit

Permalink
feat: adds general handbook links to compensation site
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr committed Dec 4, 2024
1 parent 967529e commit c8331d1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -120,9 +119,6 @@ function SalaryCalculator({
required
/>
</div>
<Button type="secondary" size="small">
Regn ut
</Button>
</form>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -24,6 +24,7 @@ export default async function CompensationCalculator({
const localeRes = loadStudioQuery<LocaleDocument>(LOCALE_QUERY).then(
(d) => d.data,
);
const handbookLinksRes = await getHandbookLinksFromCompensationPage(language);

// TODO: add cn util or andIf
const calculatorBgClassname =
Expand Down Expand Up @@ -65,6 +66,14 @@ export default async function CompensationCalculator({
{section.handbookBlock.handbookDescription}
</Text>

{handbookLinksRes.ok && (
<div className={styles.handbookLinks}>
{handbookLinksRes.value.map((link) => (
<LinkButton key={link.url} link={link} />
))}
</div>
)}

{section.handbookBlock.handbookLink && (
<LinkButton link={section.handbookBlock.handbookLink} />
)}
Expand Down
23 changes: 22 additions & 1 deletion src/components/sections/compensation-calculator/api.ts
Original file line number Diff line number Diff line change
@@ -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<Result<ILink[], unknown>> {
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,
Expand Down
3 changes: 3 additions & 0 deletions studio/lib/interfaces/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,5 +88,6 @@ export interface CompensationsPage {
bonusesByLocation: BonusesByLocationPage[];
salariesByLocation: SalariesByLocation[];
showSalaryCalculator: boolean;
handbookLinks: ILink[];
seo: SeoData;
}
13 changes: 11 additions & 2 deletions studio/lib/queries/specialPages.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions studio/schemas/documents/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c8331d1

Please sign in to comment.