Skip to content

Commit 9187734

Browse files
committed
Create fetch fucntion to get employers data from the database
1 parent f62249b commit 9187734

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Components/forms/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const path = `${domain()}${appPath}`
1313
class Forms extends Component {
1414
state = {
1515
teamOptions: [],
16+
employersOptions: [],
1617
...initialState
1718
}
1819

1920
componentDidMount() {
2021
this.fetchTeamData()
22+
this.fetchEmployers()
2123
}
2224

2325
fetchTeamData = async () => {
@@ -34,6 +36,17 @@ class Forms extends Component {
3436
}
3537
}
3638

39+
fetchEmployers = async () => {
40+
try {
41+
const employersResponse = await axios.get(`${domain()}/employers`)
42+
const employersData = employersResponse.data.employers
43+
employersData.sort((a, b) => a.name.localeCompare(b.name))
44+
this.setState({ employersOptions: employersData })
45+
} catch (err) {
46+
console.log(err)
47+
}
48+
}
49+
3750
handleMagicLinkRequest = async e => {
3851
e.preventDefault()
3952
const { email, userId } = this.state
@@ -393,6 +406,7 @@ class Forms extends Component {
393406
telOnChange={this.telOnChange}
394407
onChangeCheckList={this.onChangeCheckList}
395408
teamOptions={this.state.teamOptions}
409+
employersOptions={this.state.employersOptions}
396410
{...this.props}
397411
{...this.state}
398412
/>

src/Components/forms/inputs/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default class VolunteerForm extends Component {
3232
guidePeople,
3333
techSkill,
3434
otherSkill,
35+
employersOptions,
3536
employer
3637
} = this.props
3738

@@ -146,10 +147,10 @@ export default class VolunteerForm extends Component {
146147
/>
147148
{hearAboutCYFFromEmployer && (
148149
<EmployerDropDown
149-
arrayList={ListsData.employerList}
150+
arrayList={employersOptions}
150151
isEmpty={errors.employer}
151152
onChange={onChange}
152-
value={employer}
153+
value={employersOptions}
153154
/>
154155
)}
155156
<span className="contact-interested">

0 commit comments

Comments
 (0)