1
1
import { useMemo , useState } from "react" ;
2
2
import { useDebounce } from "react-use" ;
3
- import { ISelectData } from "shared/types/options" ;
3
+ import { ILabelValue } from "shared/types/options" ;
4
4
import { useApi } from "frontend/lib/data/useApi" ;
5
5
import { useLingui } from "@lingui/react" ;
6
6
import { ErrorAlert } from "@/components/app/alert" ;
7
- import { IBaseFormSelect } from "@/frontend/design-system/components/Form/Select/types" ;
8
7
import { FormSelect } from "./select" ;
8
+ import { IBaseFormSelect } from "./types" ;
9
+ import { transformLabelValueToSelectData } from "@/translations/fake" ;
9
10
10
11
interface IProps extends IBaseFormSelect {
11
12
url : string ;
@@ -21,11 +22,11 @@ export function AsyncFormSelect(props: IProps) {
21
22
const [ search , setSearch ] = useState ( "" ) ;
22
23
const [ debounceSearch , setDebounceSearch ] = useState ( "" ) ;
23
24
24
- const fullData = useApi < ISelectData [ ] > ( url , {
25
+ const fullData = useApi < ILabelValue [ ] > ( url , {
25
26
defaultData : [ ] ,
26
27
} ) ;
27
28
28
- const selectOptions = useApi < ISelectData [ ] > (
29
+ const selectOptions = useApi < ILabelValue [ ] > (
29
30
debounceSearch ? `${ url } ?search=${ debounceSearch } ` : url ,
30
31
{
31
32
defaultData : [ ] ,
@@ -34,15 +35,15 @@ export function AsyncFormSelect(props: IProps) {
34
35
35
36
const currentLabelFromSelection = useMemo ( ( ) => {
36
37
const isValueInFirstDataLoad = fullData . data . find (
37
- ( { value } : ISelectData ) => String ( value ) === String ( input . value )
38
+ ( { value } : ILabelValue ) => String ( value ) === String ( input . value )
38
39
) ;
39
40
40
41
if ( isValueInFirstDataLoad ) {
41
42
return _ ( isValueInFirstDataLoad . label ) ;
42
43
}
43
44
44
45
const isValueInSelectionOptions = selectOptions . data . find (
45
- ( { value } : ISelectData ) => String ( value ) === String ( input . value )
46
+ ( { value } : ILabelValue ) => String ( value ) === String ( input . value )
46
47
) ;
47
48
48
49
if ( isValueInSelectionOptions ) {
@@ -78,7 +79,7 @@ export function AsyncFormSelect(props: IProps) {
78
79
return (
79
80
< FormSelect
80
81
{ ...props }
81
- selectData = { selectOptions . data }
82
+ selectData = { transformLabelValueToSelectData ( selectOptions . data ) }
82
83
isLoading = { isLoading }
83
84
onSearch = { {
84
85
isLoading : selectOptions . isLoading ,
@@ -91,6 +92,10 @@ export function AsyncFormSelect(props: IProps) {
91
92
}
92
93
93
94
return (
94
- < FormSelect { ...props } selectData = { fullData . data } isLoading = { isLoading } />
95
+ < FormSelect
96
+ { ...props }
97
+ selectData = { transformLabelValueToSelectData ( fullData . data ) }
98
+ isLoading = { isLoading }
99
+ />
95
100
) ;
96
101
}
0 commit comments