Skip to content

Commit

Permalink
use api for geting G
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsve committed Jan 12, 2024
1 parent 90360a3 commit a6f260d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/advanced-calculator/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const ONE_G = 111477;

export type HistoricBonus = [year: number, bonus: number];

export const historicBonus: HistoricBonus[] = [
Expand Down
19 changes: 15 additions & 4 deletions src/advanced-calculator/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -454,7 +465,7 @@ export default function Calculator(props: SalaryCalculatorProps) {
<ul>
<li>
Full lønn under permisjon. NAV dekker opp til{' '}
<span>{formatCurrencyFromNumber(ONE_G * 6)}</span> (6G). Variant
<span>{formatCurrencyFromNumber(grunnbelop * 6)}</span> (6G). Variant
tar seg av resten.
</li>
<li>
Expand Down

0 comments on commit a6f260d

Please sign in to comment.