Skip to content

Commit 85335fa

Browse files
Merge pull request #12 from marcoaraujojunior/develop
Using Card instead table to show clients
2 parents db45c8c + 8a5f613 commit 85335fa

27 files changed

+1234
-138
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
node_modules/**
33
public/dist/**
44
public/css/**
5+
jest/**
6+
coverage/**

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: node_js
2+
node_js:
3+
- "6.7"
4+
5+
before_script:
6+
- npm install
7+
8+
script:
9+
- npm run coverage
10+
- codecov
11+
12+
after_success:
13+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# IClient - React
2+
3+
[![Build Status](https://travis-ci.org/highideas/iClient-react.svg?branch=master)](https://travis-ci.org/highideas/iClient-react) [![codecov](https://codecov.io/gh/highideas/iClient-react/branch/master/graph/badge.svg)](https://codecov.io/gh/highideas/iClient-react)
4+
5+
Simple client to IClient Server made in React JS
6+
7+
8+
# To Try
9+
10+
docker-compose up -d
11+
12+
docker-compose exec iClientReact bash
13+
14+
cd client/
15+
16+
npm run dev
17+
18+
License
19+
----
20+
21+
MIT
22+

app/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Router, Route, IndexRoute, hashHistory } from 'react-router'
44
import 'bulma/css/bulma.css'
55
import 'font-awesome-webpack'
66

7-
import iClientComponent from 'components/iClient/iClientComponent';
8-
import HomeComponent from 'components/Home/HomeComponent';
9-
import ClientComponent from 'components/Client/ClientComponent';
7+
import iClientComponent from 'components/IClient/IClient';
8+
import HomeComponent from 'components/Home/Home';
9+
import ClientComponent from 'components/Client/Client';
1010
import AreaComponent from 'components/Area/Area';
1111

1212
ReactDOM.render(

app/components/Area/Area.js

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,63 @@
11
import React from 'react';
2-
import { Router, Link } from 'react-router'
2+
import { Link } from 'react-router'
33

4-
import Visit from 'services/Visit';
4+
import VisitService from 'services/Visit'
5+
6+
import Visit from 'components/Visit/Visit'
7+
import ErrorComponent from 'components/Error/Error'
58

69
class Area extends React.Component
710
{
811
constructor(props) {
912
super(props);
1013
this.state = {
11-
areas : []
14+
areas : [],
15+
error : ''
1216
};
13-
this.renderVisit = this.renderVisit.bind(this);
14-
this.renderArea = this.renderArea.bind(this);
17+
this.generate = this.generate.bind(this);
18+
this.generateError = this.generateError.bind(this);
19+
this.getVisitGroupByArea = this.getVisitGroupByArea.bind(this);
1520
this.getVisitGroupByArea();
1621
}
1722

1823
getVisitGroupByArea() {
19-
Visit.getGroupByArea().then((response) => {
20-
this.setState({areas: response.data.visits});
24+
VisitService.getGroupByArea().then((response) => {
25+
this.setState({error: ''});
26+
this.setState({
27+
areas: this.generate(response.data.visits)
28+
});
29+
}).catch((error) => {
30+
if (error.response) {
31+
this.setState({error: error.response.data.error});
32+
}
2133
});
2234
}
2335

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-
});
36+
generateError(error) {
37+
return (
38+
<ErrorComponent error={this.state.error} />
39+
);
3840
}
3941

40-
renderArea(areas) {
42+
generate(areas) {
4143
return areas.map((area, key) => {
4244
return (
4345
<div className="area" key={ key }>
4446
<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>
47+
<Visit visits={area.visits} />
5748
</div>
5849
);
5950
});
6051
}
6152

6253
render() {
54+
if (this.state.error) {
55+
let error = this.generateError(this.state.error);
56+
return error;
57+
}
6358
return (
6459
<div className="container hello">
65-
{ this.renderArea(this.state.areas) }
60+
{ this.state.areas }
6661
</div>
6762
);
6863
}

app/components/Client/Client.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
import { CardStack, Card } from 'react-cardstack';
3+
4+
import ClientService from 'services/Client';
5+
import Error from 'components/Error/Error'
6+
7+
class Client extends React.Component
8+
{
9+
constructor(props) {
10+
super(props);
11+
this.state = {
12+
clients : null,
13+
error : ''
14+
};
15+
this.getClients();
16+
}
17+
18+
getClients() {
19+
ClientService.getClients().then((response) => {
20+
this.setState({clients: response.data.clients});
21+
}).catch((error) => {
22+
this.setState({error: 'Error Found: Trying get client'});
23+
if (error.response) {
24+
this.setState({error: error.response.data.error});
25+
}
26+
});
27+
}
28+
29+
render() {
30+
if (this.state.error) {
31+
return (<Error error={this.state.error} />);
32+
}
33+
if (!this.state.clients) {
34+
return <div>Loading...</div>;
35+
}
36+
const clientList = this.state.clients.map((client, key) => {
37+
return (
38+
<Card key={key}>
39+
<article className={`message ${((key % 2) ? 'is-success' : 'is-info')}`}>
40+
<div className="message-header">
41+
<strong>{ client.name }</strong>
42+
</div>
43+
<div className="message-body">
44+
<address>{ client.address }</address>
45+
<city><small>{ client.city }</small></city>
46+
</div>
47+
</article>
48+
</Card>
49+
);
50+
});
51+
52+
return (
53+
<div className="container hello">
54+
<CardStack
55+
height={100}
56+
width={1200}
57+
background='#00d1b2'
58+
hoverOffset={0}>
59+
60+
{ clientList }
61+
62+
</CardStack>
63+
</div>
64+
);
65+
}
66+
}
67+
68+
export default Client;
69+

app/components/Client/ClientComponent.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

app/components/Error/Error.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ const Error = ({error}) => (
66
{error}
77
</div> : null
88
);
9+
910
export default Error;
11+
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import React from 'react';
2-
import { Router } from 'react-router'
32

4-
class HomeComponent extends React.Component{
3+
class Home extends React.Component{
54

65
render() {
7-
if (!localStorage.token) {
8-
this.context.router.push("/");
9-
}
106
return (
117
<div className="hero-body">
128
<div className="container">
@@ -19,10 +15,5 @@ class HomeComponent extends React.Component{
1915
}
2016
}
2117

22-
HomeComponent.contextTypes = {
23-
router: React.PropTypes.object.isRequired
24-
};
25-
26-
export default HomeComponent;
27-
18+
export default Home;
2819

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
2-
import { Router, Route, IndexRoute, IndexLink, Link } from 'react-router'
32

4-
import LoginComponent from 'components/Login/LoginComponent';
3+
import LoginComponent from 'components/Login/Login';
54
import MenuComponent from 'components/Menu/Menu';
65

7-
class iClientComponent extends React.Component{
8-
constructor(props) {
9-
super(props);
6+
class IClient extends React.Component
7+
{
8+
constructor(props, context) {
9+
super(props, context);
1010
this.handleView = this.handleView.bind(this);
1111
}
1212

@@ -20,10 +20,11 @@ class iClientComponent extends React.Component{
2020
</div>
2121
);
2222
}
23+
2324
render() {
2425
let view = this.handleView();
2526

26-
if (!localStorage.token) {
27+
if (!window.localStorage.getItem('token')) {
2728
view = <LoginComponent />;
2829
}
2930
return (
@@ -32,5 +33,5 @@ class iClientComponent extends React.Component{
3233
}
3334
}
3435

35-
export default iClientComponent;
36+
export default IClient;
3637

0 commit comments

Comments
 (0)