Compare commits

...

1 Commits

Author SHA1 Message Date
GotPPay
768afa475b show error dialog if adding chaild organization fails 2018-05-10 18:25:22 +02:00

View File

@@ -11,6 +11,8 @@ import {
import moment from 'moment'; import moment from 'moment';
import Delete from 'material-ui/svg-icons/action/delete'; import Delete from 'material-ui/svg-icons/action/delete';
import IconButton from 'material-ui/IconButton'; import IconButton from 'material-ui/IconButton';
import FlatButton from 'material-ui/FlatButton';
import Dialog from 'material-ui/Dialog';
import GoogleAddressComponent from './GoogleAddressComponent'; import GoogleAddressComponent from './GoogleAddressComponent';
import ContactComponent from './ContactComponent'; import ContactComponent from './ContactComponent';
@@ -463,7 +465,9 @@ class Organization extends React.Component {
"useruuid": "", "useruuid": "",
"name": "", "name": "",
} }
} },
showErrorMessage : false,
errorMessage : ''
} }
componentDidMount() { componentDidMount() {
@@ -597,11 +601,20 @@ class Organization extends React.Component {
self.setState(Object.assign(self.state, { organization: res.data })); self.setState(Object.assign(self.state, { organization: res.data }));
}) })
.catch(err => { .catch(err => {
if (err.response.status === 422) { let errorMessage = '';
location.href = '/#/app/table/organizations'; switch(err.response.status){
} else { case 403:
console.error(err); errorMessage = 'Not authorized to add child organization';
break;
case 422:
location.href = '/#/app/table/organizations';
break;
default:
errorMessage = 'Error adding child organization';
console.error(err);
} }
this.setState(Object.assign(this.state, { showErrorMessage:true, errorMessage:errorMessage }));
}); });
} }
@@ -613,10 +626,32 @@ class Organization extends React.Component {
this.getOrganization(organization.id); this.getOrganization(organization.id);
} }
handleDialogDismiss(){
this.setState(Object.assign(this.state, { showErrorMessage:false }));
}
render() { render() {
const actions = [
<FlatButton
label="Dismiss"
primary={true}
onClick={this.handleDialogDismiss.bind(this)}
/>,
];
return ( return (
<div className="container-fluid no-breadcrumbs page-dashboard"> <div className="container-fluid no-breadcrumbs page-dashboard">
<QueueAnim type="bottom" className="ui-animate"> <QueueAnim type="bottom" className="ui-animate">
<Dialog
title="Error"
actions={actions}
modal={false}
open={this.state.showErrorMessage}
onRequestClose={this.handleDialogDismiss.bind(this)}
>
{this.state.message}
</Dialog>
<Main organization={this.state.organization} <Main organization={this.state.organization}
onAddressAdded={this.handleAddressAdded} onAddressRemoved={this.handleAddressRemoved} onAddressAdded={this.handleAddressAdded} onAddressRemoved={this.handleAddressRemoved}
onContactAdded={this.handleContactAdded} onContactRemoved={this.handleContactRemoved} onContactAdded={this.handleContactAdded} onContactRemoved={this.handleContactRemoved}