Skip to content

Commit 0c9aed5

Browse files
committed
Add Area component and Server constant
1 parent c81f00e commit 0c9aed5

File tree

9 files changed

+102
-7
lines changed

9 files changed

+102
-7
lines changed

app/App.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { Router, Route, IndexRoute, hashHistory } from 'react-router'
55
import iClientComponent from 'components/iClient/iClientComponent';
66
import HomeComponent from 'components/Home/HomeComponent';
77
import ClientComponent from 'components/Client/ClientComponent';
8+
import AreaComponent from 'components/Area/Area';
89

910
ReactDOM.render(
1011
<Router history={hashHistory} >
1112
<Route path="/" component={iClientComponent} >
1213
<IndexRoute component={HomeComponent} />
1314
<Route path="client" component={ClientComponent} />
15+
<Route path="area" component={AreaComponent} />
16+
<Route path="visit/:id" component={AreaComponent} />
1417
</Route>
1518
</Router>,
1619
document.getElementById('app')

app/components/Area/Area.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from 'react';
2+
import { Router, Link } from 'react-router'
3+
4+
import Visit from 'services/Visit';
5+
6+
class Area extends React.Component
7+
{
8+
constructor(props) {
9+
super(props);
10+
this.state = {
11+
areas : []
12+
};
13+
this.renderVisit = this.renderVisit.bind(this);
14+
this.renderArea = this.renderArea.bind(this);
15+
this.getVisitGroupByArea();
16+
}
17+
18+
getVisitGroupByArea() {
19+
Visit.getGroupByArea().then((response) => {
20+
this.setState({areas: response.data.visits});
21+
});
22+
}
23+
24+
renderVisit(visits) {
25+
return visits.map((areaVisit, key) => {
26+
return (
27+
<tr key={ key } >
28+
<td>{ areaVisit.visit.client.name }</td>
29+
<td>{ areaVisit.visit.visit_date }</td>
30+
<td className="is-icon">
31+
<Link to={ `/visit/${areaVisit.visit._id}` } >
32+
<i className="fa fa-info-circle" />
33+
</Link>
34+
</td>
35+
</tr>
36+
);
37+
});
38+
}
39+
40+
renderArea(areas) {
41+
return areas.map((area, key) => {
42+
return (
43+
<div className="area" key={ key }>
44+
<h3 className="title is-3">{area._id}</h3>
45+
<table className="table">
46+
<thead>
47+
<tr>
48+
<th>Name</th>
49+
<th>Last Visit</th>
50+
<th />
51+
</tr>
52+
</thead>
53+
<tbody>
54+
{this.renderVisit(area.visits)}
55+
</tbody>
56+
</table>
57+
</div>
58+
);
59+
});
60+
}
61+
62+
render() {
63+
return (
64+
<div className="container hello">
65+
{ this.renderArea(this.state.areas) }
66+
</div>
67+
);
68+
}
69+
}
70+
71+
export default Area;
72+

app/components/Client/ClientComponent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react';
22

33
import Client from 'services/Client';
44

5-
class ClientComponent extends React.Component{
5+
class ClientComponent extends React.Component
6+
{
67
constructor(props) {
78
super(props);
89
this.state = {

app/components/Login/LoginComponent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Router } from 'react-router'
44
import User from 'services/User';
55
import ErrorComponent from 'components/Error/Error';
66

7-
class LoginComponent extends React.Component{
7+
class LoginComponent extends React.Component
8+
{
89
constructor(props, context) {
910
super(props, context);
1011
this.handleSubmit = this.handleSubmit.bind(this);

app/components/Menu/Menu.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class Menu extends React.Component{
3131
<Link to="/area" className="nav-item is-tab">Area</Link>
3232
<span className="nav-item">
3333
<a className="button" onClick={this.handleLogout}>Logout</a>
34-
<a className="button is-info">Sign up </a>
3534
</span>
3635
</div>
3736
</div>

app/constants/Server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const HOST = 'http://localhost:3000';

app/services/Client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import axios from 'axios';
22

3-
const host = 'http://localhost:3000';
3+
import { HOST } from 'constants/Server';
4+
45
const Client = {
56
getClients() {
67
let config = {
78
headers: {
89
Authorization : localStorage.token
910
}
1011
};
11-
return axios.get(`${host}/api/v1/client`, config);
12+
return axios.get(`${HOST}/api/v1/client`, config);
1213
}
1314
};
1415

app/services/User.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import axios from 'axios';
2+
import { HOST } from 'constants/Server';
23

3-
const host = 'http://localhost:3000';
44
const User = {
55
login(username, password) {
66
let auth = {
77
username: username,
88
password: password
99
};
10-
return axios.post(`${host}/authenticate`, auth);
10+
return axios.post(`${HOST}/authenticate`, auth);
1111
}
1212
};
1313

app/services/Visit.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import axios from 'axios';
2+
3+
import { HOST } from 'constants/Server';
4+
5+
const Visit = {
6+
getGroupByArea() {
7+
let config = {
8+
headers: {
9+
Authorization : localStorage.token
10+
}
11+
};
12+
return axios.get(`${HOST}/api/v1/visit/group/area`, config);
13+
}
14+
};
15+
16+
export default Visit;
17+

0 commit comments

Comments
 (0)