|
1 |
| -import React, { useState } from 'react' |
| 1 | +import React from 'react' |
2 | 2 | import { Label } from 'reactstrap'
|
3 | 3 | import Select from 'react-select'
|
4 | 4 |
|
5 |
| -const EmployerDropDown = ({ onChange, isEmpty, arrayList, name }) => { |
6 |
| - const [value, setValue] = useState('') |
7 |
| - const employerSorter = (a, b) => { |
8 |
| - const aIndex = a.value.toLowerCase().indexOf(value.toLowerCase()) |
9 |
| - const bIndex = b.value.toLowerCase().indexOf(value.toLowerCase()) |
10 |
| - return a.value === 'Other' || b.value === 'Other' |
11 |
| - ? 1 |
12 |
| - : aIndex > bIndex |
13 |
| - ? 1 |
14 |
| - : aIndex < bIndex |
15 |
| - ? -1 |
16 |
| - : 0 |
17 |
| - } |
18 |
| - const employersList = arrayList |
19 |
| - .map(item => ({ |
20 |
| - value: item.name, |
21 |
| - label: item.name |
22 |
| - })) |
23 |
| - .sort(employerSorter) |
| 5 | +const EmployerDropDown = ({ onChange, isEmpty, arrayList }) => { |
| 6 | + const employersList = arrayList.map(({ _id, name }) => ({ |
| 7 | + value: _id, |
| 8 | + label: name |
| 9 | + })) |
24 | 10 | return (
|
25 |
| - <div className="form-group" data-testid="form-group"> |
26 |
| - <Label htmlFor="employer">"Who is your employer? *"</Label> |
| 11 | + <div className="form-group"> |
| 12 | + <Label htmlFor="employer">Who is your employer? *</Label> |
27 | 13 | <Select
|
28 |
| - className={`form-control ${isEmpty && 'is-empty'}`} |
| 14 | + className={isEmpty ? 'is-empty' : ''} |
29 | 15 | noOptionsMessage={() => 'Employer not found? Please select "Other".'}
|
30 | 16 | inputId="employer"
|
31 |
| - onInputChange={inputVal => setValue(inputVal)} |
| 17 | + isSearchable |
32 | 18 | options={employersList}
|
33 | 19 | onChange={e =>
|
34 | 20 | onChange({
|
35 | 21 | target: { name: 'employer', type: 'text', value: e.value }
|
36 | 22 | })
|
37 | 23 | }
|
| 24 | + name="employer" |
38 | 25 | placeholder="Type your employer name here"
|
39 | 26 | />
|
40 | 27 | </div>
|
|
0 commit comments