forked from aditya-sridhar/simple-reactjs-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomers.js
58 lines (48 loc) · 1.53 KB
/
Customers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, {Component} from 'react';
import Panel from 'react-bootstrap/lib/Panel'
import Button from 'react-bootstrap/lib/Button'
import CustomerDetails from './CustomerDetails'
import axios from 'axios'
export default class Customers extends Component {
constructor(props) {
super(props)
this.state = {
selectedCustomer: 1
}
}
//function which is called the first time the component loads
componentDidMount() {
this.getCustomerData();
}
//Function to get the Customer Data from json
getCustomerData() {
axios.get('assets/samplejson/customerlist.json').then(response => {
this.setState({customerList: response})
})
};
render() {
if (!this.state.customerList)
return (<p>Loading data</p>)
return (<div className="addmargin">
<div className="col-md-3">
{
this.state.customerList.data.map(customer => <Panel bsStyle="info" key={customer.name} className="centeralign">
<Panel.Heading>
<Panel.Title componentClass="h3">{customer.name}</Panel.Title>
</Panel.Heading>
<Panel.Body>
<p>{customer.email}</p>
<p>{customer.phone}</p>
<Button bsStyle="info" onClick={() => this.setState({selectedCustomer: customer.id})}>
Click to View Details
</Button>
</Panel.Body>
</Panel>)
}
</div>
<div className="col-md-6">
<CustomerDetails val={this.state.selectedCustomer}/>
</div>
</div>)
}
}