diff --git a/app/App.js b/app/App.js index 2d2e6a1..fbf35cb 100644 --- a/app/App.js +++ b/app/App.js @@ -1,22 +1,32 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; +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/IClient'; -import HomeComponent from 'components/Home/Home'; -import ClientComponent from 'components/Client/Client'; -import AreaComponent from 'components/Area/Area'; +import iClientComponent from 'components/IClient/IClient' +import HomeComponent from 'components/Home/Home' +import AreaComponent from 'components/Area/Area' +import ListClientComponent from 'components/Client/List/Client' +import ProfileClientComponent from 'components/Client/Profile/Client' +import SaveClientComponent from 'components/Client/Save/Client' +import CreateVisitComponent from 'components/Visit/Create/Visit' +import CreateAreaComponent from 'components/Area/Create/Area' ReactDOM.render( - - + + + + + + + , document.getElementById('app') ); + diff --git a/app/components/Area/Area.js b/app/components/Area/Area.js index f97ac3b..ac8cbf3 100644 --- a/app/components/Area/Area.js +++ b/app/components/Area/Area.js @@ -27,7 +27,7 @@ class Area extends React.Component areas: this.generate(response.data.visits) }); }).catch((error) => { - if (error.response) { + if (typeof error.response.data.error !== 'undefined') { this.setState({error: error.response.data.error}); } }); @@ -57,6 +57,19 @@ class Area extends React.Component } return (
+
+
+

iClient

+
+
+ + + + + New Area + +
+
{ this.state.areas }
); diff --git a/app/components/Area/Create/Area.js b/app/components/Area/Create/Area.js new file mode 100644 index 0000000..ffaa789 --- /dev/null +++ b/app/components/Area/Create/Area.js @@ -0,0 +1,95 @@ +import React from 'react'; +import { Link, Router } from 'react-router' + +import Error from 'components/Error/Error' +import AreaSelect from 'components/Area/Select/Area' +import ClientService from 'services/Client' +import AreaService from 'services/Area' + +class Area extends React.Component +{ + constructor(props, context) { + super(props, context); + this.handleSubmit = this.handleSubmit.bind(this); + this.state = { + error : '', + area : {} + }; + } + + handleSubmit(e) { + e.preventDefault(); + + let form = e.target; + let formData = { + _id : this.refs.area.value, + parent: form.querySelector('[name="parent"]').value + }; + + this.setState({area: formData}); + + AreaService.save(formData).then((response) => { + this.context.router.push("/clients"); + }).catch((error) => { + + this.setState({error: 'Error trying create area'}); + + let responseValid = typeof error.response.data !== 'undefined'; + + if (responseValid && typeof error.response.data.error !== 'undefined') { + this.setState({error: error.response.data.error}); + } + }); + } + + render() { + if (this.state.error) { + return (); + } + + return ( +
+
+
+

+ Create Area +

+
+
+ +

+ + +

+ + +
+

+ + + Cancel + +

+
+ +
+
+
+ ); + } +} + +Area.contextTypes = { + router: React.PropTypes.object.isRequired +}; + +export default Area; + diff --git a/app/components/Area/Select/Area.js b/app/components/Area/Select/Area.js new file mode 100644 index 0000000..12bc999 --- /dev/null +++ b/app/components/Area/Select/Area.js @@ -0,0 +1,58 @@ +import React from 'react'; + +import Error from 'components/Error/Error' +import AreaService from 'services/Area' +import styles from 'components/Area/Select/styles.css' + +class Area extends React.Component +{ + constructor(props, context) { + super(props, context); + this.state = { + error : '', + areas : null, + }; + } + + componentWillMount() { + + AreaService.getAll().then((response) => { + this.setState({areas: response.data.areas}); + }).catch((error) => { + this.setState({error: 'Error Found: Trying get areas'}); + let isValidResponse = typeof error.response.data !== 'undefined'; + if (isValidResponse && typeof error.response.data.error !== 'undefined') { + this.setState({error: error.response.data.error}); + } + }); + } + + render() { + if (this.state.error) { + return (); + } + if (!this.state.areas) { + return
Loading...
; + } + + const select = Object.assign({}, this.props.select); + + return ( +

+ + + +