From a483aeb7fc3b86f1239239dda4b725bead6440df Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 31 May 2017 09:48:06 -0400 Subject: [PATCH 1/2] Add usage type dropdown menu --- src/components/Utilities/index.js | 2 ++ src/components/UtilityAccount/index.js | 41 ++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index c526b49e..0e65517f 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -44,6 +44,7 @@ class Utilities extends Component { username: account.login, password: account.pass, access_code: account.access_code, + usage_type: account.usage_type, }, account.id, account.bill_database_output, @@ -168,6 +169,7 @@ class Utilities extends Component { */ const allAccounts = this.state.accountLines.slice(); allAccounts.pop(); + console.log(form); allAccounts.push(this.createUtilityComponent(form, res.data.id)); allAccounts.push(this.createUtilityComponent()); this.setState({ accountLines: allAccounts }); diff --git a/src/components/UtilityAccount/index.js b/src/components/UtilityAccount/index.js index e6e9bf6e..4d5c3211 100644 --- a/src/components/UtilityAccount/index.js +++ b/src/components/UtilityAccount/index.js @@ -15,6 +15,7 @@ class UtilityAccount extends Component { username: this.props.form.username, password: this.props.form.password, access_code: this.props.form.access_code, + usage_type: this.props.form.usage_type, }, account_id: this.props.account_id, billData: this.props.billData, @@ -62,6 +63,7 @@ class UtilityAccount extends Component { }, }) ) + downloadSVG = (event) => { event.preventDefault(); const chartWrapper = document.getElementsByClassName(this.state.form.account_number)[0]; @@ -155,6 +157,7 @@ class UtilityAccount extends Component { handleCreateAccount = (event) => { event.preventDefault(); this.setState({ disabled: true }); + console.log(this.state.form); this.props.createAccount({ ...this.state.form }); } @@ -282,7 +285,6 @@ class UtilityAccount extends Component { ); } - renderFetchBtn = () => { if (this.state.form.utility.startsWith('other')) { return ( @@ -309,6 +311,15 @@ class UtilityAccount extends Component { ) + renderDeleteAccountBtn = () => ( + + ) + renderBillButtons = () => { const { billData, disaggregateData } = this.state; @@ -572,6 +583,27 @@ class UtilityAccount extends Component { return (
); } + renderDisaggregateDropdown = () => ( + ( +

+ +

+ ) + ) + renderUtility = () => { // Bills with no scrapers do not need account numbers inputted if (this.state.form.utility.startsWith('other')) { @@ -683,12 +715,13 @@ class UtilityAccount extends Component { {this.renderUtility()}

{this.renderNatGrid()} + {this.renderDisaggregateDropdown()}
-

+

{this.state.disabled && this.renderFetchBtn()} {!this.state.disabled ? this.renderAddAccountBtn() : this.renderDeleteAccountBtn()} -

+
{this.showAccountWarning()}
@@ -732,6 +765,7 @@ UtilityAccount.propTypes = { access_code: PropTypes.string, username: PropTypes.string, password: PropTypes.string, + usage_type: PropTypes.string, }), account_id: PropTypes.number, billData: PropTypes.arrayOf( @@ -768,6 +802,7 @@ UtilityAccount.defaultProps = { access_code: '', username: '', password: '', + usage_type: '', }, account_id: null, disaggregateData: [], -- GitLab From e2d0997ab96231ea46cd21e0264a16a7463bdfeb Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 31 May 2017 10:08:13 -0400 Subject: [PATCH 2/2] Update the form right after the account is created to reflect new usage type --- src/components/Utilities/index.js | 10 ++++++++-- src/components/UtilityAccount/index.js | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index 0e65517f..c6bb5183 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -169,8 +169,14 @@ class Utilities extends Component { */ const allAccounts = this.state.accountLines.slice(); allAccounts.pop(); - console.log(form); - allAccounts.push(this.createUtilityComponent(form, res.data.id)); + const newForm = {}; + // Copy the form properties to a new object so we can update it + Object.keys(form).map((val) => { + newForm[val] = form[val]; + return val; + }); + newForm.usage_type = res.data.usage_type; + allAccounts.push(this.createUtilityComponent(newForm, res.data.id)); allAccounts.push(this.createUtilityComponent()); this.setState({ accountLines: allAccounts }); this.resetErrorMessage(); diff --git a/src/components/UtilityAccount/index.js b/src/components/UtilityAccount/index.js index 4d5c3211..1097d1f6 100644 --- a/src/components/UtilityAccount/index.js +++ b/src/components/UtilityAccount/index.js @@ -157,7 +157,6 @@ class UtilityAccount extends Component { handleCreateAccount = (event) => { event.preventDefault(); this.setState({ disabled: true }); - console.log(this.state.form); this.props.createAccount({ ...this.state.form }); } -- GitLab