diff --git a/messages/en.json b/messages/en.json index b5a1ef583..2e56ddb0d 100644 --- a/messages/en.json +++ b/messages/en.json @@ -25,6 +25,20 @@ "visit_cv": "Visit mini-CV", "read_more": "Read more" }, + "compensation_calculator": { + "calculator": { + "formLabel": "Salary calculator", + "educationInput": "Education", + "yearInput": "The year you started in relevant work", + "bonusResult": "+ bonus", + "resultLabel": "Your annual salary" + }, + "degreeOptions": { + "bachelor": "Bachelor", + "master": "Master" + } + }, + "employee_card": { "show": "Showing", "of": "out of", diff --git a/messages/no.json b/messages/no.json index 05c59f0c9..1a142a983 100644 --- a/messages/no.json +++ b/messages/no.json @@ -21,6 +21,19 @@ "contact_sale": "Kontakt salg!", "contact_us": "Kontakt oss" }, + "compensation_calculator": { + "calculator": { + "formLabel": "Lønnskalkulator", + "educationInput": "Utdanning", + "yearInput": "Året du begynte i relevant arbeid", + "bonusResult": "+ bonus", + "resultLabel": "Din årslønn" + }, + "degreeOptions": { + "bachelor": "Bachelor", + "master": "Master" + } + }, "custom_link": { "visit_cv": "Gå til mini-CV", "read_more": "Les mer" diff --git a/messages/se.json b/messages/se.json index a3ccb0c0f..e88f3a4b3 100644 --- a/messages/se.json +++ b/messages/se.json @@ -21,6 +21,19 @@ "contact_sale": "Kontakta sälj!", "contact_us": "Kontakt oss" }, + "compensation_calculator": { + "calculator": { + "formLabel": "Lönskalkulator", + "educationInput": "Utbildning", + "yearInput": "Året du började i relevant arbete", + "bonusResult": "+ bonus", + "resultLabel": "Din årslön" + }, + "degreeOptions": { + "bachelor": "Bachelor", + "master": "Master" + } + }, "custom_link": { "visit_cv": "Besök mini-CV", "read_more": "Läs mer" diff --git a/src/components/sections/compensation-calculator/Calculator.tsx b/src/components/sections/compensation-calculator/Calculator.tsx index 057365e0a..2bdbf137b 100644 --- a/src/components/sections/compensation-calculator/Calculator.tsx +++ b/src/components/sections/compensation-calculator/Calculator.tsx @@ -15,6 +15,7 @@ import { Result } from "studio/utils/result"; import styles from "./compensation-calculator.module.css"; import { Degree, SalaryData } from "./types"; +import { useTranslations } from "next-intl"; type CalculatorProps = { localeRes: Promise; @@ -24,11 +25,6 @@ type CalculatorProps = { initialYear: number; }; -const degreeOptions: IOption[] = [ - { id: "bachelor", label: "Bachelor" }, - { id: "master", label: "Master" }, -]; - export default function Calculator({ localeRes, salariesRes, @@ -36,6 +32,7 @@ export default function Calculator({ initialYear, background, }: CalculatorProps) { + const t = useTranslations("compensation_calculator"); const locale = use(localeRes); const salaries = use(salariesRes); const [year, setYear] = useState(initialYear); @@ -48,13 +45,22 @@ export default function Calculator({ return null; } + const { min, max } = getMinMaxYear(salaries.value); const salary = calculateSalary(year, degree, salaries.value) ?? 0; + const degreeOptions: IOption[] = [ + { id: "bachelor", label: t("degreeOptions.bachelor") }, + { id: "master", label: t("degreeOptions.master") }, + ]; + return ( -
+ setYear(parseInt(value))} required @@ -78,13 +84,20 @@ export default function Calculator({ {salary !== null ? (
- Din årslønn + {t("calculator.resultLabel")} {formatAsCurrency(salary, locale.locale, locale.currency)} - + bonus + {t("calculator.bonusResult")}
) : null} ); } + +function getMinMaxYear(salaries: SalaryData) { + const years = Object.keys(salaries).map((s) => parseInt(s)); + const min = Math.min(...years); + const max = Math.max(...years); + return { min, max }; +} diff --git a/src/components/sections/compensation-calculator/CompensationCalculator.tsx b/src/components/sections/compensation-calculator/CompensationCalculator.tsx index bfcb71b77..eb8d1e611 100644 --- a/src/components/sections/compensation-calculator/CompensationCalculator.tsx +++ b/src/components/sections/compensation-calculator/CompensationCalculator.tsx @@ -12,6 +12,7 @@ import { loadStudioQuery } from "studio/lib/store"; import { getHandbookLinksFromCompensationPage, getSalaryByYear } from "./api"; import Calculator from "./Calculator"; import styles from "./compensation-calculator.module.css"; +import { cnIf } from "src/utils/css"; export interface CompensationCalculatorProps { language: string; @@ -28,20 +29,17 @@ export default async function CompensationCalculator({ ); const handbookLinksRes = await getHandbookLinksFromCompensationPage(language); - // TODO: add cn util or andIf - const calculatorBgClassname = - section.background === "violet" - ? `${styles.calculator} ${styles["calculator--violet"]}` - : styles.calculator; - const handbookBgClassname = - section.background === "violet" - ? `${styles.handbook} ${styles["handbook--violet"]}` - : styles.handbook; + const calculatorBgClassname = cnIf({ + [styles.calculator]: true, + [styles["calculator--violet"]]: section.background === "violet", + }); + const handbookBgClassname = cnIf({ + [styles.handbook]: true, + [styles["handbook--violet"]]: section.background === "violet", + }); const radioBackground = section.background === "violet" ? "light" : "dark"; - // @TODO add proper translations - return (
{section.moduleTitle} diff --git a/src/utils/css.ts b/src/utils/css.ts new file mode 100644 index 000000000..570256b97 --- /dev/null +++ b/src/utils/css.ts @@ -0,0 +1,9 @@ +export function cn(...classes: (string | undefined)[]) { + return classes.filter(Boolean).join(" "); +} +export function cnIf(classes: Record) { + return Object.entries(classes) + .filter(([, value]) => value) + .map(([key]) => key) + .join(" "); +}