@@ -51,7 +51,7 @@ function logSokPersonResults(amount: number) {
51
51
}
52
52
53
53
export default function SokPerson ( ) {
54
- const [ nameInitials , setNameInitials ] = useState < string > ( '' ) ;
54
+ const [ initials , setInitials ] = useState < string > ( '' ) ;
55
55
const [ birthdate , setBirthdate ] = useState < string > ( '' ) ;
56
56
const {
57
57
mutate,
@@ -72,15 +72,15 @@ export default function SokPerson() {
72
72
}
73
73
} ;
74
74
75
- const validInitials = ( initials : string ) : boolean => {
76
- return initials . length <= 3 && initials . length > 1 ;
75
+ const isValidInitials = ( initials : string ) : boolean => {
76
+ return initials === '' || ( initials . length <= 3 && initials . length > 1 ) ;
77
77
} ;
78
78
79
79
const handleSubmit = ( ) => {
80
80
const parsedBirthdate = parseBirthdate ( birthdate ) ;
81
- if ( validInitials ( nameInitials ) && ! ! parsedBirthdate ) {
81
+ if ( isValidInitials ( initials ) && ! ! parsedBirthdate ) {
82
82
const requestDTO : SokDTO = {
83
- initials : nameInitials . toLowerCase ( ) ,
83
+ initials : initials . toLowerCase ( ) ,
84
84
birthdate : parsedBirthdate ,
85
85
} ;
86
86
mutate ( requestDTO , {
@@ -92,8 +92,8 @@ export default function SokPerson() {
92
92
}
93
93
} ;
94
94
95
- const invalidInitials = isFormError && ! validInitials ( nameInitials ) ;
96
- const invalidBirthdate = isFormError && parseBirthdate ( birthdate ) === null ;
95
+ const isInvalidInitials = isFormError && ! isValidInitials ( initials ) ;
96
+ const isInvalidBirthdate = isFormError && parseBirthdate ( birthdate ) === null ;
97
97
98
98
return (
99
99
< >
@@ -115,16 +115,16 @@ export default function SokPerson() {
115
115
description = "AB"
116
116
htmlSize = { 10 }
117
117
type = "text"
118
- onChange = { ( e ) => setNameInitials ( e . target . value ) }
119
- error = { invalidInitials }
118
+ onChange = { ( e ) => setInitials ( e . target . value ) }
119
+ error = { isFormError && ! isValidInitials ( initials ) }
120
120
/>
121
121
< TextField
122
122
label = "Fødselsdato"
123
123
description = "ddmmåå"
124
124
htmlSize = { 14 }
125
125
type = "text"
126
126
onChange = { ( e ) => setBirthdate ( e . target . value ) }
127
- error = { invalidBirthdate }
127
+ error = { isInvalidBirthdate }
128
128
/>
129
129
< Button
130
130
loading = { isLoading }
@@ -134,12 +134,12 @@ export default function SokPerson() {
134
134
Søk
135
135
</ Button >
136
136
</ HStack >
137
- { invalidInitials && (
137
+ { isInvalidInitials && (
138
138
< ErrorMessage size = "small" >
139
139
{ texts . validation . initials }
140
140
</ ErrorMessage >
141
141
) }
142
- { invalidBirthdate && (
142
+ { isInvalidBirthdate && (
143
143
< ErrorMessage size = "small" >
144
144
{ texts . validation . birthdate }
145
145
</ ErrorMessage >
0 commit comments