Skip to content

Commit

Permalink
show create group errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stropitek committed Sep 26, 2017
1 parent 44f507f commit 9f44a47
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion conf/devConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
username: 'admin',
password: 'admin',
// Already administrator from global configuration
superAdministrators: ['admin@a.com'],
superAdministrators: ['admin@a.com', 'a@a.com'],
autoCreateDatabase: true,
allowedOrigins: ['http://localhost:8080'],
};
11 changes: 9 additions & 2 deletions src/client/actions/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ export function createGroup(groupName, type) {
const groupUrl = `db/${dbManager.currentDb}/group/${groupName}?type=${type}`;
return {
type: CREATE_GROUP,
payload: apiFetchJSON(groupUrl, {method: 'PUT'})
.then(() => apiFetchJSON(groupUrl))
payload: doCreateGroup(groupUrl)
};
}

async function doCreateGroup(groupUrl) {
const res = await apiFetchJSON(groupUrl, {method: 'PUT'});
if (res.error) {
return res;
}
return apiFetchJSON(groupUrl);
}


export const REMOVE_GROUP = 'REMOVE_GROUP';
export function removeGroup(groupName) {
Expand Down
13 changes: 10 additions & 3 deletions src/client/components/GroupCreator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';

class GroupCreator extends Component {
constructor(props) {
Expand All @@ -9,7 +10,7 @@ class GroupCreator extends Component {
}

render() {
const {createGroup} = this.props;
const {createGroup, error} = this.props;
return (
<div className="card">
<div className="header">
Expand Down Expand Up @@ -43,7 +44,7 @@ class GroupCreator extends Component {
value="Create LDAP group"
/>
</form>
{/*<EnterTextField onSubmit={createGroup} />*/}
{error ? <div style={{marginTop: 8}} className="alert alert-danger">{error}</div> : null }
</div>
</div>
);
Expand All @@ -55,4 +56,10 @@ GroupCreator.propTypes = {
createGroup: PropTypes.func.isRequired
};

export default GroupCreator;
const mapStateToProps = (state) => {
return {
error: state.db.errors.createGroup
};
};

export default connect(mapStateToProps)(GroupCreator);
3 changes: 1 addition & 2 deletions src/client/components/GroupEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ class GroupEditor extends PureComponent {
</div>
</div>
<Ephemere>
{group.error ? <div className="alert alert-danger">{group.error}</div> : null }
{group.success ? <div className="alert alert-success">{group.success}</div> : null }
</Ephemere>

{group.error ? <div className="alert alert-danger">{group.error}</div> : null }
</div>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/client/reducers/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
const initialState = {
dbList: [],
userRights: [],
userGroups: []
userGroups: [],
errors: {}
};

const dbReducer = (state = initialState, action) => {
Expand All @@ -25,6 +26,12 @@ const dbReducer = (state = initialState, action) => {
case SET_USER_GROUPS:
return Object.assign({}, state, {userGroups: action.payload.sort(sortByName)});
case `${CREATE_GROUP}_FULFILLED`: {
if (action.payload.error) {
const errors = Object.assign({}, state.errors, {
createGroup: action.payload.error
});
return Object.assign({}, state, {errors});
}
const newGroupList = state.userGroups.slice();
newGroupList.unshift(action.payload);
return Object.assign({}, state, {userGroups: newGroupList});
Expand Down

0 comments on commit 9f44a47

Please sign in to comment.