diff --git a/src/components/forms/radioButtonGroup/RadioButtonGroup.tsx b/src/components/forms/radioButtonGroup/RadioButtonGroup.tsx index 98bb57490..8ce8c67f5 100644 --- a/src/components/forms/radioButtonGroup/RadioButtonGroup.tsx +++ b/src/components/forms/radioButtonGroup/RadioButtonGroup.tsx @@ -7,63 +7,27 @@ export interface IOption { id: string; label: string; disabled?: boolean; - currentSelected: boolean; -} - -interface RenderOptionsProps { - options: IOption[]; - onChange: (e: React.ChangeEvent) => void; } interface RadioButtonGroupProps { id: string; label: string; options: IOption[]; + selectedId: string; onValueChange: (option: IOption) => void; } -/** - * Important Note on RadioButtons: - * - * - The `RadioButton` component, defined in this code, should not be used in isolation. - * Radio buttons are designed to be part of a group where only one option can be selected at a time. - * - * - When used individually, a radio button loses its intended functionality of providing mutually exclusive choices - * and may confuse users or lead to unexpected behavior. - * - * - Instead, radio buttons should always be used within a group, typically managed by a parent component - * such as `RadioButtonGroup`, which ensures that only one radio button in the group can be selected at any given time. - * - * - The parent component should handle the state management and changes, ensuring that the user can only select - * one option from the group and that this selection is properly communicated back to the application. - * - * - Example of usage within a group: - * - * ``` - * const options = [ - * { id: 'radio1', label: 'Option 1', value: '1', currentSelected: false }, - * { id: 'radio2', label: 'Option 2', value: '2', currentSelected: true }, - * ]; - * - * console.log(`Selected ${name}: ${value}`)} - * /> - * ``` - * - In this example, the `RadioButtonGroup` component renders multiple `RadioButton` components - * as part of a cohesive group, enabling proper radio button functionality. - */ - export const RadioButtonGroup = ({ id, label, options, + selectedId, onValueChange, }: RadioButtonGroupProps) => { - const handleChange = (e: React.ChangeEvent) => { - const selectedOption = options.find((option) => option.id === e.target.id); + const onChange = (e: React.ChangeEvent) => { + const selectedOption = options.find( + (option) => option.id === e.target.value + ); if (selectedOption) { onValueChange(selectedOption); } @@ -73,27 +37,19 @@ export const RadioButtonGroup = ({
{label}
- + {options.map(({ id, label, disabled }) => ( + + ))}
); -}; - -const RenderOptions = ({ options, onChange }: RenderOptionsProps) => { - return ( - <> - {options.map(({ id, label, disabled, currentSelected }) => ( - - ))} - - ); -}; +}; \ No newline at end of file diff --git a/src/salaryAndBenefits/SalaryAndBenefits.tsx b/src/salaryAndBenefits/SalaryAndBenefits.tsx index a061e4a83..999c14d47 100644 --- a/src/salaryAndBenefits/SalaryAndBenefits.tsx +++ b/src/salaryAndBenefits/SalaryAndBenefits.tsx @@ -1,5 +1,4 @@ "use client"; - import styles from "./salaryAndBenefits.module.css"; import Text from "src/components/text/Text"; import { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits"; @@ -8,11 +7,7 @@ import SalaryCalculator, { Degree, } from "./components/salaryCalculator/SalaryCalculator"; import { useState } from "react"; -import { - calculatePension, - calculateSalary, - maxExperience, -} from "./utils/calculateSalary"; +import { calculatePension, calculateSalary } from "./utils/calculateSalary"; interface SalaryAndBenefitsProps { salaryAndBenefits: SalaryAndBenefitsPage; @@ -25,8 +20,6 @@ interface SalaryCalculatorFormState { const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => { const currentYear = new Date().getFullYear(); - const minExaminationYear = maxExperience(currentYear); - const maxExaminationYear = currentYear - 1; const [formState, setFormState] = useState({ examinationYear: currentYear - 1, @@ -54,8 +47,8 @@ const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => { calculateSalary( currentYear, formState.examinationYear, - formState.selectedDegree, - ), + formState.selectedDegree + ) ); }; @@ -63,24 +56,24 @@ const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => {
{salaryAndBenefits.basicTitle} {salaryAndBenefits.showSalaryCalculator && ( - + <> + + {salary !== null ? ( +
+ Du vil få en årlig lønn på {salary} + + Du vil få en årlig pensjon på omtrent {calculatePension(salary)} + +
+ ) : null} + )} - {salary !== null ? ( -
- Du vil få en årlig lønn på {salary} - - Du vil få en årlig pensjon på omtrent {calculatePension(salary)} - -
- ) : null}
{salaryAndBenefits.benefits.map((benefit) => (
diff --git a/src/salaryAndBenefits/components/salaryCalculator/SalaryCalculator.tsx b/src/salaryAndBenefits/components/salaryCalculator/SalaryCalculator.tsx index f6fb28f9d..3db2ef89f 100644 --- a/src/salaryAndBenefits/components/salaryCalculator/SalaryCalculator.tsx +++ b/src/salaryAndBenefits/components/salaryCalculator/SalaryCalculator.tsx @@ -5,36 +5,34 @@ import { RadioButtonGroup, } from "src/components/forms/radioButtonGroup/RadioButtonGroup"; import Button from "src/components/buttons/Button"; +import { maxExperience } from "src/salaryAndBenefits/utils/calculateSalary"; export type Degree = "bachelor" | "master"; const degreeOptions: IOption[] = [ - { - id: "bachelor", - label: "Bachelor", - currentSelected: true, - disabled: false, - }, - { id: "master", label: "Master", currentSelected: false, disabled: false }, + { id: "bachelor", label: "Bachelor" }, + { id: "master", label: "Master" }, ]; interface SalaryCalculatorProps { - examinationYear: number; - minExaminationYear: number; - maxExaminationYear: number; + examinationYearValue: number; + selectedDegree: Degree; onDegreeChanged: (degree: Degree) => void; onExaminationYearChanged: (examinationYear: number) => void; onSubmit: (event: React.FormEvent) => void; } export default function SalaryCalculator({ - examinationYear, - minExaminationYear, - maxExaminationYear, + examinationYearValue: yearValue, + selectedDegree, onDegreeChanged, onExaminationYearChanged, onSubmit, }: SalaryCalculatorProps) { + const currentYear = new Date().getFullYear(); + const minExaminationYear = maxExperience(currentYear); + const maxExaminationYear = currentYear - 1; + return (
- (value.id === "bachelor" || value.id === "master") && - onDegreeChanged(value.id) + selectedId={selectedDegree} + onValueChange={(selectedOption) => + onDegreeChanged(selectedOption.id as Degree) } /> onExaminationYearChanged(parseInt(value))} required /> diff --git a/studio/lib/queries/pages.ts b/studio/lib/queries/pages.ts index b2a52e399..37d140c10 100644 --- a/studio/lib/queries/pages.ts +++ b/studio/lib/queries/pages.ts @@ -15,7 +15,43 @@ const SECTIONS_FRAGMENT = groq` } } } - } + }, + _type == "article" => { + ..., + link { + ..., + linkType == "internal" => { + ..., + "internalLink": internalLink->{ + "_ref": slug.current + } + } + } + }, + _type == "callout" => { + ..., + link { + ..., + linkType == "internal" => { + ..., + "internalLink": internalLink->{ + "_ref": slug.current + } + } + } + }, + _type == "ctaSection" => { + ..., + callToActions[] { + ..., + linkType == "internal" => { + ..., + "internalLink": internalLink->{ + "_ref": slug.current + } + } + } + }, } `;