mirror of
https://github.com/vale981/Vulcan
synced 2025-03-08 19:11:38 -05:00
small fixes on user mutations
This commit is contained in:
parent
cab93c1128
commit
0f6aeb3670
5 changed files with 50 additions and 12 deletions
|
@ -68,7 +68,7 @@ Telescope.registerComponent("CanDo", require('./permissions/CanDo
|
||||||
|
|
||||||
Telescope.registerComponent("UsersSingle", require('./users/UsersSingle.jsx'));
|
Telescope.registerComponent("UsersSingle", require('./users/UsersSingle.jsx'));
|
||||||
Telescope.registerComponent("UsersAccount", require('./users/UsersAccount.jsx'));
|
Telescope.registerComponent("UsersAccount", require('./users/UsersAccount.jsx'));
|
||||||
Telescope.registerComponent("UsersEdit", require('./users/UsersEdit.jsx'));
|
Telescope.registerComponent("UsersEditForm", require('./users/UsersEditForm.jsx'));
|
||||||
Telescope.registerComponent("UsersProfile", require('./users/UsersProfile.jsx'));
|
Telescope.registerComponent("UsersProfile", require('./users/UsersProfile.jsx'));
|
||||||
Telescope.registerComponent("UsersProfileCheck", require('./users/UsersProfileCheck.jsx'));
|
Telescope.registerComponent("UsersProfileCheck", require('./users/UsersProfileCheck.jsx'));
|
||||||
Telescope.registerComponent("UsersAvatar", require('./users/UsersAvatar.jsx'));
|
Telescope.registerComponent("UsersAvatar", require('./users/UsersAvatar.jsx'));
|
||||||
|
|
|
@ -7,7 +7,7 @@ const UsersAccount = (props, context) => {
|
||||||
return (
|
return (
|
||||||
<Telescope.components.CanDo action="users.edit.own" displayNoPermissionMessage={true}>
|
<Telescope.components.CanDo action="users.edit.own" displayNoPermissionMessage={true}>
|
||||||
<Telescope.components.UsersSingleContainer
|
<Telescope.components.UsersSingleContainer
|
||||||
component={Telescope.components.UsersEdit}
|
component={Telescope.components.UsersEditForm}
|
||||||
{...terms}
|
{...terms}
|
||||||
/>
|
/>
|
||||||
</Telescope.components.CanDo>
|
</Telescope.components.CanDo>
|
||||||
|
|
|
@ -8,7 +8,7 @@ import Users from 'meteor/nova:users';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const UsersEdit = (props, context) => {
|
const UsersEditForm = (props, context) => {
|
||||||
|
|
||||||
const user = props.document;
|
const user = props.document;
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ const UsersEdit = (props, context) => {
|
||||||
<NovaForm
|
<NovaForm
|
||||||
collection={Users}
|
collection={Users}
|
||||||
document={user}
|
document={user}
|
||||||
methodName="users.edit"
|
mutationName="usersEdit"
|
||||||
|
resultQuery={Users.graphQLQueries.single}
|
||||||
successCallback={(user)=>{
|
successCallback={(user)=>{
|
||||||
props.flash(context.intl.formatMessage({id: "users.edit_success"}, {name: Users.getDisplayName(user)}), 'success')
|
props.flash(context.intl.formatMessage({id: "users.edit_success"}, {name: Users.getDisplayName(user)}), 'success')
|
||||||
}}
|
}}
|
||||||
|
@ -34,19 +35,19 @@ const UsersEdit = (props, context) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
UsersEdit.propTypes = {
|
UsersEditForm.propTypes = {
|
||||||
document: React.PropTypes.object,
|
document: React.PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
UsersEdit.contextTypes = {
|
UsersEditForm.contextTypes = {
|
||||||
currentUser: React.PropTypes.object,
|
currentUser: React.PropTypes.object,
|
||||||
intl: intlShape
|
intl: intlShape
|
||||||
};
|
};
|
||||||
|
|
||||||
UsersEdit.displayName = "UsersEdit";
|
UsersEditForm.displayName = "UsersEditForm";
|
||||||
|
|
||||||
const mapStateToProps = state => ({ messages: state.messages, });
|
const mapStateToProps = state => ({ messages: state.messages, });
|
||||||
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
|
const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch);
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(UsersEdit);
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(UsersEditForm);
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(UsersEdit);
|
export default connect(mapStateToProps, mapDispatchToProps)(UsersEditForm);
|
|
@ -336,3 +336,40 @@ Telescope.utils.findIndex = (array, predicate) => {
|
||||||
});
|
});
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adapted from http://stackoverflow.com/a/22072374/649299
|
||||||
|
Telescope.utils.unflatten = function( array, idProperty, parentIdProperty, parent, tree ){
|
||||||
|
|
||||||
|
tree = typeof tree !== "undefined" ? tree : [];
|
||||||
|
|
||||||
|
let children = [];
|
||||||
|
|
||||||
|
if (typeof parent === "undefined") {
|
||||||
|
// if there is no parent, we're at the root level
|
||||||
|
// so we return all root nodes (i.e. nodes with no parent)
|
||||||
|
children = _.filter( array, node => !node[parentIdProperty]);
|
||||||
|
} else {
|
||||||
|
// if there *is* a parent, we return all its child nodes
|
||||||
|
// (i.e. nodes whose parentId is equal to the parent's id.)
|
||||||
|
children = _.filter( array, node => node[parentIdProperty] === parent[idProperty]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we found children, we keep on iterating
|
||||||
|
if (!!children.length) {
|
||||||
|
|
||||||
|
if (typeof parent === "undefined") {
|
||||||
|
// if we're at the root, then the tree consist of all root nodes
|
||||||
|
tree = children;
|
||||||
|
} else {
|
||||||
|
// else, we add the children to the parent as the "childrenResults" property
|
||||||
|
parent.childrenResults = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we call the function on each child
|
||||||
|
children.forEach(child => {
|
||||||
|
Telescope.utils.unflatten(array, idProperty, parentIdProperty, child);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree;
|
||||||
|
}
|
|
@ -36,8 +36,8 @@ Users.mutations = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// GraphQL mutations
|
// GraphQL mutations
|
||||||
Telescope.graphQL.addMutation('usersNew(document: usersInput) : Post');
|
Telescope.graphQL.addMutation('usersNew(document: usersInput) : User');
|
||||||
Telescope.graphQL.addMutation('usersEdit(documentId: String, set: usersInput, unset: usersUnset) : Post');
|
Telescope.graphQL.addMutation('usersEdit(documentId: String, set: usersInput, unset: usersUnset) : User');
|
||||||
Telescope.graphQL.addMutation('usersRemove(documentId: String) : Post');
|
Telescope.graphQL.addMutation('usersRemove(documentId: String) : User');
|
||||||
|
|
||||||
export default Users.mutations;
|
export default Users.mutations;
|
Loading…
Add table
Reference in a new issue