2020-08-17 21:07:16 +01:00
import React from 'react'
2020-08-17 21:59:29 +01:00
import PropTypes from 'prop-types'
2020-02-28 15:20:47 +00:00
import { defineMessages , injectIntl } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
import { List as ImmutableList } from 'immutable'
2020-05-01 06:50:27 +01:00
import { DEFAULT _REL } from '../../constants'
2020-02-28 15:20:47 +00:00
import PanelLayout from './panel_layout'
2020-02-29 15:42:47 +00:00
import Divider from '../divider'
2020-02-28 15:20:47 +00:00
import Icon from '../icon'
import Text from '../text'
2020-05-09 03:17:19 +01:00
import Dummy from '../dummy'
2020-07-28 21:11:51 +01:00
import ProfileInfoPanelPlaceholder from '../placeholder/profile_info_panel_placeholder'
2020-02-28 15:20:47 +00:00
class ProfileInfoPanel extends ImmutablePureComponent {
2020-02-24 21:56:07 +00:00
render ( ) {
2020-05-09 03:17:19 +01:00
const {
intl ,
account ,
noPanel
} = this . props
2020-02-28 15:20:47 +00:00
2020-07-28 21:11:51 +01:00
const Wrapper = noPanel ? Dummy : PanelLayout
2020-07-29 21:40:47 +01:00
if ( ! account && ! noPanel ) {
2020-07-28 21:11:51 +01:00
return (
< Wrapper title = { intl . formatMessage ( messages . title ) } >
< ProfileInfoPanelPlaceholder / >
< / W r a p p e r >
)
}
2020-03-24 04:39:12 +00:00
const fields = account . get ( 'fields' )
const content = { _ _html : account . get ( 'note_emojified' ) }
const memberSinceDate = intl . formatDate ( account . get ( 'created_at' ) , { month : 'long' , year : 'numeric' } )
2020-02-28 15:20:47 +00:00
const hasNote = ! ! content ? ( account . get ( 'note' ) . length > 0 && account . get ( 'note' ) !== '<p></p>' ) : false
2020-04-24 04:17:27 +01:00
const isPro = account . get ( 'is_pro' )
const isDonor = account . get ( 'is_donor' )
const isInvestor = account . get ( 'is_investor' )
const hasBadges = isPro || isDonor || isInvestor
2020-02-28 15:20:47 +00:00
2020-02-24 21:56:07 +00:00
return (
2020-05-09 03:17:19 +01:00
< Wrapper title = { intl . formatMessage ( messages . title ) } >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d ] . join ( ' ' ) } >
2020-03-24 04:39:12 +00:00
{
hasNote &&
2020-08-17 21:07:16 +01:00
< React . Fragment >
2020-03-24 04:39:12 +00:00
< div className = { _s . dangerousContent } dangerouslySetInnerHTML = { content } / >
2020-04-23 07:13:29 +01:00
< Divider isSmall / >
2020-08-17 21:07:16 +01:00
< / R e a c t . F r a g m e n t >
2020-03-24 04:39:12 +00:00
}
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . flexRow , _s . aiCenter ] . join ( ' ' ) } >
2020-08-18 21:43:06 +01:00
< Icon id = 'calendar' size = '12px' className = { _s . cSecondary } / >
2020-03-24 04:39:12 +00:00
< Text
size = 'small'
color = 'secondary'
className = { _s . ml5 }
>
{
intl . formatMessage ( messages . memberSince , {
date : memberSinceDate
} )
}
< / T e x t >
< / d i v >
2020-04-24 04:17:27 +01:00
{
hasBadges &&
2020-08-17 21:07:16 +01:00
< React . Fragment >
2020-04-24 04:17:27 +01:00
< Divider isSmall / >
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d , _s . flexRow , _s . aiCenter ] . join ( ' ' ) } >
2020-05-04 19:44:37 +01:00
{
isPro &&
< div className = { [ _s . mr5 , _s . radiusSmall , _s . bgPro , _s . py2 , _s . px5 ] . join ( ' ' ) } >
2020-05-14 07:03:22 +01:00
< Text weight = 'bold' size = 'small' className = { _s . colorBGPrimary } isBadge > PRO < / T e x t >
2020-05-04 19:44:37 +01:00
< / d i v >
}
{
isInvestor &&
< div className = { [ _s . mr5 , _s . radiusSmall , _s . bgInvestor , _s . py2 , _s . px5 ] . join ( ' ' ) } >
2020-05-14 07:03:22 +01:00
< Text weight = 'bold' size = 'small' className = { _s . colorBGPrimary } isBadge > INVESTOR < / T e x t >
2020-05-04 19:44:37 +01:00
< / d i v >
}
{
isDonor &&
< div className = { [ _s . mr5 , _s . radiusSmall , _s . bgDonor , _s . py2 , _s . px5 ] . join ( ' ' ) } >
2020-05-14 07:03:22 +01:00
< Text weight = 'bold' size = 'small' className = { _s . colorBGPrimary } isBadge > DONOR < / T e x t >
2020-05-04 19:44:37 +01:00
< / d i v >
}
2020-04-24 04:17:27 +01:00
< / d i v >
2020-08-17 21:07:16 +01:00
< / R e a c t . F r a g m e n t >
2020-04-24 04:17:27 +01:00
}
2020-03-24 04:39:12 +00:00
2020-06-07 18:47:22 +01:00
{
fields . size > 0 &&
2020-08-18 21:49:11 +01:00
< div className = { [ _s . d ] } >
2020-03-24 04:39:12 +00:00
{
fields . map ( ( pair , i ) => (
2020-08-17 21:07:16 +01:00
< React . Fragment >
2020-04-23 07:13:29 +01:00
< Divider isSmall / >
2020-08-18 21:49:11 +01:00
< dl className = { [ _s . d , _s . flexRow , _s . aiCenter ] . join ( ' ' ) } key = { ` profile-field- ${ i } ` } >
2020-02-29 15:42:47 +00:00
< dt
2020-08-06 05:55:23 +01:00
className = { [ _s . text , _s . dangerousContent , _s . pr5 ] . join ( ' ' ) }
2020-03-24 04:39:12 +00:00
dangerouslySetInnerHTML = { { _ _html : pair . get ( 'name_emojified' ) } }
title = { pair . get ( 'name' ) }
/ >
< dd
2020-04-24 04:17:27 +01:00
className = { [ _s . dangerousContent , _s . mlAuto ] . join ( ' ' ) }
2020-03-24 04:39:12 +00:00
title = { pair . get ( 'value_plain' ) }
dangerouslySetInnerHTML = { { _ _html : pair . get ( 'value_emojified' ) } }
2020-02-29 15:42:47 +00:00
/ >
< / d l >
2020-08-17 21:07:16 +01:00
< / R e a c t . F r a g m e n t >
2020-03-24 04:39:12 +00:00
) )
}
< / d i v >
2020-06-07 18:47:22 +01:00
}
2020-02-28 15:20:47 +00:00
2020-03-24 04:39:12 +00:00
< / d i v >
2020-05-09 03:17:19 +01:00
< / W r a p p e r >
2020-02-28 15:20:47 +00:00
)
}
2020-08-19 01:22:15 +01:00
}
const messages = defineMessages ( {
title : { id : 'about' , defaultMessage : 'About' } ,
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.' } ,
bot : { id : 'account.badges.bot' , defaultMessage : 'Bot' } ,
memberSince : { id : 'account.member_since' , defaultMessage : 'Member since {date}' } ,
} )
ProfileInfoPanel . propTypes = {
account : ImmutablePropTypes . map ,
noPanel : PropTypes . bool ,
intl : PropTypes . object . isRequired ,
}
export default injectIntl ( ProfileInfoPanel )