gab-social/app/javascript/gabsocial/components/panel/profile_info_panel.js

172 lines
6.6 KiB
JavaScript
Raw Normal View History

2020-02-29 15:42:47 +00:00
import { Fragment } from 'react'
2020-02-28 15:20:47 +00:00
import { defineMessages, injectIntl } from 'react-intl'
import { fetchSuggestions, dismissSuggestion } from '../../actions/suggestions'
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-02-24 21:56:07 +00:00
const messages = defineMessages({
2020-02-28 15:20:47 +00:00
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}' },
})
const mapStateToProps = (state, { account }) => {
2020-02-29 15:42:47 +00:00
const identityProofs = !!account ? state.getIn(['identity_proofs', account.get('id')], ImmutableList()) : ImmutableList()
2020-02-28 15:20:47 +00:00
return {
identityProofs,
domain: state.getIn(['meta', 'domain']),
2020-02-29 15:42:47 +00:00
}
}
2020-02-24 21:56:07 +00:00
2020-04-11 23:29:19 +01:00
const mapDispatchToProps = (dispatch) => ({
fetchSuggestions: () => dispatch(fetchSuggestions()),
dismissSuggestion: account => dispatch(dismissSuggestion(account.get('id'))),
})
2020-02-24 21:56:07 +00:00
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps, mapDispatchToProps)
2020-02-24 21:56:07 +00:00
@injectIntl
2020-02-28 15:20:47 +00:00
class ProfileInfoPanel extends ImmutablePureComponent {
2020-02-24 21:56:07 +00:00
static propTypes = {
2020-02-28 15:20:47 +00:00
identityProofs: ImmutablePropTypes.list,
2020-03-24 04:39:12 +00:00
account: ImmutablePropTypes.map,
2020-02-24 21:56:07 +00:00
intl: PropTypes.object.isRequired,
2020-02-28 15:20:47 +00:00
}
2020-02-24 21:56:07 +00:00
2020-02-28 15:20:47 +00:00
componentDidMount() {
this.props.fetchSuggestions()
2020-02-24 21:56:07 +00:00
}
render() {
2020-02-28 15:20:47 +00:00
const { intl, account, identityProofs } = this.props
2020-03-24 04:39:12 +00:00
if (!account) return null
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-02-28 15:20:47 +00:00
<PanelLayout title={intl.formatMessage(messages.title)}>
2020-03-24 04:39:12 +00:00
<div className={[_s.default].join(' ')}>
{
hasNote &&
<Fragment>
<div className={_s.dangerousContent} dangerouslySetInnerHTML={content} />
2020-04-23 07:13:29 +01:00
<Divider isSmall />
2020-03-24 04:39:12 +00:00
</Fragment>
}
<div className={[_s.default, _s.flexRow, _s.alignItemsCenter].join(' ')}>
2020-04-29 23:32:49 +01:00
<Icon id='calendar' size='12px' className={_s.fillSecondary} />
2020-03-24 04:39:12 +00:00
<Text
size='small'
color='secondary'
className={_s.ml5}
>
{
intl.formatMessage(messages.memberSince, {
date: memberSinceDate
})
}
</Text>
</div>
2020-04-24 04:17:27 +01:00
{
hasBadges &&
<Fragment>
<Divider isSmall />
<div className={[_s.default, _s.flexRow, _s.alignItemsCenter].join(' ')}>
2020-05-04 19:44:37 +01:00
{
isPro &&
<div className={[_s.mr5, _s.radiusSmall, _s.bgPro, _s.py2, _s.px5].join(' ')}>
<Text weight='bold' size='small' color='white' isBadge>PRO</Text>
</div>
}
{
isInvestor &&
<div className={[_s.mr5, _s.radiusSmall, _s.bgInvestor, _s.py2, _s.px5].join(' ')}>
<Text weight='bold' size='small' color='white' isBadge>INVESTOR</Text>
</div>
}
{
isDonor &&
<div className={[_s.mr5, _s.radiusSmall, _s.bgDonor, _s.py2, _s.px5].join(' ')}>
<Text weight='bold' size='small' color='white' isBadge>DONOR</Text>
</div>
}
2020-04-24 04:17:27 +01:00
</div>
</Fragment>
}
2020-03-24 04:39:12 +00:00
{(fields.size > 0 || identityProofs.size > 0) && (
<div className={[_s.default]}>
{identityProofs.map((proof, i) => (
<Fragment>
2020-04-23 07:13:29 +01:00
<Divider isSmall />
2020-03-24 04:39:12 +00:00
<dl className={[_s.default, _s.flexRow, _s.alignItemsCenter].join(' ')} key={`profile-identity-proof-${i}`}>
<dt
className={_s.dangerousContent}
dangerouslySetInnerHTML={{ __html: proof.get('provider') }}
/>
{ /* : todo : */}
<dd className='verified'>
2020-05-01 06:50:27 +01:00
<a href={proof.get('proof_url')} target='_blank' rel={DEFAULT_REL}>
2020-03-24 04:39:12 +00:00
<span title={intl.formatMessage(messages.linkVerifiedOn, { date: intl.formatDate(proof.get('updated_at'), dateFormatOptions) })}>
2020-04-23 07:13:29 +01:00
<Icon id='check' size='12px' className='verified__mark' />
2020-03-24 04:39:12 +00:00
</span>
</a>
2020-05-01 06:50:27 +01:00
<a href={proof.get('profile_url')} target='_blank' rel={DEFAULT_REL}>
2020-03-24 04:39:12 +00:00
<span
className={_s.dangerousContent}
dangerouslySetInnerHTML={{ __html: ' ' + proof.get('provider_username') }}
/>
</a>
</dd>
</dl>
</Fragment>
))}
2020-02-28 15:20:47 +00:00
2020-03-24 04:39:12 +00:00
{
fields.map((pair, i) => (
2020-02-29 15:42:47 +00:00
<Fragment>
2020-04-23 07:13:29 +01:00
<Divider isSmall />
2020-03-24 04:39:12 +00:00
<dl className={[_s.default, _s.flexRow, _s.alignItemsCenter].join(' ')} key={`profile-field-${i}`}>
2020-02-29 15:42:47 +00:00
<dt
2020-03-24 04:39:12 +00:00
className={[_s.text, _s.dangerousContent].join(' ')}
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
/>
</dl>
</Fragment>
2020-03-24 04:39:12 +00:00
))
}
2020-02-28 15:20:47 +00:00
2020-03-24 04:39:12 +00:00
</div>
)}
2020-02-28 15:20:47 +00:00
2020-03-24 04:39:12 +00:00
</div>
2020-02-24 21:56:07 +00:00
</PanelLayout>
2020-02-28 15:20:47 +00:00
)
}
}