_ = require 'underscore'
React = require "react"
{Actions} = require 'nylas-exports'
{RetinaImg} = require 'nylas-component-kit'
class SidebarFullContactDetails extends React.Component
@displayName: "SidebarFullContactDetails"
@propTypes:
contact: React.PropTypes.object
fullContact: React.PropTypes.object
render: =>
{@_profilePhoto()}
{@_name()}
{@_email()}
{@_title()}
{@_company()}
{@_socialProfiles()}
{@_noInfo()}
_socialProfiles: =>
profiles = @_profiles()
return profiles.map (profile) =>
_profiles: =>
profiles = @props.fullContact.socialProfiles ? []
profiles = _.filter profiles, (p) => @_supportedProfileTypes[p.typeId]
_supportedProfileTypes:
twitter: true
linkedin: true
facebook: true
_showSocialProfiles: =>
@_profiles().length > 0
_username: (profile) =>
if (profile.username ? "").length > 0
if profile.typeId is "twitter"
return "@#{profile.username}"
else
return profile.username
else
return profile.typeName
_noInfo: =>
if not @_showSocialProfiles() and not @_showSubheader()
No additional information available.
else return ""
_twitterBio: (profile) =>
return "" unless profile.typeId is "twitter"
return "" unless profile.bio?.length > 0
# http://stackoverflow.com/a/13398311/793472
twitterRegex = /(^|[^@\w])@(\w{1,15})\b/g
replace = '$1@$2'
bio = profile.bio.replace(twitterRegex, replace)
_showSubheader: =>
@_title().length > 0 or @_company().length > 0
_name: =>
(@props.fullContact.contactInfo?.fullName) ? @props.contact?.name ? ""
_email: =>
email = @props.contact.email ? ""
if @_name().toLowerCase().trim() isnt email.toLowerCase().trim()
return email
else return ""
_title: =>
org = @_primaryOrg()
return "" unless org?
if org.current and org.title?
return org.title
else if not org.current and org.title?
return "Former #{org.title}"
else return ""
_company: =>
location = @props.fullContact.demographics?.locationGeneral ? ""
name = @_primaryOrg()?.name ? ""
if name.length > 0 and location.length > 0
return "#{name} (#{location})"
else if name.length > 0
return name
else if location.length > 0
return "(#{location})"
else return ""
_primaryOrg: =>
orgs = @props.fullContact.organizations ? []
org = _.findWhere orgs, isPrimary: true
if not org? then org = orgs[0]
return org
_profilePhoto: =>
photos = @props.fullContact.photos ? []
photo = _.findWhere photo, isPrimary: true
if not photo? then photo = _.findWhere photo, typeId: "linkedin"
if not photo? then photo = photos[0]
if photo? and photo.url?
return
else return ""
module.exports = SidebarFullContactDetails