2016-12-08 09:42:50 +01:00
|
|
|
import { Components, registerComponent } from 'meteor/nova:lib';
|
2016-03-18 10:50:40 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-30 12:05:59 +09:00
|
|
|
import { FormattedMessage, intlShape } from 'react-intl';
|
2016-12-20 09:27:16 +09:00
|
|
|
import SmartForm from "meteor/nova:forms";
|
2016-06-23 15:00:58 +09:00
|
|
|
import Users from 'meteor/nova:users';
|
2016-12-12 09:54:16 +09:00
|
|
|
import { ShowIf, withCurrentUser, withDocument, withMessages } from 'meteor/nova:core';
|
2016-12-08 11:03:20 +09:00
|
|
|
import gql from 'graphql-tag';
|
2016-10-31 17:13:14 +01:00
|
|
|
|
2016-11-09 11:55:28 +09:00
|
|
|
const UsersEditForm = (props, context) => {
|
2016-12-01 16:12:39 +01:00
|
|
|
return (
|
|
|
|
<ShowIf
|
|
|
|
check={Users.options.mutations.edit.check}
|
2016-12-22 10:47:44 +09:00
|
|
|
document={{_id: props.userId || props.document && props.document._id}}
|
2016-12-01 16:12:39 +01:00
|
|
|
failureComponent={<FormattedMessage id="app.noPermission"/>}
|
|
|
|
>
|
|
|
|
<div className="page users-edit-form">
|
|
|
|
<h2 className="page-title users-edit-form-title"><FormattedMessage id="users.edit_account"/></h2>
|
2016-12-20 09:27:16 +09:00
|
|
|
<SmartForm
|
2016-12-01 16:12:39 +01:00
|
|
|
collection={Users}
|
2016-12-22 10:47:44 +09:00
|
|
|
documentId={props.userId || props.document && props.document._id}
|
2016-12-01 16:12:39 +01:00
|
|
|
queryToUpdate="usersSingleQuery"
|
2016-12-08 10:23:12 +01:00
|
|
|
successCallback={user => {
|
2016-12-01 16:12:39 +01:00
|
|
|
props.flash(context.intl.formatMessage({id: "users.edit_success"}, {name: Users.getDisplayName(user)}), 'success')
|
|
|
|
}}
|
2016-12-08 11:03:20 +09:00
|
|
|
showRemove={true}
|
2016-12-01 16:12:39 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</ShowIf>
|
|
|
|
);
|
2016-05-25 08:52:04 +02:00
|
|
|
};
|
2016-03-31 13:24:19 -06:00
|
|
|
|
2016-12-08 11:03:20 +09:00
|
|
|
|
2016-11-09 11:55:28 +09:00
|
|
|
UsersEditForm.propTypes = {
|
2016-10-28 13:56:07 +02:00
|
|
|
document: React.PropTypes.object,
|
2016-05-25 08:52:04 +02:00
|
|
|
};
|
2016-02-23 11:34:40 +09:00
|
|
|
|
2016-11-09 11:55:28 +09:00
|
|
|
UsersEditForm.contextTypes = {
|
2016-06-30 12:05:59 +09:00
|
|
|
intl: intlShape
|
2016-06-14 17:03:35 +09:00
|
|
|
};
|
|
|
|
|
2016-11-09 11:55:28 +09:00
|
|
|
UsersEditForm.displayName = "UsersEditForm";
|
2016-05-22 16:42:24 +09:00
|
|
|
|
2016-12-08 11:03:20 +09:00
|
|
|
UsersEditForm.fragment = gql`
|
|
|
|
fragment UsersEditFormFragment on User {
|
|
|
|
_id
|
|
|
|
__slug
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
collection: Users,
|
2016-12-27 11:44:35 +01:00
|
|
|
queryName: 'usersEditPermissionCheckQuery',
|
2016-12-08 11:03:20 +09:00
|
|
|
fragment: UsersEditForm.fragment,
|
|
|
|
};
|
|
|
|
|
2016-12-27 11:44:35 +01:00
|
|
|
registerComponent('UsersEditForm', UsersEditForm, withCurrentUser, withDocument(options), withMessages);
|