1
1
import React , { useState } from 'react' ;
2
- import { useFormContext } from 'react-hook-form' ;
2
+ import { useFormContext , useWatch } from 'react-hook-form' ;
3
+ import { useRecoilValue } from 'recoil' ;
3
4
4
5
import { BodyLong , BodyShort , Textarea } from '@navikt/ds-react' ;
5
6
6
7
import { Button } from '@components/Button' ;
7
8
import { Modal } from '@components/Modal' ;
8
9
import { SortInfoikon } from '@components/ikoner/SortInfoikon' ;
10
+ import { sanityMaler } from '@utils/featureToggles' ;
11
+ import { toKronerOgØre } from '@utils/locale' ;
9
12
10
13
import { skjønnsfastsettelseBegrunnelser } from '../skjønnsfastsetting' ;
14
+ import { skjønnsfastsettingMaler } from '../state' ;
11
15
12
16
import styles from './SkjønnsfastsettingBegrunnelse.module.css' ;
13
17
@@ -21,10 +25,14 @@ export const SkjønnsfastsettingBegrunnelse = ({
21
25
sammenligningsgrunnlag,
22
26
} : SkjønnsfastsettingBegrunnelseProps ) => {
23
27
const { formState, register, watch } = useFormContext ( ) ;
28
+ const valgtÅrsak = useWatch ( { name : 'årsak' } ) ;
29
+ const malFraSanity = useRecoilValue ( skjønnsfastsettingMaler ) . find ( ( it ) => it . arsak === valgtÅrsak ) ;
24
30
const [ showModal , setShowModal ] = useState ( false ) ;
25
31
const begrunnelseId = watch ( 'begrunnelseId' ) ;
26
32
const arbeidsgivere = watch ( 'arbeidsgivere' , [ ] ) ;
27
33
const annet = arbeidsgivere . reduce ( ( n : number , { årlig } : { årlig : number } ) => n + årlig , 0 ) ;
34
+ const skjønnsfastsatt =
35
+ begrunnelseId === '0' ? omregnetÅrsinntekt : begrunnelseId === '1' ? sammenligningsgrunnlag : annet ;
28
36
29
37
const valgtBegrunnelse = skjønnsfastsettelseBegrunnelser (
30
38
omregnetÅrsinntekt ,
@@ -40,7 +48,17 @@ export const SkjønnsfastsettingBegrunnelse = ({
40
48
< BodyShort >
41
49
< span className = { styles . Bold } > Begrunnelse</ span > (teksten vises til bruker)
42
50
</ BodyShort >
43
- { valgtBegrunnelse ?. mal && < BodyLong className = { styles . mal } > { valgtBegrunnelse . mal } </ BodyLong > }
51
+ { ! sanityMaler && valgtBegrunnelse ?. mal && (
52
+ < BodyLong className = { styles . mal } > { valgtBegrunnelse . mal } </ BodyLong >
53
+ ) }
54
+ { sanityMaler && malFraSanity ?. begrunnelse && (
55
+ < BodyLong className = { styles . mal } >
56
+ { malFraSanity . begrunnelse
57
+ . replace ( '${omregnetÅrsinntekt}' , toKronerOgØre ( omregnetÅrsinntekt ) )
58
+ . replace ( '${omregnetÅrsinntekt/12}' , toKronerOgØre ( omregnetÅrsinntekt / 12 ) )
59
+ . replace ( '${sammenligningsgrunnlag}' , toKronerOgØre ( sammenligningsgrunnlag ) ) }
60
+ </ BodyLong >
61
+ ) }
44
62
</ div >
45
63
< Textarea
46
64
className = { styles . fritekst }
@@ -63,9 +81,17 @@ export const SkjønnsfastsettingBegrunnelse = ({
63
81
}
64
82
resize
65
83
/>
66
- { valgtBegrunnelse ?. konklusjon && (
84
+ { ! sanityMaler && valgtBegrunnelse ?. konklusjon && (
67
85
< BodyLong className = { styles . mal } > { valgtBegrunnelse . konklusjon } </ BodyLong >
68
86
) }
87
+ { sanityMaler && malFraSanity ?. konklusjon && (
88
+ < BodyLong className = { styles . mal } >
89
+ { malFraSanity . konklusjon . replace (
90
+ '${skjønnsfastsattÅrsinntekt}' ,
91
+ toKronerOgØre ( skjønnsfastsatt ) ,
92
+ ) }
93
+ </ BodyLong >
94
+ ) }
69
95
</ div >
70
96
< Modal
71
97
isOpen = { showModal }
0 commit comments