2020-03-27 13:59:38 -07:00
'use strict' ;
import React from 'react' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import PropTypes from 'prop-types' ;
import { connect } from 'react-redux' ;
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import Icon from 'gabsocial/components/icon' ;
import VerificationBadge from 'gabsocial/components/verification_badge' ;
import Badge from 'gabsocial/components/badge' ;
import ProBadge from 'gabsocial/components/pro_badge' ;
import DonorBadge from 'gabsocial/components/donor_badge' ;
import InvestorBadge from 'gabsocial/components/investor_badge' ;
import { List as ImmutableList } from 'immutable' ;
2020-03-28 11:07:36 -07:00
import { acctFull } from 'gabsocial/utils/accounts' ;
2020-03-27 13:59:38 -07:00
const messages = defineMessages ( {
linkVerifiedOn : { id : 'account.link_verified_on' , defaultMessage : 'Ownership of this link was checked on {date}' } ,
account _locked : { id : 'account.locked_info' , defaultMessage : 'This account privacy status is set to locked. The owner manually reviews who can follow them.' } ,
} ) ;
const dateFormatOptions = {
month : 'short' ,
day : 'numeric' ,
year : 'numeric' ,
hour12 : false ,
hour : '2-digit' ,
minute : '2-digit' ,
} ;
class ProfileInfoPanel extends ImmutablePureComponent {
static propTypes = {
account : ImmutablePropTypes . map ,
identity _proofs : ImmutablePropTypes . list ,
intl : PropTypes . object . isRequired ,
username : PropTypes . string ,
} ;
render ( ) {
const { account , intl , identity _proofs , username } = this . props ;
if ( ! account ) {
return (
< div className = 'profile-info-panel' >
< div className = 'profile-info-panel__content' >
< div className = 'profile-info-panel-content__name' >
< h1 >
2020-04-14 11:44:40 -07:00
< span / >
2020-03-27 13:59:38 -07:00
< small > @ { username } < / s m a l l >
< / h 1 >
< / d i v >
< / d i v >
< / d i v >
) ;
}
const lockedIcon = account . get ( 'locked' ) ? ( < Icon id = 'lock' title = { intl . formatMessage ( messages . account _locked ) } / > ) : '' ;
const badge = account . get ( 'bot' ) ? ( < div className = 'account-role bot' > < FormattedMessage id = 'account.badges.bot' defaultMessage = 'Bot' / > < / d i v > ) : n u l l ;
const content = { _ _html : account . get ( 'note_emojified' ) } ;
const fields = account . get ( 'fields' ) ;
const displayNameHtml = { _ _html : account . get ( 'display_name_html' ) } ;
const memberSinceDate = intl . formatDate ( account . get ( 'created_at' ) , { month : 'long' , year : 'numeric' } ) ;
return (
< div className = 'profile-info-panel' >
< div className = 'profile-info-panel__content' >
< div className = 'profile-info-panel-content__name' >
< h1 >
< span dangerouslySetInnerHTML = { displayNameHtml } / >
2020-04-14 11:44:40 -07:00
{ account . get ( 'is_verified' ) && < VerificationBadge / > }
{ badge }
2020-03-28 11:07:36 -07:00
< small > @ { acctFull ( account ) } { lockedIcon } < / s m a l l >
2020-03-27 13:59:38 -07:00
< / h 1 >
< / d i v >
< div className = 'profile-info-panel-content__badges' >
2020-04-14 11:44:40 -07:00
{ account . get ( 'is_admin' ) && < Badge slug = 'admin' title = 'Admin' / > }
{ account . get ( 'is_moderator' ) && < Badge slug = 'moderator' title = 'Moderator' / > }
2020-03-27 13:59:38 -07:00
{ account . get ( 'is_pro' ) && < ProBadge / > }
{ account . get ( 'is_donor' ) && < DonorBadge / > }
{ account . get ( 'is_investor' ) && < InvestorBadge / > }
{ account . get ( 'acct' ) . includes ( '@' ) || < div className = 'profile-info-panel-content__badges__join-date' >
2020-04-14 11:44:40 -07:00
< Icon id = 'calendar' / >
< FormattedMessage
id = 'account.member_since' defaultMessage = 'Member since {date}' values = { {
date : memberSinceDate ,
} }
/ >
2020-03-27 13:59:38 -07:00
< / d i v > }
< / d i v >
{
( account . get ( 'note' ) . length > 0 && account . get ( 'note' ) !== '<p></p>' ) &&
< div className = 'profile-info-panel-content__bio' dangerouslySetInnerHTML = { content } / >
}
{ ( fields . size > 0 || identity _proofs . size > 0 ) && (
< div className = 'profile-info-panel-content__fields' >
{ identity _proofs . map ( ( proof , i ) => (
< dl className = 'test' key = { i } >
< dt dangerouslySetInnerHTML = { { _ _html : proof . get ( 'provider' ) } } / >
< dd className = 'verified' >
< a href = { proof . get ( 'proof_url' ) } target = '_blank' rel = 'noopener' >
< span title = { intl . formatMessage ( messages . linkVerifiedOn , { date : intl . formatDate ( proof . get ( 'updated_at' ) , dateFormatOptions ) } ) } >
< Icon id = 'check' className = 'verified__mark' / >
< / s p a n >
< / a >
< a href = { proof . get ( 'profile_url' ) } target = '_blank' rel = 'noopener' >
< span dangerouslySetInnerHTML = { { _ _html : ' ' + proof . get ( 'provider_username' ) } } / >
< / a >
< / d d >
< / d l >
) ) }
{ fields . map ( ( pair , i ) => (
< dl className = 'profile-info-panel-content__fields__item' key = { i } >
< dt dangerouslySetInnerHTML = { { _ _html : pair . get ( 'name_emojified' ) } } title = { pair . get ( 'name' ) } / >
< dd className = { pair . get ( 'verified_at' ) && 'verified' } title = { pair . get ( 'value_plain' ) } >
{ pair . get ( 'verified_at' ) && < span title = { intl . formatMessage ( messages . linkVerifiedOn , { date : intl . formatDate ( pair . get ( 'verified_at' ) , dateFormatOptions ) } ) } > < Icon id = 'check' className = 'verified__mark' / > < /span>} <span dangerouslySetInnerHTML={{ __html: pair.get('value_emojified') }} / >
< / d d >
< / d l >
) ) }
< / d i v >
) }
< / d i v >
< / d i v >
) ;
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}
const mapStateToProps = ( state , { account } ) => {
const identity _proofs = account ? state . getIn ( [ 'identity_proofs' , account . get ( 'id' ) ] , ImmutableList ( ) ) : ImmutableList ( ) ;
return {
identity _proofs ,
domain : state . getIn ( [ 'meta' , 'domain' ] ) ,
} ;
} ;
export default injectIntl (
connect ( mapStateToProps , null , null , {
forwardRef : true ,
}
2020-04-14 11:44:40 -07:00
) ( ProfileInfoPanel ) ) ;