From f57690696af1b2b37289cc76e6aae35f0814524c Mon Sep 17 00:00:00 2001
From: Conrad
Date: Tue, 30 May 2017 12:12:00 -0400
Subject: [PATCH] Disable fetch and upload buttons until create account returns
correctly from the server
---
src/components/ErrorAlert/index.js | 2 +-
src/components/Utilities/index.js | 3 +-
src/components/UtilityAccount/index.js | 62 ++++++++++++++------------
3 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/src/components/ErrorAlert/index.js b/src/components/ErrorAlert/index.js
index 87d606aa..e0fdbc00 100644
--- a/src/components/ErrorAlert/index.js
+++ b/src/components/ErrorAlert/index.js
@@ -15,7 +15,7 @@ class ErrorAlert extends Component {
if (error) {
error.responseBody.then((res) => {
- this.setState({ errMessage: res.data });
+ this.setState({ errMessage: JSON.stringify(res.data) });
});
}
}
diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js
index c526b49e..a5cf9a18 100644
--- a/src/components/Utilities/index.js
+++ b/src/components/Utilities/index.js
@@ -210,6 +210,7 @@ class Utilities extends Component {
accountId = null,
billData = [],
disaggregateData = [],
+
) => {
let accountProps = {};
const { accountsCounter } = this.state;
@@ -219,7 +220,7 @@ class Utilities extends Component {
account_id: accountId,
billData,
disaggregateData,
- disabled: true,
+ accountCreated: true,
};
}
diff --git a/src/components/UtilityAccount/index.js b/src/components/UtilityAccount/index.js
index e6e9bf6e..f1be0dbf 100644
--- a/src/components/UtilityAccount/index.js
+++ b/src/components/UtilityAccount/index.js
@@ -19,7 +19,8 @@ class UtilityAccount extends Component {
account_id: this.props.account_id,
billData: this.props.billData,
disaggregateData: this.props.disaggregateData,
- disabled: this.props.disabled,
+ accountCreated: this.props.accountCreated,
+ disableButtons: false,
convertingFile: false,
displayBillData: false,
displayDisaggregateData: false,
@@ -154,7 +155,12 @@ class UtilityAccount extends Component {
handleCreateAccount = (event) => {
event.preventDefault();
- this.setState({ disabled: true });
+ this.setState({
+ accountCreated: true,
+ // Disable all of the buttons until the create account returns succesfully
+ // The buttons will be reenabled when the component is recreated by the parent
+ disableButtons: true,
+ });
this.props.createAccount({ ...this.state.form });
}
@@ -273,7 +279,7 @@ class UtilityAccount extends Component {
name={type}
className="file"
onChange={this.uploadHandler}
- disabled={disabled}
+ disabled={disabled || this.state.disableButtons}
/>
@@ -595,7 +601,7 @@ class UtilityAccount extends Component {
placeholder="password"
value={this.state.form.password}
onChange={this.handleInputChange}
- disabled={this.state.disabled}
+ disabled={this.state.accountCreated}
/>
@@ -603,13 +609,15 @@ class UtilityAccount extends Component {
);
}
return (
-
+
+
+
);
}
@@ -626,7 +634,7 @@ class UtilityAccount extends Component {
placeholder="username"
value={this.state.form.username}
onChange={this.handleInputChange}
- disabled={this.state.disabled}
+ disabled={this.state.accountCreated}
/>
@@ -635,7 +643,7 @@ class UtilityAccount extends Component {
placeholder="password"
value={this.state.form.password}
onChange={this.handleInputChange}
- disabled={this.state.disabled}
+ disabled={this.state.accountCreated}
/>
@@ -644,7 +652,7 @@ class UtilityAccount extends Component {
placeholder="access code"
value={this.state.form.access_code}
onChange={this.handleInputChange}
- disabled={this.state.disabled || false}
+ disabled={this.state.accountCreated || false}
/>
@@ -666,7 +674,7 @@ class UtilityAccount extends Component {
name="utility"
value={this.state.form.utility}
onChange={this.handleInputChange}
- disabled={this.state.disabled}
+ disabled={this.state.accountCreated}
>
@@ -679,14 +687,12 @@ class UtilityAccount extends Component {
-
- {this.renderUtility()}
-
+ {this.renderUtility()}
{this.renderNatGrid()}
- {this.state.disabled && this.renderFetchBtn()}
- {!this.state.disabled ?
+ {this.state.accountCreated && this.renderFetchBtn()}
+ {!this.state.accountCreated ?
this.renderAddAccountBtn() : this.renderDeleteAccountBtn()}
{this.showAccountWarning()}
@@ -695,15 +701,15 @@ class UtilityAccount extends Component {
-
{this.state.disabled ? 'Account Details' : ''}
+
{this.state.accountCreated ? 'Account Details' : ''}
- {this.state.disabled && this.renderBillButtons()}
+ {this.state.accountCreated && this.renderBillButtons()}
-
{this.state.disabled ? 'View Data' : ''}
+
{this.state.accountCreated ? 'View Data' : ''}
- {this.state.disabled && this.renderBillViewButtons()}
+ {this.state.accountCreated && this.renderBillViewButtons()}
@@ -753,7 +759,7 @@ UtilityAccount.propTypes = {
other: PropTypes.number,
})
),
- disabled: PropTypes.bool,
+ accountCreated: PropTypes.bool,
createAccount: PropTypes.func,
deleteAccount: PropTypes.func,
fetchUtilityBill: PropTypes.func,
@@ -772,7 +778,7 @@ UtilityAccount.defaultProps = {
account_id: null,
disaggregateData: [],
billData: [],
- disabled: false,
+ accountCreated: false,
};
export default UtilityAccount;
--
GitLab