diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js
index a114657dbbffa84179d40856276de178eed35073..9cf5e49ae81d251ea1f462be6bf389080a427ecc 100644
--- a/src/components/Utilities/index.js
+++ b/src/components/Utilities/index.js
@@ -64,7 +64,8 @@ class Utilities extends Component {
});
}
- getUtilityBill = (form) => {
+ /* eslint-disable arrow-body-style */
+ getUtilityBill = (form, updateLoadingState, setDownloadURL) => {
request(utilityURL, {
method: 'PUT',
headers: getHeaders(),
@@ -76,10 +77,14 @@ class Utilities extends Component {
}).then((res) => {
if (res.err) {
this.setState({ error: 'Failed to retrieve utility bill' });
+ } else {
+ setDownloadURL(res.data.download_url);
}
+ updateLoadingState(false);
});
}
+
createAccount = (form) => {
request(utilityURL, {
method: 'POST',
@@ -119,7 +124,7 @@ class Utilities extends Component {
});
}
- addAccountLine = (form, downloadURL, disabled = false) => {
+ addAccountLine = (form, downloadURL, disabled = false, loading = 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 ee6c64b07148bad09f9e3e8cb354e74d8cc7733e..add05d4875b38fcbc729c68ac0a8f10d63802c53 100644
--- a/src/components/UtilityForm/index.js
+++ b/src/components/UtilityForm/index.js
@@ -7,6 +7,7 @@ class UtilityForm extends Component {
this.state = {
disabled: this.props.disabled,
+ loading: this.props.loading,
form: {
utility: this.props.form.utility,
account_number: this.props.form.account_number,
@@ -20,7 +21,17 @@ class UtilityForm extends Component {
getUtilityBill = (event) => {
event.preventDefault();
- this.props.getUtilityBill(this.state.form);
+ this.updateLoadingState(true);
+ this.props.getUtilityBill(this.state.form, this.updateLoadingState, this.setDownloadURL);
+ }
+
+ /* eslint-disable arrow-body-style */
+ setDownloadURL = (url) => {
+ this.setState({ downloadURL: url });
+ }
+
+ updateLoadingState = (isLoading) => {
+ this.setState({ loading: isLoading });
}
handleInputChange = (event) => {
@@ -43,8 +54,42 @@ class UtilityForm extends Component {
this.props.deleteAccount(this);
}
+ renderNatGrid = () => {
+ if (this.state.form.utility !== 'national_grid_gas') {
+ return
;
+ }
+
+ return (
+
+
+
+
+
+ );
+ }
+
render() {
- const natGrid = this.state.form.utility === 'national_grid_gas' ? '' : 'hidden';
return (