-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add salary calculator based on legacy site
Co-authored-by: Ane <[email protected]>
- Loading branch information
Showing
14 changed files
with
275 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/components/forms/radioButtonGroup/radioButtonGroup.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.fieldset{ | ||
border: 0 none; | ||
padding: 0; | ||
} | ||
|
||
.wrapper { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,96 @@ | ||
"use client"; | ||
|
||
import styles from "./salaryAndBenefits.module.css"; | ||
import Text from "src/components/text/Text"; | ||
import {SalaryAndBenefits as SalaryAndBenefitsPayload} from "studio/lib/payloads/salaryAndBenefits"; | ||
import Benefit from './components/benefit/Benefit'; | ||
import SalaryCalculator, { | ||
Degree, | ||
} from "./components/salaryCalculator/SalaryCalculator"; | ||
import { useState } from "react"; | ||
import { | ||
calculatePension, | ||
calculateSalary, | ||
maxExperience, | ||
} from "./utils/calculateSalary"; | ||
import { SalaryAndBenefitsPage } from "studio/lib/payloads/salaryAndBenefits"; | ||
import { RichText } from "src/components/richText/RichText"; | ||
|
||
interface SalaryAndBenefitsProps { | ||
salaryAndBenefits: SalaryAndBenefitsPayload | ||
salaryAndBenefits: SalaryAndBenefitsPage; | ||
} | ||
|
||
interface SalaryCalculatorFormState { | ||
examinationYear: number; | ||
selectedDegree: Degree; | ||
} | ||
|
||
const SalaryAndBenefits = ({salaryAndBenefits}: SalaryAndBenefitsProps) => { | ||
const SalaryAndBenefits = ({ salaryAndBenefits }: SalaryAndBenefitsProps) => { | ||
const currentYear = new Date().getFullYear(); | ||
const minExaminationYear = maxExperience(currentYear); | ||
const maxExaminationYear = currentYear - 1; | ||
|
||
const [formState, setFormState] = useState<SalaryCalculatorFormState>({ | ||
examinationYear: currentYear - 1, | ||
selectedDegree: "bachelor", | ||
}); | ||
const [salary, setSalary] = useState<number | null>(null); | ||
|
||
const updateSelectedDegree = (newDegree: Degree) => { | ||
setFormState((prevState) => ({ | ||
...prevState, | ||
selectedDegree: newDegree, | ||
})); | ||
}; | ||
|
||
const updateExaminationYear = (newYear: number) => { | ||
setFormState((prevState) => ({ | ||
...prevState, | ||
examinationYear: newYear, | ||
})); | ||
}; | ||
|
||
const handleSubmit = (event: React.FormEvent) => { | ||
event.preventDefault(); | ||
setSalary( | ||
calculateSalary( | ||
currentYear, | ||
formState.examinationYear, | ||
formState.selectedDegree, | ||
), | ||
); | ||
}; | ||
|
||
return ( | ||
<div className={styles.wrapper}> | ||
<Text type="h1">{salaryAndBenefits.basicTitle}</Text> | ||
{salaryAndBenefits.showSalaryCalculator && ( | ||
<SalaryCalculator | ||
// TODO: should also take in degree state (this requires changes to IOption of RadioButtonGroup) | ||
examinationYear={formState.examinationYear} | ||
minExaminationYear={minExaminationYear} | ||
maxExaminationYear={maxExaminationYear} | ||
onDegreeChanged={updateSelectedDegree} | ||
onExaminationYearChanged={updateExaminationYear} | ||
onSubmit={handleSubmit} | ||
/> | ||
)} | ||
{salary !== null ? ( | ||
<div aria-live="polite"> | ||
<Text> Du vil få en årlig lønn på {salary}</Text> | ||
<Text> | ||
Du vil få en årlig pensjon på omtrent {calculatePension(salary)} | ||
</Text> | ||
</div> | ||
) : null} | ||
<div className={styles.benefits}> | ||
{salaryAndBenefits.benefits.map((benefit) => ( | ||
<Benefit key={benefit._key} benefit={benefit} /> | ||
<div key={benefit._key} className={styles.benefitWrapper}> | ||
<Text type="h2">{benefit.basicTitle}</Text> | ||
<RichText value={benefit.richText} /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default SalaryAndBenefits; | ||
export default SalaryAndBenefits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/salaryAndBenefits/components/salaryCalculator/SalaryCalculator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import styles from "./salaryCalculator.module.css"; | ||
import InputField from "src/components/forms/inputField/InputField"; | ||
import { | ||
IOption, | ||
RadioButtonGroup, | ||
} from "src/components/forms/radioButtonGroup/RadioButtonGroup"; | ||
import Button from "src/components/buttons/Button"; | ||
|
||
export type Degree = "bachelor" | "master"; | ||
|
||
const degreeOptions: IOption[] = [ | ||
{ | ||
id: "bachelor", | ||
label: "Bachelor", | ||
currentSelected: true, | ||
disabled: false, | ||
}, | ||
{ id: "master", label: "Master", currentSelected: false, disabled: false }, | ||
]; | ||
|
||
interface SalaryCalculatorProps { | ||
examinationYear: number; | ||
minExaminationYear: number; | ||
maxExaminationYear: number; | ||
onDegreeChanged: (degree: Degree) => void; | ||
onExaminationYearChanged: (examinationYear: number) => void; | ||
onSubmit: (event: React.FormEvent) => void; | ||
} | ||
|
||
export default function SalaryCalculator({ | ||
examinationYear, | ||
minExaminationYear, | ||
maxExaminationYear, | ||
onDegreeChanged, | ||
onExaminationYearChanged, | ||
onSubmit, | ||
}: SalaryCalculatorProps) { | ||
return ( | ||
<form | ||
aria-label="salary calculator" | ||
className={styles.calculator} | ||
onSubmit={onSubmit} | ||
> | ||
<RadioButtonGroup | ||
id="degree-group" | ||
label="Choose your degree" | ||
options={degreeOptions} | ||
onValueChange={(value) => | ||
(value.id === "bachelor" || value.id === "master") && | ||
onDegreeChanged(value.id) | ||
} | ||
/> | ||
<InputField | ||
label="year" | ||
name="examinationYear" | ||
type="number" | ||
max={maxExaminationYear} | ||
min={minExaminationYear} | ||
value={examinationYear} | ||
onChange={(_name, value) => onExaminationYearChanged(parseInt(value))} | ||
required | ||
/> | ||
<Button type="secondary" size="small"> | ||
Submit | ||
</Button> | ||
</form> | ||
); | ||
} |
4 changes: 2 additions & 2 deletions
4
...its/components/benefit/benefit.module.css → ...aryCalculator/salaryCalculator.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.wrapper { | ||
.calculator{ | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
gap: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.