@@ -3,6 +3,7 @@ import { Button, HStack, Table, TextField } from '@navikt/ds-react';
3
3
import { makeStyles } from '@navikt/skjemadigitalisering-shared-components' ;
4
4
import { Recipient } from '@navikt/skjemadigitalisering-shared-domain' ;
5
5
import { useState } from 'react' ;
6
+ import { useRecipients } from '../context/recipients/RecipientsContext' ;
6
7
7
8
const useStyles = makeStyles ( {
8
9
editRow : {
@@ -22,8 +23,10 @@ const useStyles = makeStyles({
22
23
type ViewState = 'display' | 'editing' ;
23
24
24
25
const RecipientRow = ( { recipient } : { recipient : Partial < Recipient > } ) => {
26
+ const { saveRecipient } = useRecipients ( ) ;
25
27
const { recipientId } = recipient ;
26
28
const [ viewState , setViewState ] = useState < ViewState > ( recipientId === 'new' ? 'editing' : 'display' ) ;
29
+ const [ isSaving , setIsSaving ] = useState < boolean > ( false ) ;
27
30
const [ value , setValue ] = useState ( recipient ) ;
28
31
const styles = useStyles ( ) ;
29
32
@@ -69,7 +72,7 @@ const RecipientRow = ({ recipient }: { recipient: Partial<Recipient> }) => {
69
72
label = "Enhetsnavn"
70
73
hideLabel
71
74
size = "small"
72
- value = { value . name }
75
+ defaultValue = { value . name }
73
76
onChange = { ( event ) => updateValueProperty ( 'name' , event . currentTarget . value ) }
74
77
/>
75
78
</ Table . DataCell >
@@ -78,7 +81,7 @@ const RecipientRow = ({ recipient }: { recipient: Partial<Recipient> }) => {
78
81
label = "Postboksadresse"
79
82
hideLabel
80
83
size = "small"
81
- value = { value . poBoxAddress }
84
+ defaultValue = { value . poBoxAddress }
82
85
onChange = { ( event ) => updateValueProperty ( 'poBoxAddress' , event . currentTarget . value ) }
83
86
/>
84
87
</ Table . DataCell >
@@ -87,7 +90,7 @@ const RecipientRow = ({ recipient }: { recipient: Partial<Recipient> }) => {
87
90
label = "Postnr."
88
91
hideLabel
89
92
size = "small"
90
- value = { value . postalCode }
93
+ defaultValue = { value . postalCode }
91
94
onChange = { ( event ) => updateValueProperty ( 'postalCode' , event . currentTarget . value ) }
92
95
/>
93
96
</ Table . DataCell >
@@ -96,7 +99,7 @@ const RecipientRow = ({ recipient }: { recipient: Partial<Recipient> }) => {
96
99
label = "Poststed"
97
100
hideLabel
98
101
size = "small"
99
- value = { value . postalName }
102
+ defaultValue = { value . postalName }
100
103
onChange = { ( event ) => updateValueProperty ( 'postalName' , event . currentTarget . value ) }
101
104
/>
102
105
</ Table . DataCell >
@@ -106,9 +109,14 @@ const RecipientRow = ({ recipient }: { recipient: Partial<Recipient> }) => {
106
109
< HStack gap = "4" justify = "end" >
107
110
< Button
108
111
size = "small"
109
- onClick = { ( ) => {
112
+ loading = { isSaving }
113
+ onClick = { async ( ) => {
110
114
console . log ( value ) ;
111
- setViewState ( 'display' ) ;
115
+ setIsSaving ( true ) ;
116
+ // FIXME
117
+ const result = await saveRecipient ( value as Recipient ) ;
118
+ setIsSaving ( false ) ;
119
+ if ( result ) setViewState ( 'display' ) ;
112
120
} }
113
121
>
114
122
Lagre
0 commit comments