2022-11-06 02:28:13 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2022-11-06 02:28:13 +09:00
|
|
|
import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2022-11-06 02:28:13 +09:00
|
|
|
import { openModal } from 'mastodon/actions/modal';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { disabledAccountId, movedToAccountId, domain } from 'mastodon/initial_state';
|
2022-11-06 02:28:13 +09:00
|
|
|
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(),
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-05-23 17:52:27 +09:00
|
|
|
class DisabledAccountBanner extends PureComponent {
|
2022-11-06 02:28:13 +09:00
|
|
|
|
|
|
|
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;
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2022-11-06 02:28:13 +09:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { disabledAcct, movedToAcct } = this.props;
|
|
|
|
|
|
|
|
const disabledAccountLink = (
|
|
|
|
<Link to={`/@${disabledAcct}`}>
|
|
|
|
{disabledAcct}@{domain}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='sign-in-banner'>
|
|
|
|
<p>
|
|
|
|
{movedToAcct ? (
|
|
|
|
<FormattedMessage
|
|
|
|
id='moved_to_account_banner.text'
|
|
|
|
defaultMessage='Your account {disabledAccount} is currently disabled because you moved to {movedToAccount}.'
|
|
|
|
values={{
|
|
|
|
disabledAccount: disabledAccountLink,
|
2022-11-06 05:11:35 +09:00
|
|
|
movedToAccount: <Link to={`/@${movedToAcct}`}>{movedToAcct.includes('@') ? movedToAcct : `${movedToAcct}@${domain}`}</Link>,
|
2022-11-06 02:28:13 +09:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<FormattedMessage
|
|
|
|
id='disabled_account_banner.text'
|
|
|
|
defaultMessage='Your account {disabledAccount} is currently disabled.'
|
|
|
|
values={{
|
|
|
|
disabledAccount: disabledAccountLink,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</p>
|
|
|
|
<a href='/auth/edit' className='button button--block'>
|
|
|
|
<FormattedMessage id='disabled_account_banner.account_settings' defaultMessage='Account settings' />
|
|
|
|
</a>
|
|
|
|
<button type='button' className='button button--block button-tertiary' onClick={this.handleLogOutClick}>
|
|
|
|
<FormattedMessage id='confirmations.logout.confirm' defaultMessage='Log out' />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-19 00:51:37 +09:00
|
|
|
}
|
2023-03-24 11:17:53 +09:00
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(DisabledAccountBanner));
|