forked from Ada-C9/video-store-consumer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added logic to CustomerList to make api call to retrieve list of cust…
…omers from our Rails api, and installed axios to package.json
- Loading branch information
Showing
6 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import axios from 'axios'; | ||
|
||
import './Customer.css'; | ||
import CustomerDetails from './CustomerDetails'; | ||
|
||
class Customer extends Component { | ||
render() { | ||
|
||
return ( | ||
<section> | ||
</section> | ||
) | ||
} | ||
|
||
} | ||
|
||
|
||
export default Customer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import axios from 'axios'; | ||
|
||
import './CustomerDetails.css'; | ||
|
||
class CustomerDetails extends Component { | ||
render() { | ||
|
||
return ( | ||
<section> | ||
</section> | ||
) | ||
} | ||
|
||
} | ||
|
||
|
||
export default CustomerDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import axios from 'axios'; | ||
|
||
import './CustomerList.css'; | ||
import Customer from './Customer'; | ||
|
||
class CustomerList extends Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
customers: [] | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
axios.get("http://localhost:3000/customers") | ||
.then((response) => { | ||
const customers = this.state.customers; | ||
response.data.forEach((customer) => { | ||
const newCustomer = {}; | ||
newCustomer.id = customer.id; | ||
newCustomer.name = customer.name; | ||
newCustomer.phone = customer.phone; | ||
newCustomer.account_credit = customer.account_credit; | ||
customers.push(newCustomer); | ||
}) | ||
|
||
this.setState({ customers }) | ||
}) | ||
.catch((error) => { | ||
this.setState({ message: error.message}) | ||
}); | ||
} | ||
|
||
seeState = () => { | ||
console.log(this.state.customers) | ||
} | ||
render() { | ||
const customerComponents = this.state.customers.map( (customer) => { | ||
return( | ||
<li key={ customer.id }> | ||
<Customer | ||
id={customer.id} | ||
name={customer.name} | ||
phone={customer.phone} | ||
credit={customer.account_credit} | ||
/> | ||
</li>) | ||
}); | ||
return ( | ||
<section> | ||
<h3>Find Customer</h3> | ||
<ul> | ||
{ customerComponents } | ||
</ul> | ||
</section> | ||
) | ||
} | ||
|
||
} | ||
|
||
|
||
export default CustomerList; |