2016-12-06 18:06:29 +01:00
import Telescope , { registerComponent } from 'meteor/nova:lib' ;
2016-04-15 11:09:19 +02:00
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-04-15 11:09:19 +02:00
import NovaForm 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-11-30 16:58:28 +09:00
import { withCurrentUser } from 'meteor/nova:core' ;
2016-04-15 11:09:19 +02:00
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-11-10 22:18:51 +01:00
const schema = Telescope . utils . stripTelescopeNamespace ( Users . simpleSchema ( ) . _schema ) ;
2016-10-14 08:47:18 +02:00
const requiredFields = _ . filter ( _ . keys ( schema ) , ( fieldName ) => {
2016-04-17 10:48:02 +09:00
var field = schema [ fieldName ] ;
2016-10-14 08:47:18 +02:00
return ! ! field . required && ! Telescope . 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 >
< NovaForm
2016-10-05 08:37:48 +02:00
collection = { Users }
2016-04-17 10:29:52 +09:00
document = { currentUser }
2016-04-17 10:48:02 +09:00
fields = { requiredFields }
2016-04-17 10:29:52 +09:00
/ >
< / Modal.Body >
< Modal.Footer >
2016-11-17 21:54:03 +01:00
< 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-04-15 11:09:19 +02:00
} ;
2016-11-15 18:33:16 +01:00
const UsersProfileCheck = ( { currentUser } , context ) => {
2016-11-16 16:26:53 +01:00
// 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-10-14 08:47:18 +02:00
} ;
2016-04-17 10:29:52 +09:00
2016-11-15 18:33:16 +01:00
UsersProfileCheck . propsTypes = {
2016-10-14 08:47:18 +02:00
currentUser : React . PropTypes . object
} ;
2016-04-16 18:02:21 +02:00
2016-05-22 16:42:24 +09:00
UsersProfileCheck . displayName = "UsersProfileCheck" ;
2016-12-06 18:06:29 +01:00
registerComponent ( 'UsersProfileCheck' , UsersProfileCheck , withCurrentUser , withRouter ) ;