import { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Link } from 'react-router-dom'; import { FormattedMessage, defineMessages, injectIntl } from 'react-intl'; import { disabledAccountId, movedToAccountId, domain } from 'mastodon/initial_state'; import { openModal } from 'mastodon/actions/modal'; import { logOut } from 'mastodon/utils/log_out'; const messages = defineMessages({ logoutMessage: { id: 'confirmations.logout.message', defaultMessage: 'Are you sure you want to log out?' }, logoutConfirm: { id: 'confirmations.logout.confirm', defaultMessage: 'Log out' }, }); const mapStateToProps = (state) => ({ disabledAcct: state.getIn(['accounts', disabledAccountId, 'acct']), movedToAcct: movedToAccountId ? state.getIn(['accounts', movedToAccountId, 'acct']) : undefined, }); const mapDispatchToProps = (dispatch, { intl }) => ({ onLogout () { dispatch(openModal('CONFIRM', { message: intl.formatMessage(messages.logoutMessage), confirm: intl.formatMessage(messages.logoutConfirm), closeWhenConfirm: false, onConfirm: () => logOut(), })); }, }); class DisabledAccountBanner extends PureComponent { static propTypes = { disabledAcct: PropTypes.string.isRequired, movedToAcct: PropTypes.string, onLogout: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; handleLogOutClick = e => { e.preventDefault(); e.stopPropagation(); this.props.onLogout(); return false; }; render () { const { disabledAcct, movedToAcct } = this.props; const disabledAccountLink = ( {disabledAcct}@{domain} ); return (
); } } export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(DisabledAccountBanner));