2021-08-05 06:31:29 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2022-01-10 14:17:52 -08:00
|
|
|
import React from 'react';
|
2021-08-05 06:31:29 -07:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2022-01-10 14:17:52 -08:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2022-01-10 14:01:24 -08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { connect } from 'react-redux';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-02-14 12:00:41 -08:00
|
|
|
import { addToAliases } from 'soapbox/actions/aliases';
|
|
|
|
import Avatar from 'soapbox/components/avatar';
|
|
|
|
import DisplayName from 'soapbox/components/display_name';
|
|
|
|
import IconButton from 'soapbox/components/icon_button';
|
|
|
|
import { makeGetAccount } from 'soapbox/selectors';
|
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
2021-08-05 06:31:29 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
add: { id: 'aliases.account.add', defaultMessage: 'Create alias' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
2022-02-14 12:00:41 -08:00
|
|
|
const mapStateToProps = (state, { accountId, added, aliases }) => {
|
2021-08-23 15:51:32 -07:00
|
|
|
const me = state.get('me');
|
2022-02-14 12:00:41 -08:00
|
|
|
|
|
|
|
const instance = state.get('instance');
|
|
|
|
const features = getFeatures(instance);
|
2021-08-23 15:51:32 -07:00
|
|
|
|
2021-08-05 06:31:29 -07:00
|
|
|
const account = getAccount(state, accountId);
|
|
|
|
const apId = account.getIn(['pleroma', 'ap_id']);
|
2022-02-14 12:00:41 -08:00
|
|
|
const name = features.accountMoving ? account.get('acct') : apId;
|
2021-08-05 06:31:29 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
account,
|
|
|
|
apId,
|
2022-02-14 12:00:41 -08:00
|
|
|
added: typeof added === 'undefined' ? aliases.includes(name) : added,
|
2021-08-23 15:51:32 -07:00
|
|
|
me,
|
2021-08-05 06:31:29 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onAdd: (intl, apId) => dispatch(addToAliases(intl, apId)),
|
|
|
|
});
|
|
|
|
|
|
|
|
export default @connect(makeMapStateToProps, mapDispatchToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Account extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2022-03-23 10:14:42 -07:00
|
|
|
account: ImmutablePropTypes.record.isRequired,
|
2021-08-05 06:31:29 -07:00
|
|
|
apId: PropTypes.string.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onAdd: PropTypes.func.isRequired,
|
|
|
|
added: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
added: false,
|
|
|
|
};
|
|
|
|
|
2022-02-14 12:00:41 -08:00
|
|
|
handleOnAdd = () => this.props.onAdd(this.props.intl, this.props.account);
|
2021-08-05 06:31:29 -07:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { account, accountId, intl, added, me } = this.props;
|
|
|
|
|
|
|
|
let button;
|
|
|
|
|
|
|
|
if (!added && accountId !== me) {
|
|
|
|
button = (
|
|
|
|
<div className='account__relationship'>
|
2021-12-14 10:48:18 -08:00
|
|
|
<IconButton src={require('@tabler/icons/icons/plus.svg')} title={intl.formatMessage(messages.add)} onClick={this.handleOnAdd} />
|
2021-08-05 06:31:29 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='account'>
|
|
|
|
<div className='account__wrapper'>
|
|
|
|
<div className='account__display-name'>
|
|
|
|
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
|
|
|
|
<DisplayName account={account} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{button}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|