Skip to content

Commit

Permalink
Merge pull request #10 from marcoaraujojunior/master
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
GabrielDeveloper authored Nov 16, 2016
2 parents 39872cd + a84ae49 commit 792fe98
Show file tree
Hide file tree
Showing 29 changed files with 1,318 additions and 100 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules/**
public/dist/**
public/css/**
jest/**
coverage/**
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- "6.7"

before_script:
- npm install

script:
- npm run coverage
- codecov

after_success:
- bash <(curl -s https://codecov.io/bash)
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# IClient - React

[![Build Status](https://travis-ci.org/marcoaraujojunior/iClient-react.svg?branch=master)](https://travis-ci.org/marcoaraujojunior/iClient-react) [![codecov](https://codecov.io/gh/marcoaraujojunior/iClient-react/branch/master/graph/badge.svg)](https://codecov.io/gh/marcoaraujojunior/iClient-react)

Simple client to IClient Server made in React JS


# To Try

docker-compose up -d

docker-compose exec iClientReact bash

cd client/

npm run dev

License
----

MIT

8 changes: 5 additions & 3 deletions app/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
import 'bulma/css/bulma.css'
import 'font-awesome-webpack'

import iClientComponent from 'components/iClient/iClientComponent';
import HomeComponent from 'components/Home/HomeComponent';
import ClientComponent from 'components/Client/ClientComponent';
import iClientComponent from 'components/IClient/IClient';
import HomeComponent from 'components/Home/Home';
import ClientComponent from 'components/Client/Client';
import AreaComponent from 'components/Area/Area';

ReactDOM.render(
Expand Down
65 changes: 30 additions & 35 deletions app/components/Area/Area.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,63 @@
import React from 'react';
import { Router, Link } from 'react-router'
import { Link } from 'react-router'

import Visit from 'services/Visit';
import VisitService from 'services/Visit'

import Visit from 'components/Visit/Visit'
import ErrorComponent from 'components/Error/Error'

class Area extends React.Component
{
constructor(props) {
super(props);
this.state = {
areas : []
areas : [],
error : ''
};
this.renderVisit = this.renderVisit.bind(this);
this.renderArea = this.renderArea.bind(this);
this.generate = this.generate.bind(this);
this.generateError = this.generateError.bind(this);
this.getVisitGroupByArea = this.getVisitGroupByArea.bind(this);
this.getVisitGroupByArea();
}

getVisitGroupByArea() {
Visit.getGroupByArea().then((response) => {
this.setState({areas: response.data.visits});
VisitService.getGroupByArea().then((response) => {
this.setState({error: ''});
this.setState({
areas: this.generate(response.data.visits)
});
}).catch((error) => {
if (error.response) {
this.setState({error: error.response.data.error});
}
});
}

renderVisit(visits) {
return visits.map((areaVisit, key) => {
return (
<tr key={ key } >
<td>{ areaVisit.visit.client.name }</td>
<td>{ areaVisit.visit.visit_date }</td>
<td className="is-icon">
<Link to={ `/visit/${areaVisit.visit._id}` } >
<i className="fa fa-info-circle" />
</Link>
</td>
</tr>
);
});
generateError(error) {
return (
<ErrorComponent error={this.state.error} />
);
}

renderArea(areas) {
generate(areas) {
return areas.map((area, key) => {
return (
<div className="area" key={ key }>
<h3 className="title is-3">{area._id}</h3>
<table className="table">
<thead>
<tr>
<th>Name</th>
<th>Last Visit</th>
<th />
</tr>
</thead>
<tbody>
{this.renderVisit(area.visits)}
</tbody>
</table>
<Visit visits={area.visits} />
</div>
);
});
}

render() {
if (this.state.error) {
let error = this.generateError(this.state.error);
return error;
}
return (
<div className="container hello">
{ this.renderArea(this.state.areas) }
{ this.state.areas }
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import React from 'react';

import Client from 'services/Client';
import ClientService from 'services/Client';
import Error from 'components/Error/Error'

class ClientComponent extends React.Component
class Client extends React.Component
{
constructor(props) {
super(props);
this.state = {
clients : []
clients : [],
error : ''
};
this.getClients();
}

getClients() {
Client.getClients().then((response) => {
ClientService.getClients().then((response) => {
this.setState({clients: response.data.clients});
}).catch((error) => {
this.setState({error: 'Error Found: Trying get client'});
if (error.response) {
this.setState({error: error.response.data.error});
}
});
}

render() {
if (this.state.error) {
return (<Error error={this.state.error} />);
}
const clientList = this.state.clients.map((client, key) => {
return (
<tr key={key} >
Expand Down Expand Up @@ -52,5 +62,5 @@ class ClientComponent extends React.Component
}
}

export default ClientComponent;
export default Client;

2 changes: 2 additions & 0 deletions app/components/Error/Error.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ const Error = ({error}) => (
{error}
</div> : null
);

export default Error;

Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from 'react';
import { Router } from 'react-router'

class HomeComponent extends React.Component{
class Home extends React.Component{

render() {
if (!localStorage.token) {
this.context.router.push("/");
}
return (
<div className="hero-body">
<div className="container">
Expand All @@ -19,10 +15,5 @@ class HomeComponent extends React.Component{
}
}

HomeComponent.contextTypes = {
router: React.PropTypes.object.isRequired
};

export default HomeComponent;

export default Home;

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { Router, Route, IndexRoute, IndexLink, Link } from 'react-router'

import LoginComponent from 'components/Login/LoginComponent';
import LoginComponent from 'components/Login/Login';
import MenuComponent from 'components/Menu/Menu';

class iClientComponent extends React.Component{
constructor(props) {
super(props);
class IClient extends React.Component
{
constructor(props, context) {
super(props, context);
this.handleView = this.handleView.bind(this);
}

Expand All @@ -20,10 +20,11 @@ class iClientComponent extends React.Component{
</div>
);
}

render() {
let view = this.handleView();

if (!localStorage.token) {
if (!window.localStorage.getItem('token')) {
view = <LoginComponent />;
}
return (
Expand All @@ -32,5 +33,5 @@ class iClientComponent extends React.Component{
}
}

export default iClientComponent;
export default IClient;

55 changes: 55 additions & 0 deletions app/components/LinksApp/LinksApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { Link } from 'react-router'

class LinksApp extends React.Component
{
constructor(props, context) {
super(props, context);
this.generate = this.generate.bind(this);
this.handleClick = this.handleClick.bind(this);
this.state = {
links: this.props.links
};
}

handleClick(e) {
if (this.context.onClick) {
this.context.onClick();
}
}

generate() {
return this.state.links.map((link, index) => {
return (
<Link to={link[0]}
key={index}
className="nav-item is-tab"
onlyActiveOnIndex={true}
activeClassName="is-active"
onClick={this.handleClick}
>
{link[1]}
</Link>
);
});
}

render() {
return (
<span className="nav-right nav-menu is-active">
{this.generate()}
</span>
);
}
}

LinksApp.propTypes = {
links: React.PropTypes.array.isRequired
};

LinksApp.contextTypes = {
onClick: React.PropTypes.func
};

export default LinksApp;

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { Router } from 'react-router'
import User from 'services/User';
import ErrorComponent from 'components/Error/Error';

class LoginComponent extends React.Component
class Login extends React.Component
{
constructor(props, context) {
super(props, context);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleDeleteMessage = this.handleDeleteMessage.bind(this);
this.state = {
error: ''
};
Expand All @@ -23,7 +22,7 @@ class LoginComponent extends React.Component
this.refs.password.value
).then((response) => {
if (response.data.success == 200) {
localStorage.token = response.data.token;
window.localStorage.setItem('token', response.data.token);
this.context.router.push("/");
}
}).catch((error) => {
Expand All @@ -34,10 +33,6 @@ class LoginComponent extends React.Component
});
}

handleDeleteMessage() {
this.setState({error: ''});
}

render() {
return (
<section className="hero is-fullheight is-primary">
Expand Down Expand Up @@ -84,8 +79,9 @@ class LoginComponent extends React.Component
}
}

LoginComponent.contextTypes = {
Login.contextTypes = {
router: React.PropTypes.object.isRequired
};

export default LoginComponent;
export default Login;

Loading

0 comments on commit 792fe98

Please sign in to comment.