Vulcan/packages/nova-base-components/lib/users/UsersProfileCheck.jsx

49 lines
1.9 KiB
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
2016-06-10 10:25:38 +09:00
import { FormattedMessage } from 'react-intl';
2016-04-17 10:29:52 +09:00
import { Modal } from 'react-bootstrap';
2016-12-20 09:27:16 +09:00
import SmartForm from "meteor/nova:forms";
2016-06-14 10:01:44 +09:00
import { withRouter } from 'react-router'
2016-06-23 15:00:58 +09:00
import Users from 'meteor/nova:users';
2016-12-12 11:34:28 +09:00
import { withCurrentUser, Utils, registerComponent } from 'meteor/nova:core';
2016-11-15 18:33:16 +01:00
const UsersProfileCheckModal = ({show, router, currentUser}, context) => {
2016-04-17 10:48:02 +09:00
// return fields that are required by the schema but haven't been filled out yet
2016-12-12 11:34:28 +09:00
const schema = Utils.stripTelescopeNamespace(Users.simpleSchema()._schema);
const requiredFields = _.filter(_.keys(schema), (fieldName) => {
2016-04-17 10:48:02 +09:00
var field = schema[fieldName];
2016-12-12 11:34:28 +09:00
return !!field.required && !Utils.getNestedProperty(currentUser, fieldName);
2016-04-17 10:48:02 +09:00
});
2016-04-17 10:29:52 +09:00
return (
<Modal bsSize='small' show={ show }>
<Modal.Header>
2016-06-10 10:25:38 +09:00
<Modal.Title><FormattedMessage id="users.complete_profile"/></Modal.Title>
2016-04-17 10:29:52 +09:00
</Modal.Header>
<Modal.Body>
2016-12-20 09:27:16 +09:00
<SmartForm
collection={ Users }
documentId={ currentUser._id }
2016-04-17 10:48:02 +09:00
fields={ requiredFields }
2016-04-17 10:29:52 +09:00
/>
</Modal.Body>
<Modal.Footer>
<FormattedMessage id="app.or"/> <a className="complete-profile-logout" onClick={ () => Meteor.logout(() => window.location.reload() /* something is broken here when giving the apollo client as a prop*/) }><FormattedMessage id="users.log_out"/></a>
2016-04-17 10:29:52 +09:00
</Modal.Footer>
</Modal>
)
};
2016-11-15 18:33:16 +01:00
const UsersProfileCheck = ({currentUser}, context) => {
// console.log('current user', currentUser);
// console.log('profile completed', !Users.hasCompletedProfile(currentUser));
2016-11-15 18:33:16 +01:00
return currentUser ? <UsersProfileCheckModal currentUser={currentUser} show={!Users.hasCompletedProfile(currentUser)}/> : null;
};
2016-04-17 10:29:52 +09:00
2016-11-15 18:33:16 +01:00
UsersProfileCheck.propsTypes = {
currentUser: React.PropTypes.object
};
UsersProfileCheck.displayName = "UsersProfileCheck";
registerComponent('UsersProfileCheck', UsersProfileCheck, withCurrentUser, withRouter);