1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-10-30 07:40:05 -04:00

Display modal on failed security deletion

This commit is contained in:
Aaron Lindsay 2017-02-05 20:48:40 -05:00
parent cec769b6b8
commit 5478ba3fd0
2 changed files with 43 additions and 7 deletions

View File

@ -268,6 +268,26 @@ const AddEditSecurityModal = React.createClass({
} }
}); });
const DeletionFailedModal = React.createClass({
render: function() {
return (
<Modal show={this.props.show} onHide={this.props.onClose}>
<Modal.Header closeButton>
<Modal.Title>Cannot Delete Security</Modal.Title>
</Modal.Header>
<Modal.Body>
We are unable to delete this security because it is in use by {this.props.securityAccounts.length} account(s). Please change those accounts to use other securities and try again.
</Modal.Body>
<Modal.Footer>
<ButtonGroup className="pull-right">
<Button onClick={this.props.onClose} bsStyle="warning">Close</Button>
</ButtonGroup>
</Modal.Footer>
</Modal>
);
}
});
const SecurityList = React.createClass({ const SecurityList = React.createClass({
render: function() { render: function() {
var children = []; var children = [];
@ -301,7 +321,8 @@ module.exports = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
creatingNewSecurity: false, creatingNewSecurity: false,
editingSecurity: false editingSecurity: false,
deletionFailedModal: false
}; };
}, },
handleNewSecurity: function() { handleNewSecurity: function() {
@ -310,6 +331,12 @@ module.exports = React.createClass({
handleEditSecurity: function() { handleEditSecurity: function() {
this.setState({editingSecurity: true}); this.setState({editingSecurity: true});
}, },
handleDeleteSecurity: function() {
if (this.props.selectedSecurityAccounts.length == 0)
this.props.onDeleteSecurity(this.props.securities[this.props.selectedSecurity]);
else
this.setState({deletionFailedModal: true});
},
handleCreationCancel: function() { handleCreationCancel: function() {
this.setState({creatingNewSecurity: false}); this.setState({creatingNewSecurity: false});
}, },
@ -324,8 +351,11 @@ module.exports = React.createClass({
this.setState({editingSecurity: false}); this.setState({editingSecurity: false});
this.props.onUpdateSecurity(security); this.props.onUpdateSecurity(security);
}, },
closeDeletionFailedModal: function() {
this.setState({deletionFailedModal: false});
},
render: function() { render: function() {
var editDisabled = this.props.selectedSecurity == -1; var noSecuritySelected = this.props.selectedSecurity == -1;
var selectedSecurity = null; var selectedSecurity = null;
if (this.props.securities.hasOwnProperty(this.props.selectedSecurity)) if (this.props.securities.hasOwnProperty(this.props.selectedSecurity))
@ -347,14 +377,20 @@ module.exports = React.createClass({
onSubmit={this.handleEditingSubmit} onSubmit={this.handleEditingSubmit}
onSearchTemplates={this.props.onSearchTemplates} onSearchTemplates={this.props.onSearchTemplates}
securityTemplates={this.props.securityTemplates} /> securityTemplates={this.props.securityTemplates} />
<DeletionFailedModal
show={this.state.deletionFailedModal}
deletingSecurity={selectedSecurity}
onClose={this.closeDeletionFailedModal}
securityAccounts={this.props.selectedSecurityAccounts} />
<SecurityList <SecurityList
selectedSecurity={this.props.selectedSecurity} selectedSecurity={this.props.selectedSecurity}
securities={this.props.securities} securities={this.props.securities}
onSelectSecurity={this.props.onSelectSecurity} /> onSelectSecurity={this.props.onSelectSecurity} />
</Col><Col xs={9} className="fullheight securities-column"> </Col><Col xs={9} className="fullheight securities-column">
<ButtonToolbar className="pull-right"><ButtonGroup> <ButtonToolbar className="pull-right"><ButtonGroup>
<Button onClick={this.handleEditSecurity} bsStyle="primary" disabled={editDisabled}><Glyphicon glyph='cog'/> Edit Security</Button>
<Button onClick={this.handleNewSecurity} bsStyle="success"><Glyphicon glyph='plus-sign'/> New Security</Button> <Button onClick={this.handleNewSecurity} bsStyle="success"><Glyphicon glyph='plus-sign'/> New Security</Button>
<Button onClick={this.handleEditSecurity} bsStyle="primary" disabled={noSecuritySelected}><Glyphicon glyph='cog'/> Edit Security</Button>
<Button onClick={this.handleDeleteSecurity} bsStyle="danger" disabled={noSecuritySelected}><Glyphicon glyph='trash'/> Delete Security</Button>
</ButtonGroup></ButtonToolbar> </ButtonGroup></ButtonToolbar>
</Col> </Col>
</Row></Grid> </Row></Grid>

View File

@ -6,10 +6,10 @@ var SecuritiesTab = require('../components/SecuritiesTab');
function mapStateToProps(state) { function mapStateToProps(state) {
var selectedSecurityAccounts = []; var selectedSecurityAccounts = [];
for (var accountId in state.accounts) { for (var accountId in state.accounts.map) {
if (state.accounts.hasOwnProperty(accountId) if (state.accounts.map.hasOwnProperty(accountId)
&& state.accounts[accountId].SecurityId == state.selectedSecurity) && state.accounts.map[accountId].SecurityId == state.selectedSecurity)
selectedSecurityAccounts.push(state.accounts[accountId]); selectedSecurityAccounts.push(state.accounts.map[accountId]);
} }
return { return {
securities: state.securities, securities: state.securities,