From 2088065603202ff0ad5beb2b8d5c16d312b9fe84 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Tue, 9 Feb 2016 21:30:07 -0500 Subject: [PATCH] Clean up UI for importing transactions --- static/account_register.js | 72 +++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/static/account_register.js b/static/account_register.js index d52d6a1..648383f 100644 --- a/static/account_register.js +++ b/static/account_register.js @@ -9,6 +9,7 @@ var Table = ReactBootstrap.Table; var Grid = ReactBootstrap.Grid; var Row = ReactBootstrap.Row; var Col = ReactBootstrap.Col; +var Panel = ReactBootstrap.Panel; var Button = ReactBootstrap.Button; var ButtonToolbar = ReactBootstrap.ButtonToolbar; @@ -436,13 +437,19 @@ const AddEditTransactionModal = React.createClass({ const ImportTransactionsModal = React.createClass({ getInitialState: function() { return { + importing: false, + imported: false, importFile: "", - uploadProgress: -1}; + uploadProgress: -1, + error: null}; }, handleCancel: function() { this.setState({ + importing: false, + imported: false, importFile: "", - uploadProgress: -1 + uploadProgress: -1, + error: null }); if (this.props.onCancel != null) this.props.onCancel(); @@ -465,6 +472,7 @@ const ImportTransactionsModal = React.createClass({ handleImportTransactions: function() { var file = this.refs.importfile.getInputDOMNode().files[0]; var formData = new FormData(); + this.setState({importing: true}); formData.append('importfile', file, this.state.importFile); $.ajax({ type: "POST", @@ -479,14 +487,29 @@ const ImportTransactionsModal = React.createClass({ } return xhrObject; }.bind(this), - beforeSend: function() { - console.log("before send"); - }, - success: function() { - this.setState({uploadProgress: 100}); - console.log("success"); + success: function(data, status, jqXHR) { + var e = new Error(); + e.fromJSON(data); + if (e.isError()) { + var errString = e.ErrorString; + if (e.ErrorId == 3 /* Invalid Request */) { + errString = "Please check that the file you uploaded is a valid OFX file for this account and try again."; + } + this.setState({ + importing: false, + error: errString + }); + return; + } + + this.setState({ + uploadProgress: 100, + importing: false, + imported: true + }); }.bind(this), error: function(e) { + this.setState({importing: false}); console.log("error handler", e); }, // So jQuery doesn't try to process teh data or content-type @@ -498,10 +521,31 @@ const ImportTransactionsModal = React.createClass({ render: function() { var accountNameLabel = "" if (this.props.account != null ) - accountNameLabel = "Import File to '" + getAccountDisplayName(this.props.account, this.props.account_map) + "':"; + accountNameLabel = "Importing to '" + getAccountDisplayName(this.props.account, this.props.account_map) + "' account:"; var progressBar = []; - if (this.state.uploadProgress != -1) - progressBar = (); + if (this.state.importing && this.state.uploadProgress == 100) { + progressBar = (); + } else if (this.state.importing && this.state.uploadProgress != -1) { + progressBar = (); + } + + var panel = []; + if (this.state.error != null) { + panel = ({this.state.error}); + } else if (this.state.imported) { + panel = (Your import is now complete.); + } + + var buttonsDisabled = (this.state.importing) ? "disabled" : ""; + var button1 = []; + var button2 = []; + if (!this.state.imported && this.state.error == null) { + button1 = (); + button2 = (); + } else { + button1 = (); + } + var inputDisabled = (this.state.importing || this.state.error != null || this.state.imported) ? "disabled" : ""; return ( @@ -513,17 +557,19 @@ const ImportTransactionsModal = React.createClass({ ref="importform"> {progressBar} + {panel} - - + {button1} + {button2}