1
1
import React from 'react' ;
2
2
import * as S from '../styles' ;
3
3
import * as H from '../../typography' ;
4
- import { Details } from '../constants ' ;
4
+ import { DataType } from '../types ' ;
5
5
6
- export const SecondaryDropDown : React . FC = ( ) => {
6
+ export const SecondaryDropDown = ( { data } ) => {
7
7
const [ showOptions , setShowOptions ] = React . useState ( false ) ;
8
8
const [ searchTerm , setSearchTerm ] = React . useState ( '' ) ;
9
9
const [ searchResults , setSearchResults ] = React . useState ( [ ] as any ) ;
@@ -12,14 +12,12 @@ export const SecondaryDropDown: React.FC = () => {
12
12
setShowOptions ( true ) ;
13
13
} ;
14
14
React . useEffect ( ( ) => {
15
- const results =
16
- [ ] ||
17
- Details . filter ( person =>
18
- person . name
19
- . replace ( / \s + / g, '' )
20
- . toLowerCase ( )
21
- . includes ( searchTerm . replace ( / \s + / g, '' ) . toLowerCase ( ) ) ,
22
- ) ;
15
+ const results : [ ] | DataType = data . filter ( person =>
16
+ person . name
17
+ . replace ( / \s + / g, '' )
18
+ . toLowerCase ( )
19
+ . includes ( searchTerm . replace ( / \s + / g, '' ) . toLowerCase ( ) ) ,
20
+ ) ;
23
21
setSearchResults ( results ) ;
24
22
if ( searchTerm ) {
25
23
setShowOptions ( true ) ;
@@ -40,11 +38,11 @@ export const SecondaryDropDown: React.FC = () => {
40
38
</ S . SearchBarWrapper >
41
39
{ showOptions && (
42
40
< S . OptionsContainer >
43
- { searchResults . map ( person => (
44
- < S . CardWrapper key = { `${ person . name } ` } >
45
- < S . Avatar src = { person . avatarLink } />
41
+ { searchResults . map ( ( { name , avatar } ) => (
42
+ < S . CardWrapper key = { `${ name } ` } >
43
+ < S . Avatar src = { avatar } />
46
44
< S . NameWrapper >
47
- < H . Heading5 > { person . name } </ H . Heading5 >
45
+ < H . Heading5 > { name } </ H . Heading5 >
48
46
</ S . NameWrapper >
49
47
</ S . CardWrapper >
50
48
) ) }
0 commit comments