From a6f260d9ed445fbf48de4699d792e38471c751ac Mon Sep 17 00:00:00 2001 From: oddsve Date: Fri, 12 Jan 2024 09:17:30 +0100 Subject: [PATCH] use api for geting G --- src/advanced-calculator/config.ts | 2 -- src/advanced-calculator/index.tsx | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/advanced-calculator/config.ts b/src/advanced-calculator/config.ts index 7048031c9..5ccf6fb2d 100644 --- a/src/advanced-calculator/config.ts +++ b/src/advanced-calculator/config.ts @@ -1,5 +1,3 @@ -export const ONE_G = 111477; - export type HistoricBonus = [year: number, bonus: number]; export const historicBonus: HistoricBonus[] = [ diff --git a/src/advanced-calculator/index.tsx b/src/advanced-calculator/index.tsx index 656de352e..86e50c3ad 100644 --- a/src/advanced-calculator/index.tsx +++ b/src/advanced-calculator/index.tsx @@ -1,8 +1,8 @@ -import { ReactNode, useState } from 'react'; +import { ReactNode, useEffect, useState } from 'react'; import InView from './Components/InView'; import RangeSlider from './Components/RangeSlider'; import { TextSplitter } from './Components/TextSplitter'; -import { ONE_G, SalaryCalculatorProps } from './config'; +import { SalaryCalculatorProps } from './config'; import Counter from './Counter'; import BonusGraph from './Graphs/BonusGraph'; import SalaryGraph from './Graphs/SalaryGraph'; @@ -43,14 +43,25 @@ const DEGREE: { [key: string]: string } = { export default function Calculator(props: SalaryCalculatorProps) { const [selectedYear, setSelectedYear] = useState(props.year); const [selectedValidYear, setSelectedValidYear] = useState(props.year); + const [grunnbelop, setGrunnbelop] = useState(118620); const [degree, setDegree] = useState(props.degree); const thisYear = new Date().getFullYear(); const year = selectedValidYear + (degree === 'bachelor' ? 1 : 0); const payscale = getPayscale(year); - + const isOverrideVisibleControls = useMediaQuery(`(min-width: 900px)`) ?? true; const [mobileVisibleInternal, setMobileVisible] = useState(true); + + useEffect(() => { + const getGrunnbelop = async () => { + const res = await fetch('https://g.nav.no/api/v1/grunnbeloep'); + const json = await res.json(); + setGrunnbelop(json['grunnbeloep']) + } + getGrunnbelop(); + },[]); + const mobileVisible = isOverrideVisibleControls || mobileVisibleInternal; const yearsOfExperience = calculateYearsSince( @@ -454,7 +465,7 @@ export default function Calculator(props: SalaryCalculatorProps) {