withList -> withMulti; add fallback prop for Avatar component

This commit is contained in:
SachaG 2018-09-12 10:31:36 +09:00
parent 493380889b
commit bafe350407
2 changed files with 8 additions and 3 deletions

View file

@ -5,8 +5,13 @@ import Users from 'meteor/vulcan:users';
import { Link } from 'react-router'; import { Link } from 'react-router';
import classNames from 'classnames'; import classNames from 'classnames';
const Avatar = ({className, user, link}) => { const Avatar = ({className, user, link, fallback}) => {
const avatarClassNames = classNames('avatar', className);
if (!user) {
return <div className={avatarClassNames}>{fallback}</div>
}
const avatarUrl = user.avatarUrl || Users.avatar.getUrl(user); const avatarUrl = user.avatarUrl || Users.avatar.getUrl(user);
const img = <img alt={Users.getDisplayName(user)} className="avatar-image" src={avatarUrl} title={user.username}/>; const img = <img alt={Users.getDisplayName(user)} className="avatar-image" src={avatarUrl} title={user.username}/>;
@ -15,7 +20,7 @@ const Avatar = ({className, user, link}) => {
const avatar = avatarUrl ? img : initials; const avatar = avatarUrl ? img : initials;
return ( return (
<div className={classNames('avatar', className)}> <div className={avatarClassNames}>
{link ? {link ?
<Link to={Users.getProfileUrl(user)}> <Link to={Users.getProfileUrl(user)}>
<span>{avatar}</span> <span>{avatar}</span>

View file

@ -72,7 +72,7 @@ class Datatable extends PureComponent {
...this.props.options ...this.props.options
} }
const DatatableWithList = withList(options)(Components.DatatableContents); const DatatableWithList = withMulti(options)(Components.DatatableContents);
const canInsert = collection.options && collection.options.mutations && collection.options.mutations.new && collection.options.mutations.new.check(this.props.currentUser); const canInsert = collection.options && collection.options.mutations && collection.options.mutations.new && collection.options.mutations.new.check(this.props.currentUser);