1
- import React , { FunctionComponent , useState , useEffect } from 'react' ;
1
+ // components/Janzz.tsx
2
+
3
+ import React , { FunctionComponent , useState } from 'react' ;
2
4
import css from './Janzz.module.css' ;
3
5
import { SET_EMPLOYMENT_JOBTITLE , SET_JANZZ } from '../../../adDataReducer' ;
4
6
import { useDispatch , useSelector } from 'react-redux' ;
@@ -20,15 +22,17 @@ const Janzz: FunctionComponent<Props> = ({ tittel }) => {
20
22
21
23
const { data : suggestions , isLoading, error } = useHentJanzzYrker ( input ) ;
22
24
23
- useEffect ( ( ) => {
24
- if ( suggestions && suggestions . length > 0 ) {
25
+ const onChange = ( event : React . ChangeEvent < HTMLInputElement > | null , value ?: string ) => {
26
+ setInput ( event ?. target ?. value || value || '' ) ;
27
+ } ;
28
+
29
+ const onToggleSelected = ( option : string , isSelected : boolean ) => {
30
+ if ( isSelected && suggestions ) {
25
31
const found = suggestions . find (
26
- ( { label } ) => label . toLowerCase ( ) === input . toLowerCase ( )
32
+ ( forslag ) => forslag . label . toLowerCase ( ) === option . toLowerCase ( )
27
33
) ;
28
-
29
34
if ( found ) {
30
35
dispatch ( { type : SET_EMPLOYMENT_JOBTITLE , jobtitle : found . label } ) ;
31
-
32
36
const kategori = [
33
37
{
34
38
id : found . konseptId ,
@@ -39,28 +43,15 @@ const Janzz: FunctionComponent<Props> = ({ tittel }) => {
39
43
parentId : null ,
40
44
} ,
41
45
] ;
42
-
43
46
dispatch ( { type : SET_JANZZ , kategori } ) ;
44
- } else {
45
- dispatch ( { type : SET_JANZZ , undefined } ) ;
47
+ setInput ( capitalizeEmployerName ( found . label ) || '' ) ;
46
48
}
47
- } else {
48
- dispatch ( { type : SET_JANZZ , undefined } ) ;
49
- }
50
- } , [ input , suggestions ] ) ;
51
-
52
- const onChange = ( event : React . ChangeEvent < HTMLInputElement > | null , value ?: string ) => {
53
- setInput ( event ?. target ?. value || value || '' ) ;
54
- } ;
55
-
56
- const onToggleSelected = ( option : string , isSelected : boolean ) => {
57
- if ( isSelected ) {
58
- setInput ( capitalizeEmployerName ( option ) || '' ) ;
59
49
}
60
50
} ;
61
51
62
52
const feilmeldingTilBruker = error ? error . message : undefined ;
63
53
54
+ // TODO: Fjern default tekster fra backend, slik at vi slipper å filterere de bort her
64
55
return (
65
56
< div >
66
57
< UnsafeCombobox
0 commit comments