From 285fc3b4e981f9470a81b9935bbfea0eeaffaa18 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 30 Jan 2017 17:11:09 -0500 Subject: [PATCH 01/11] Add utility components --- .vscode/settings.json | 4 ++ src/components/Utilities/index.js | 12 +++++ src/components/Utilities/styles.css | 0 src/components/UtilityForm/index.js | 77 +++++++++++++++++++++++++++ src/components/UtilityForm/styles.css | 0 src/routes.js | 3 +- 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 src/components/Utilities/index.js create mode 100644 src/components/Utilities/styles.css create mode 100644 src/components/UtilityForm/index.js create mode 100644 src/components/UtilityForm/styles.css diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c67846a6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "editor.tabSize": 2 +} \ No newline at end of file diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js new file mode 100644 index 00000000..76abe781 --- /dev/null +++ b/src/components/Utilities/index.js @@ -0,0 +1,12 @@ +import React from 'react'; + +import UtilityForm from '../UtilityForm'; + +export default function Utilities() { + return ( +
+ + +
+ ); +} diff --git a/src/components/Utilities/styles.css b/src/components/Utilities/styles.css new file mode 100644 index 00000000..e69de29b diff --git a/src/components/UtilityForm/index.js b/src/components/UtilityForm/index.js new file mode 100644 index 00000000..ca8f8500 --- /dev/null +++ b/src/components/UtilityForm/index.js @@ -0,0 +1,77 @@ +import React, { Component, PropTypes } from 'react'; + +class UtilityForm extends Component { + constructor(props) { + super(props); + + this.state = { + utility: this.props.utility, + account_number: this.props.account_number, + access_code: this.props.access_code, + username: this.props.username, + password: this.props.password, + }; + } + + render() { + return ( +
+
+ + + + + + +
+
+ ); + } +} + +UtilityForm.propTypes = { + utility: PropTypes.string, + account_number: PropTypes.number, + access_code: PropTypes.number, + username: PropTypes.string, + password: PropTypes.string, +}; + +UtilityForm.defaultProps = { + utility: '', + account_number: '', + access_code: '', + username: '', + password: '', +}; + +export default UtilityForm; diff --git a/src/components/UtilityForm/styles.css b/src/components/UtilityForm/styles.css new file mode 100644 index 00000000..e69de29b diff --git a/src/routes.js b/src/routes.js index ef2a8816..c64dc2a6 100644 --- a/src/routes.js +++ b/src/routes.js @@ -9,6 +9,7 @@ import HomePage from './screens/HomePage'; import BuildingDetail from './screens/BuildingDetail'; import BuildingOverview from './containers/BuildingOverview'; +import Utilities from './components/Utilities'; import Dummy from './components/dummyComponent'; export default ( @@ -23,7 +24,7 @@ export default ( - + -- GitLab From 4b89f757fc06b0b313e8eebafdfd0be6fd1043e7 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 30 Jan 2017 17:23:46 -0500 Subject: [PATCH 02/11] Add disable property to utility form --- src/components/UtilityForm/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/UtilityForm/index.js b/src/components/UtilityForm/index.js index ca8f8500..7eed27be 100644 --- a/src/components/UtilityForm/index.js +++ b/src/components/UtilityForm/index.js @@ -20,6 +20,9 @@ class UtilityForm extends Component { this.setState({ username: event.target.value })} + disabled={this.props.disable || false} /> this.setState({ password: event.target.value })} + disabled={this.props.disable || false} /> - - ); +class Utilities extends Component { + constructor(props) { + super(props); + + this.state = { + accountLines: [], + }; + } + + componentDidMount() { + this.addAccountLine(); + } + + addAccount = () => { + this.addAccountLine(); + } + + addAccountLine = () => { + const curr = this.state.accountLines; + curr.push(); + this.setState({ accountLines: curr }); + } + + render() { + return ( +
+ {this.state.accountLines} +
+ ); + } } + +Utilities.propTypes = { + buildingId: PropTypes.string, +}; + +export default Utilities; diff --git a/src/components/UtilityForm/index.js b/src/components/UtilityForm/index.js index 7eed27be..d52e07d9 100644 --- a/src/components/UtilityForm/index.js +++ b/src/components/UtilityForm/index.js @@ -1,69 +1,104 @@ import React, { Component, PropTypes } from 'react'; +import request from '../../utils/request'; +import { getHeaders, utilityURL } from '../../utils/rest_services'; class UtilityForm extends Component { constructor(props) { super(props); this.state = { - utility: this.props.utility, - account_number: this.props.account_number, - access_code: this.props.access_code, - username: this.props.username, - password: this.props.password, + disabled: this.props.disabled, + form: { + utility: this.props.utility, + account_numbers: this.props.account_numbers, + username: this.props.username, + password: this.props.password, + }, }; } + handleInputChange = (event) => { + this.setState({ + form: { + ...this.state.form, + [event.target.name]: event.target.value, + }, + }); + } + + handleClick = (event) => { + event.preventDefault(); + this.setState({ disabled: true }); + request(utilityURL, { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify({ + ...this.state.form, + building_id: this.props.buildingId, + }), + }).then((data) => { + console.log(data); + }); + this.props.addAccount(); + } + render() { return (
-
+ this.setState({ account_number: event.target.value })} - disabled={this.props.disable || false} - /> - this.setState({ username: event.target.value })} - disabled={this.props.disable || false} - /> - this.setState({ password: event.target.value })} - disabled={this.props.disable || false} + value={this.state.form.account_number} + onChange={this.handleInputChange} + disabled={this.state.disabled || false} /> + {this.state.utility !== 'national_grid_gas' || +
+ + +
+ } - + + }
); @@ -71,18 +106,19 @@ class UtilityForm extends Component { } UtilityForm.propTypes = { - disable: PropTypes.bool, + disabled: PropTypes.bool, + buildingId: PropTypes.string, utility: PropTypes.string, - account_number: PropTypes.number, - access_code: PropTypes.number, + account_numbers: PropTypes.string, username: PropTypes.string, password: PropTypes.string, + addAccount: PropTypes.func, }; UtilityForm.defaultProps = { disable: false, utility: 'con_edison_electric', - account_number: '', + account_numbers: '', access_code: '', username: '', password: '', diff --git a/src/screens/BuildingDetail/index.js b/src/screens/BuildingDetail/index.js index 620e993e..85cfdc0d 100644 --- a/src/screens/BuildingDetail/index.js +++ b/src/screens/BuildingDetail/index.js @@ -12,7 +12,9 @@ export default function BuildingDetail(props) {
- {props.children} + {props.children && React.cloneElement(props.children, { + buildingId: props.params.buildingID, + })}
); diff --git a/src/utils/rest_services.js b/src/utils/rest_services.js index 04fb1634..e60bf65d 100644 --- a/src/utils/rest_services.js +++ b/src/utils/rest_services.js @@ -5,5 +5,8 @@ export function getHeaders() { }); } -export const buildingsURL = `${process.env.REACT_APP_BUILDING_SERVICE}/building/`; -export const turkURL = `${process.env.REACT_APP_BUILDING_SERVICE}/turkhit/`; +const buildingService = process.env.REACT_APP_BUILDING_SERVICE; + +export const buildingsURL = `${buildingService}/building/`; +export const turkURL = `${buildingService}/turkhit/`; +export const utilityURL = `${buildingService}/scraper/`; -- GitLab From ebf348a37607246a96acba9f019fe7b6d6d1872c Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 01:57:35 -0500 Subject: [PATCH 05/11] Retrieve data on component mount for utilties --- src/components/Utilities/index.js | 21 +++++++- src/components/UtilityForm/index.js | 80 +++++++++++++++-------------- 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 2b4fc0a1..658057f1 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -1,4 +1,6 @@ import React, { Component, PropTypes } from 'react'; +import request from '../../utils/request'; +import { getHeaders, utilityURL } from '../../utils/rest_services'; import UtilityForm from '../UtilityForm'; @@ -12,19 +14,34 @@ class Utilities extends Component { } componentDidMount() { - this.addAccountLine(); + request(`${utilityURL}${this.props.buildingId}`, { + method: 'GET', + headers: getHeaders(), + }).then(({ data }) => { + data.accounts.forEach((item) => { + this.addAccountLine({ + utility: item.type, + account_numbers: item.account, + username: item.login, + password: item.pass, + }, true); + }); + this.addAccountLine(); + }); } addAccount = () => { this.addAccountLine(); } - addAccountLine = () => { + addAccountLine = (form, disabled = false) => { const curr = this.state.accountLines; curr.push(); this.setState({ accountLines: curr }); } diff --git a/src/components/UtilityForm/index.js b/src/components/UtilityForm/index.js index d52e07d9..03ff1397 100644 --- a/src/components/UtilityForm/index.js +++ b/src/components/UtilityForm/index.js @@ -9,10 +9,10 @@ class UtilityForm extends Component { this.state = { disabled: this.props.disabled, form: { - utility: this.props.utility, - account_numbers: this.props.account_numbers, - username: this.props.username, - password: this.props.password, + utility: this.props.form.utility, + account_numbers: this.props.form.account_numbers, + username: this.props.form.username, + password: this.props.form.password, }, }; } @@ -43,14 +43,15 @@ class UtilityForm extends Component { } render() { + const natGrid = this.state.form.utility === 'national_grid_gas' ? '' : 'hidden'; return (
- -
- } +
+ + +
{!this.state.disabled || Download } +
); } @@ -108,20 +107,25 @@ class UtilityForm extends Component { UtilityForm.propTypes = { disabled: PropTypes.bool, buildingId: PropTypes.string, - utility: PropTypes.string, - account_numbers: PropTypes.string, - username: PropTypes.string, - password: PropTypes.string, + form: PropTypes.shape({ + utility: PropTypes.string, + account_numbers: PropTypes.string, + username: PropTypes.string, + password: PropTypes.string, + addAccount: PropTypes.func, + }), addAccount: PropTypes.func, }; UtilityForm.defaultProps = { disable: false, - utility: 'con_edison_electric', - account_numbers: '', - access_code: '', - username: '', - password: '', + form: { + utility: 'con_edison_electric', + account_numbers: '', + access_code: '', + username: '', + password: '', + }, }; export default UtilityForm; -- GitLab From 3028a91c2683e7d6d83539c6ac80d66012a6e4e7 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 13:53:02 -0500 Subject: [PATCH 06/11] Update util field names on GET --- src/components/Utilities/index.js | 37 ++++++++++++++++------------- src/components/UtilityForm/index.js | 3 +++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 658057f1..1754c048 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -10,6 +10,7 @@ class Utilities extends Component { this.state = { accountLines: [], + error: false, }; } @@ -17,31 +18,34 @@ class Utilities extends Component { request(`${utilityURL}${this.props.buildingId}`, { method: 'GET', headers: getHeaders(), - }).then(({ data }) => { - data.accounts.forEach((item) => { - this.addAccountLine({ - utility: item.type, - account_numbers: item.account, - username: item.login, - password: item.pass, - }, true); - }); - this.addAccountLine(); + }).then((res) => { + if (!res.err && res.data.box_building_list) { + res.data.box_building_list.forEach((item) => { + this.addAccountLine({ + utility: item.type, + account_numbers: item.account, + username: item.login, + password: item.pass, + }, + item.url_download, + true); + }); + this.addAccountLine(); + } else if (res.err) { + this.setState({ error: res.err.message }); + } }); } - addAccount = () => { - this.addAccountLine(); - } - - addAccountLine = (form, disabled = false) => { + addAccountLine = (form, downloadURL, disabled = false) => { const curr = this.state.accountLines; curr.push(); this.setState({ accountLines: curr }); } @@ -49,6 +53,7 @@ class Utilities extends Component { render() { return (
+ {this.state.error} {this.state.accountLines}
); diff --git a/src/components/UtilityForm/index.js b/src/components/UtilityForm/index.js index 03ff1397..499f4e7c 100644 --- a/src/components/UtilityForm/index.js +++ b/src/components/UtilityForm/index.js @@ -14,6 +14,7 @@ class UtilityForm extends Component { username: this.props.form.username, password: this.props.form.password, }, + downloadURL: this.props.downloadURL, }; } @@ -93,6 +94,7 @@ class UtilityForm extends Component { {!this.state.disabled || Download @@ -114,6 +116,7 @@ UtilityForm.propTypes = { password: PropTypes.string, addAccount: PropTypes.func, }), + downloadURL: PropTypes.string, addAccount: PropTypes.func, }; -- GitLab From eb87319fd583a7dbf84928252aac8e75d95dc2b0 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 18:14:23 -0500 Subject: [PATCH 07/11] Add address from redux to Utilities component --- src/components/Utilities/index.js | 65 +++++++++++++++++-- src/components/UtilityForm/index.js | 30 +++++++-- .../buildingDetailPropType.js | 20 ++++++ src/containers/BuildingOverview/index.js | 20 +----- 4 files changed, 105 insertions(+), 30 deletions(-) create mode 100644 src/containers/BuildingOverview/buildingDetailPropType.js diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 1754c048..8509c9ee 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -1,7 +1,12 @@ import React, { Component, PropTypes } from 'react'; +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; +import buildingDetailPropTypes from '../../containers/BuildingOverview/buildingDetailPropType'; + import request from '../../utils/request'; import { getHeaders, utilityURL } from '../../utils/rest_services'; +import { loadBuildingDetail } from '../../containers/BuildingOverview/actions'; import UtilityForm from '../UtilityForm'; class Utilities extends Component { @@ -15,12 +20,32 @@ class Utilities extends Component { } componentDidMount() { - request(`${utilityURL}${this.props.buildingId}`, { + const { address, building_id } = this.props.buildingDetail.overview; + + // TODO remove getting adress, should be done in backend + /* eslint-disable camelcase */ + if (!address || this.props.buildingId !== building_id) { + this.props.loadBuildingDetail(this.props.buildingId); + } else if (address && this.props.buildingId === building_id) { + this.getUtilityAccounts(address); + } + } + + componentDidUpdate(prevProps) { + const { address, building_id } = this.props.buildingDetail.overview; + const prevAddress = prevProps.buildingDetail.overview.address; + if (parseInt(this.props.buildingId, 10) === building_id && prevAddress !== address) { + this.getUtilityAccounts(address); + } + } + + getUtilityAccounts(address) { + request(`${utilityURL}${this.props.buildingId}?address=${address}`, { method: 'GET', headers: getHeaders(), }).then((res) => { - if (!res.err && res.data.box_building_list) { - res.data.box_building_list.forEach((item) => { + if (!res.err && res.data.utilities) { + res.data.utilities.forEach((item) => { this.addAccountLine({ utility: item.type, account_numbers: item.account, @@ -37,11 +62,31 @@ class Utilities extends Component { }); } + deleteAccountLine = (lineItem) => { + const accounts = this.state.accountLines; + const accountToRemove = lineItem.props.form.account_numbers; + + request(`${utilityURL}${this.props.buildingId}?=account_number=${accountToRemove}`, { + method: 'GET', + headers: getHeaders(), + }).then((res) => { + console.log(res); + }); + /* eslint-disable arrow-body-style */ + // TODO remove eslint disable + const newAccounts = accounts.filter((item) => { + return item.props.form.account_numbers !== accountToRemove; + }); + /* eslint-enable */ + this.setState({ accountLines: newAccounts }); + } + addAccountLine = (form, downloadURL, disabled = false) => { const curr = this.state.accountLines; curr.push( { + event.preventDefault(); + this.props.deleteAccount(this); + } + render() { const natGrid = this.state.form.utility === 'national_grid_gas' ? '' : 'hidden'; return ( @@ -85,20 +91,29 @@ class UtilityForm extends Component { disabled={this.state.disabled || false} /> - {!this.state.disabled || Download } + + + {!this.state.disabled || + + }
@@ -118,6 +133,7 @@ UtilityForm.propTypes = { }), downloadURL: PropTypes.string, addAccount: PropTypes.func, + deleteAccount: PropTypes.func, }; UtilityForm.defaultProps = { diff --git a/src/containers/BuildingOverview/buildingDetailPropType.js b/src/containers/BuildingOverview/buildingDetailPropType.js new file mode 100644 index 00000000..6cdf609e --- /dev/null +++ b/src/containers/BuildingOverview/buildingDetailPropType.js @@ -0,0 +1,20 @@ +import { PropTypes } from 'react'; + +export default PropTypes.shape({ + overview: PropTypes.shape({ + address: PropTypes.string, + bbl: PropTypes.number, + building_id: PropTypes.number, + lot_id: PropTypes.number, + borough: PropTypes.string, + zipcode: PropTypes.number, + loading: PropTypes.boolean, + error: PropTypes.boolean, + }), + hit: PropTypes.shape({ + id: PropTypes.string, + status: PropTypes.string, + loading: PropTypes.boolean, + error: PropTypes.boolean, + }), +}); diff --git a/src/containers/BuildingOverview/index.js b/src/containers/BuildingOverview/index.js index c813797f..24e62a01 100644 --- a/src/containers/BuildingOverview/index.js +++ b/src/containers/BuildingOverview/index.js @@ -1,6 +1,7 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; +import buildingDetailPropTypes from './buildingDetailPropType'; import { loadBuildingDetail, @@ -58,24 +59,7 @@ class BuildingOverview extends Component { } BuildingOverview.propTypes = { - buildingDetail: PropTypes.shape({ - overview: PropTypes.shape({ - address: PropTypes.string, - bbl: PropTypes.number, - building_id: PropTypes.number, - lot_id: PropTypes.number, - borough: PropTypes.string, - zipcode: PropTypes.number, - loading: PropTypes.boolean, - error: PropTypes.boolean, - }), - hit: PropTypes.shape({ - id: PropTypes.string, - status: PropTypes.string, - loading: PropTypes.boolean, - error: PropTypes.boolean, - }), - }), + buildingDetail: buildingDetailPropTypes, params: PropTypes.objectOf(PropTypes.string), loadBuildingDetail: PropTypes.func, loadHit: PropTypes.func, -- GitLab From ea12ade881502857a5de8cca5451c0ddc5604b28 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 19:51:36 -0500 Subject: [PATCH 08/11] Create getUtilBill function --- src/components/Utilities/index.js | 77 +++++++++++++++++++++------- src/components/UtilityForm/index.js | 79 +++++++++++++++-------------- 2 files changed, 100 insertions(+), 56 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 8509c9ee..f294853e 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -39,7 +39,7 @@ class Utilities extends Component { } } - getUtilityAccounts(address) { + getUtilityAccounts = (address) => { request(`${utilityURL}${this.props.buildingId}?address=${address}`, { method: 'GET', headers: getHeaders(), @@ -47,13 +47,15 @@ class Utilities extends Component { if (!res.err && res.data.utilities) { res.data.utilities.forEach((item) => { this.addAccountLine({ + building_address: address, utility: item.type, - account_numbers: item.account, + account_number: item.account_number, username: item.login, password: item.pass, + access_code: item.access_code, }, - item.url_download, - true); + item.url_download, + true); }); this.addAccountLine(); } else if (res.err) { @@ -62,32 +64,71 @@ class Utilities extends Component { }); } + getUtilityBill = (form) => { + request(utilityURL, { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify({ + ...form, + building_id: parseInt(this.props.buildingId, 10), + building_address: this.props.buildingDetail.overview.address, + }), + }).then((res) => { + // TODO handle error + if (res.err) { + console.error(res.err); + } + }); + } + + createAccount = (form) => { + request(utilityURL, { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify({ + ...form, + building_id: parseInt(this.props.buildingId, 10), + building_address: this.props.buildingDetail.overview.address, + }), + }).then((res) => { + // TODO handle error + if (res.err) { + console.error(res.err); + } + }); + this.addAccountLine(); + } + deleteAccountLine = (lineItem) => { const accounts = this.state.accountLines; - const accountToRemove = lineItem.props.form.account_numbers; + const accountToRemove = lineItem.props.form.account_number; - request(`${utilityURL}${this.props.buildingId}?=account_number=${accountToRemove}`, { - method: 'GET', + request(`${utilityURL}${this.props.buildingId}?account_number=${accountToRemove}`, { + method: 'DELETE', headers: getHeaders(), }).then((res) => { - console.log(res); - }); - /* eslint-disable arrow-body-style */ - // TODO remove eslint disable - const newAccounts = accounts.filter((item) => { - return item.props.form.account_numbers !== accountToRemove; + if (!res.err) { + /* eslint-disable arrow-body-style */ + // TODO remove eslint disable + const newAccounts = accounts.filter((item) => { + return item.props.form.account_number !== accountToRemove; + }); + /* eslint-enable */ + this.setState({ accountLines: newAccounts }); + } else { + // TODO handle error + console.error(res.err); + } }); - /* eslint-enable */ - this.setState({ accountLines: newAccounts }); } addAccountLine = (form, downloadURL, disabled = false) => { const curr = this.state.accountLines; curr.push( { + event.preventDefault(); + this.props.getUtilityBill(this.state.form); + } + handleInputChange = (event) => { this.setState({ form: { @@ -28,23 +32,13 @@ class UtilityForm extends Component { }); } - handleClick = (event) => { + handleCreateAccount = (event) => { event.preventDefault(); this.setState({ disabled: true }); - request(utilityURL, { - method: 'POST', - headers: getHeaders(), - body: JSON.stringify({ - ...this.state.form, - building_id: this.props.buildingId, - }), - }).then((data) => { - console.log(data); - }); - this.props.addAccount(); + this.props.createAccount(this.state.form); } - deleteAccount = (event) => { + handleDeleteAccount = (event) => { event.preventDefault(); this.props.deleteAccount(this); } @@ -66,10 +60,10 @@ class UtilityForm extends Component { @@ -92,27 +86,34 @@ class UtilityForm extends Component { /> {!this.state.disabled || - - Download - +
+ + Download + + + +
} + {this.state.disabled || - - {!this.state.disabled || - }
@@ -123,24 +124,26 @@ class UtilityForm extends Component { UtilityForm.propTypes = { disabled: PropTypes.bool, - buildingId: PropTypes.string, form: PropTypes.shape({ + building_address: PropTypes.string, utility: PropTypes.string, - account_numbers: PropTypes.string, + account_number: PropTypes.string, + access_code: PropTypes.string, username: PropTypes.string, password: PropTypes.string, - addAccount: PropTypes.func, }), downloadURL: PropTypes.string, - addAccount: PropTypes.func, + createAccount: PropTypes.func, deleteAccount: PropTypes.func, + getUtilityBill: PropTypes.func, }; UtilityForm.defaultProps = { disable: false, form: { + building_address: '', utility: 'con_edison_electric', - account_numbers: '', + account_number: '', access_code: '', username: '', password: '', -- GitLab From 29017a1320e6d024f61a8c3a50fcfb7622194df0 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 19:57:15 -0500 Subject: [PATCH 09/11] Add env var REACT_APP_UTILITY_SERVICE --- src/utils/rest_services.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/rest_services.js b/src/utils/rest_services.js index e60bf65d..4f2a2c16 100644 --- a/src/utils/rest_services.js +++ b/src/utils/rest_services.js @@ -6,7 +6,8 @@ export function getHeaders() { } const buildingService = process.env.REACT_APP_BUILDING_SERVICE; +const utilityService = process.env.REACT_APP_UTILITY_SERVICE; export const buildingsURL = `${buildingService}/building/`; export const turkURL = `${buildingService}/turkhit/`; -export const utilityURL = `${buildingService}/scraper/`; +export const utilityURL = `${utilityService}/scraper/`; -- GitLab From cbacdc56e0c5e494cdc4cf254d88f10266985683 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 20:19:20 -0500 Subject: [PATCH 10/11] Add error message above utilities form --- src/components/Utilities/index.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index f294853e..b8b7738d 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -74,9 +74,8 @@ class Utilities extends Component { building_address: this.props.buildingDetail.overview.address, }), }).then((res) => { - // TODO handle error if (res.err) { - console.error(res.err); + this.setState({ error: 'Failed to retrieve utility bill' }); } }); } @@ -91,9 +90,8 @@ class Utilities extends Component { building_address: this.props.buildingDetail.overview.address, }), }).then((res) => { - // TODO handle error if (res.err) { - console.error(res.err); + this.setState({ error: 'Failed to create account' }); } }); this.addAccountLine(); @@ -116,8 +114,7 @@ class Utilities extends Component { /* eslint-enable */ this.setState({ accountLines: newAccounts }); } else { - // TODO handle error - console.error(res.err); + this.setState({ error: 'Failed to delete account' }); } }); } @@ -139,7 +136,7 @@ class Utilities extends Component { render() { return (
- {this.state.error} +
{this.state.error}
{this.state.accountLines}
); -- GitLab From a6956d274dc57905321d1b870900758bccbc12a5 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 31 Jan 2017 20:43:28 -0500 Subject: [PATCH 11/11] Fix formatting for alert in utilities --- src/components/Utilities/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index b8b7738d..e6264e18 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -136,7 +136,12 @@ class Utilities extends Component { render() { return (
-
{this.state.error}
+
+ {this.state.error} +
{this.state.accountLines}
); -- GitLab