-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDagpengerKalkulator.tsx
101 lines (91 loc) · 2.95 KB
/
DagpengerKalkulator.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, { useEffect, useState } from "react";
import { Collapse } from "react-collapse";
import { Alert, BodyShort } from "@navikt/ds-react";
import { GrunnlagInput, InputWrapper, KalkulatorStyle, ResultatTable, toKR } from "./felles";
import { useDebouncedValue } from "../../hooks/useDebouncedValue";
import { useTranslation } from "react-i18next";
import { loggKalkulatorbruk } from "../../utils/logging";
import { useGrunnbellop } from "../../utils/folketrygdensGrunnbeløp";
function Resultat(props: { grunnlag?: number }) {
const { t } = useTranslation("kalkulator");
const { G, GtoNOK } = useGrunnbellop();
if (!props.grunnlag) {
return null;
}
if (props.grunnlag < 1.5 * G) {
return (
<>
<BodyShort>{t("forLavtGrunnlag", { G: `1.5 G (${GtoNOK(1.5)} kroner)` })} </BodyShort>
<Alert variant="info">{t("sendSøknadLikvel")}</Alert>
</>
);
}
//const under3G = Math.min(props.grunnlag, 3 * G);
const mellom0og6g = Math.max(0, Math.min(props.grunnlag, 6 * G));
const over6G = Math.max(0, props.grunnlag - 6 * G);
//const resultatUnder3G = under3G * 0.624;
const resultatMellom0og6G = mellom0og6g * 0.624;
const totalt = resultatMellom0og6G;
return (
<>
<ResultatTable>
<tbody>
<tr>
<td>
<i>{t("mellom", { over: 0, under: 6 })}</i>
</td>
<td>{toKR(mellom0og6g)} x 62.4 %</td>
<td> {toKR(resultatMellom0og6G)}</td>
</tr>
{over6G > 0 && (
<tr>
<td>
<i>Inntekt over 6 G</i>
</td>
<td>{toKR(over6G)} x 0 %</td>
<td>{toKR(0)}</td>
</tr>
)}
<tr>
<td colSpan={2}>{t("tilsammen")}</td>
<td>{toKR(totalt)}</td>
</tr>
<tr>
<td colSpan={2}>{t("ukesats")}</td>
<td> {toKR(totalt / 52)}</td>
</tr>
</tbody>
</ResultatTable>
<Alert variant="info">{t("kunveiledende")}</Alert>
</>
);
}
function DagpengerKalkulator() {
const [harLoggetBruk, setHarLoggetBruk] = useState(false);
const [grunnlag, setGrunnlag] = useState<undefined | number>();
const debouncedGrunnlag = useDebouncedValue(grunnlag, 300);
const { t } = useTranslation("kalkulator");
useEffect(() => {
if (!harLoggetBruk && grunnlag) {
loggKalkulatorbruk("Uinnlogget vanlig");
setHarLoggetBruk(true);
}
}, [grunnlag, harLoggetBruk]);
return (
<KalkulatorStyle>
<Collapse isOpened={true}>
<InputWrapper>
<GrunnlagInput
label={t("label")}
type="number"
value={grunnlag || ""}
onChange={(e) => setGrunnlag(Math.max(0, +e.target.value) || undefined)}
placeholder="350 000"
/>
</InputWrapper>
<Resultat grunnlag={debouncedGrunnlag} />
</Collapse>
</KalkulatorStyle>
);
}
export default DagpengerKalkulator;