1
+ import {
2
+ KontrollerInntektPeriodeDtoStatus ,
3
+ KontrollerInntektPeriodeDtoValg ,
4
+ type KontrollerInntektDto ,
5
+ type RapportertInntektDto ,
6
+ } from '@k9-sak-web/backend/ungsak/generated' ;
1
7
import { CheckmarkCircleFillIcon , ExclamationmarkTriangleFillIcon , PersonIcon } from '@navikt/aksel-icons' ;
2
8
import { Bleed , BodyLong , Box , Button , Heading , HStack , Table , VStack } from '@navikt/ds-react' ;
3
9
import { Form , InputField , RadioGroupPanel , TextAreaField } from '@navikt/ft-form-hooks' ;
4
10
import { minLength , required } from '@navikt/ft-form-validators' ;
5
11
import { useForm } from 'react-hook-form' ;
12
+ import PeriodLabel from '../../shared/periodLabel/PeriodLabel' ;
13
+ import { formatCurrencyWithKr } from '../../utils/formatters' ;
6
14
import styles from './arbeidOgInntekt.module.css' ;
7
15
8
- const dummyData = [
9
- {
10
- status : 'Ingen avvik' ,
11
- arbeidsforhold : 'Bedrift AS' ,
12
- periode : `${ new Date ( ) . toLocaleDateString ( 'no' ) } - ${ new Date ( ) . toLocaleDateString ( 'no' ) } ` ,
13
- rapportertDeltager : '0 kr' ,
14
- rapportertInntekt : '0 kr' ,
15
- } ,
16
- {
17
- status : 'Avvik' ,
18
- arbeidsforhold : 'Bedrift 2 AS' ,
19
- periode : `${ new Date ( ) . toLocaleDateString ( 'no' ) } - ${ new Date ( ) . toLocaleDateString ( 'no' ) } ` ,
20
- rapportertDeltager : '0 kr' ,
21
- rapportertInntekt : '0 kr' ,
22
- } ,
23
- ] ;
16
+ const formaterInntekt = ( inntekt : RapportertInntektDto ) => {
17
+ return formatCurrencyWithKr ( ( inntekt . arbeidsinntekt ?? 0 ) + ( inntekt . ytelse ?? 0 ) ) ;
18
+ } ;
24
19
25
20
type Formvalues = {
26
- inntektArbeid : string ;
27
- inntektYtelse : string ;
28
- inntektRadio : 'deltager' | 'a-inntekt' | 'fastsett-belop' | '' ;
21
+ fastsattArbeidsinntekt : string ;
22
+ fastsattYtelse : string ;
23
+ inntektRadio : KontrollerInntektPeriodeDtoValg | '' ;
29
24
begrunnelse : string ;
30
25
} ;
31
26
32
27
interface ArbeidOgInntektProps {
33
28
submitCallback : ( data : unknown ) => void ;
29
+ inntektKontrollperioder : KontrollerInntektDto [ 'kontrollperioder' ] ;
34
30
}
35
31
36
- export const ArbeidOgInntekt = ( { submitCallback } : ArbeidOgInntektProps ) => {
32
+ export const ArbeidOgInntekt = ( { submitCallback, inntektKontrollperioder } : ArbeidOgInntektProps ) => {
37
33
const formMethods = useForm < Formvalues > ( {
38
34
defaultValues : {
39
- inntektArbeid : '' ,
40
- inntektYtelse : '' ,
35
+ fastsattArbeidsinntekt : '' ,
36
+ fastsattYtelse : '' ,
41
37
inntektRadio : '' ,
42
38
begrunnelse : '' ,
43
39
} ,
44
40
} ) ;
45
41
const inntektRadio = formMethods . watch ( 'inntektRadio' ) ;
46
42
47
43
const onSubmit = ( values : Formvalues ) => {
48
- let payload ;
49
- if ( values . inntektRadio === 'fastsett-belop' ) {
50
- payload = {
51
- inntektArbeid : values . inntektArbeid ,
52
- inntektYtelse : values . inntektYtelse ,
53
- begrunnelse : values . begrunnelse ,
54
- } ;
55
- } else {
56
- payload = {
57
- inntektRadio : values . inntektRadio ,
58
- begrunnelse : values . begrunnelse ,
59
- } ;
60
- }
44
+ const payload = {
45
+ inntektRadio : values . inntektRadio ,
46
+ begrunnelse : values . begrunnelse ,
47
+ ...( values . inntektRadio === KontrollerInntektPeriodeDtoValg . MANUELT_FASTSATT && {
48
+ fastsattArbeidsinntekt : values . fastsattArbeidsinntekt ,
49
+ fastsattYtelse : values . fastsattYtelse ,
50
+ } ) ,
51
+ } ;
61
52
submitCallback ( payload ) ;
62
53
} ;
63
54
@@ -94,23 +85,29 @@ export const ArbeidOgInntekt = ({ submitCallback }: ArbeidOgInntektProps) => {
94
85
label = "Hvilken inntekt skal benyttes?"
95
86
validate = { [ required ] }
96
87
radios = { [
97
- { value : 'deltager' , label : 'Rapportert inntekt fra deltager' } ,
98
- { value : 'a-inntekt' , label : 'Rapportert inntekt fra A-inntekt' } ,
99
- { value : 'fastsett-belop' , label : 'Fastsett beløp' } ,
88
+ {
89
+ value : KontrollerInntektPeriodeDtoValg . BRUK_BRUKERS_INNTEKT ,
90
+ label : 'Rapportert inntekt fra deltager' ,
91
+ } ,
92
+ {
93
+ value : KontrollerInntektPeriodeDtoValg . BRUK_REGISTER_INNTEKT ,
94
+ label : 'Rapportert inntekt fra A-inntekt' ,
95
+ } ,
96
+ { value : KontrollerInntektPeriodeDtoValg . MANUELT_FASTSATT , label : 'Fastsett beløp' } ,
100
97
] }
101
98
/>
102
- { inntektRadio === 'fastsett-belop' && (
99
+ { inntektRadio === KontrollerInntektPeriodeDtoValg . MANUELT_FASTSATT && (
103
100
< VStack gap = "4" >
104
101
< InputField
105
- name = "inntektArbeid "
102
+ name = "fastsattArbeidsinntekt "
106
103
label = "Inntekt fra arbeid"
107
104
type = "text"
108
105
validate = { [ required ] }
109
106
htmlSize = { 7 }
110
107
size = "small"
111
108
/>
112
109
< InputField
113
- name = "inntektYtelse "
110
+ name = "fastsattYtelse "
114
111
label = "Inntekt fra ytelse"
115
112
type = "text"
116
113
validate = { [ required ] }
@@ -150,7 +147,6 @@ export const ArbeidOgInntekt = ({ submitCallback }: ArbeidOgInntektProps) => {
150
147
< Table . HeaderCell scope = "col" className = { styles . firstHeaderCell } >
151
148
Status
152
149
</ Table . HeaderCell >
153
- < Table . HeaderCell scope = "col" > Arbeidsforhold</ Table . HeaderCell >
154
150
< Table . HeaderCell scope = "col" > Periode</ Table . HeaderCell >
155
151
< Table . HeaderCell scope = "col" align = "right" >
156
152
Rapportert av deltager
@@ -162,32 +158,40 @@ export const ArbeidOgInntekt = ({ submitCallback }: ArbeidOgInntektProps) => {
162
158
</ Table . Row >
163
159
</ Table . Header >
164
160
< Table . Body >
165
- { dummyData . map ( ( data , index ) => {
166
- const isLastRow = index === dummyData . length - 1 ;
167
- const hasAvvik = data . status === 'Avvik' ;
161
+ { inntektKontrollperioder ?. map ( ( inntekt , index ) => {
162
+ const isLastRow = index === inntektKontrollperioder . length - 1 ;
163
+ const harAksjonspunkt = inntekt . erTilVurdering ;
164
+ const harAvvik = inntekt . status === KontrollerInntektPeriodeDtoStatus . AVVIK ;
168
165
return (
169
166
< Table . ExpandableRow
170
- key = { index }
171
- content = { hasAvvik ? getAksjonspunkt ( ) : null }
167
+ key = { ` ${ inntekt . periode ?. fom } _ ${ inntekt . periode ?. tom } ` }
168
+ content = { harAksjonspunkt ? getAksjonspunkt ( ) : null }
172
169
togglePlacement = "right"
173
170
className = { isLastRow ? styles . lastRow : '' }
174
171
expandOnRowClick
175
- expansionDisabled = { ! hasAvvik }
172
+ expansionDisabled = { ! harAksjonspunkt }
176
173
>
177
174
< Table . DataCell className = { styles . firstDataCell } >
178
175
< HStack gap = "2" >
179
- { hasAvvik ? (
176
+ { harAvvik ? (
180
177
< ExclamationmarkTriangleFillIcon fontSize = "1.5rem" className = { styles . exclamationmarkIcon } />
181
178
) : (
182
179
< CheckmarkCircleFillIcon fontSize = { 24 } className = { styles . checkmarkIcon } />
183
180
) }
184
- { data . status }
181
+ { inntekt . status }
185
182
</ HStack >
186
183
</ Table . DataCell >
187
- < Table . DataCell > { data . arbeidsforhold } </ Table . DataCell >
188
- < Table . DataCell > { data . periode } </ Table . DataCell >
189
- < Table . DataCell align = "right" > { data . rapportertDeltager } </ Table . DataCell >
190
- < Table . DataCell align = "right" > { data . rapportertInntekt } </ Table . DataCell >
184
+ < Table . DataCell >
185
+ { inntekt . periode && (
186
+ < PeriodLabel dateStringFom = { inntekt . periode ?. fom } dateStringTom = { inntekt . periode ?. tom } />
187
+ ) }
188
+ </ Table . DataCell >
189
+ < Table . DataCell align = "right" >
190
+ { inntekt . rapporterteInntekter ?. bruker && formaterInntekt ( inntekt . rapporterteInntekter ?. bruker ) }
191
+ </ Table . DataCell >
192
+ < Table . DataCell align = "right" >
193
+ { inntekt . rapporterteInntekter ?. register && formaterInntekt ( inntekt . rapporterteInntekter ?. register ) }
194
+ </ Table . DataCell >
191
195
</ Table . ExpandableRow >
192
196
) ;
193
197
} ) }
0 commit comments