UnapprovedAccount: convert to tsx
This commit is contained in:
parent
527b5086a6
commit
ce23e48106
2 changed files with 63 additions and 77 deletions
|
@ -1,77 +0,0 @@
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import { approveUsers } from 'soapbox/actions/admin';
|
|
||||||
import snackbar from 'soapbox/actions/snackbar';
|
|
||||||
import IconButton from 'soapbox/components/icon_button';
|
|
||||||
import { makeGetAccount } from 'soapbox/selectors';
|
|
||||||
|
|
||||||
import { rejectUserModal } from '../../../actions/moderation';
|
|
||||||
|
|
||||||
const messages = defineMessages({
|
|
||||||
approved: { id: 'admin.awaiting_approval.approved_message', defaultMessage: '{acct} was approved!' },
|
|
||||||
rejected: { id: 'admin.awaiting_approval.rejected_message', defaultMessage: '{acct} was rejected.' },
|
|
||||||
});
|
|
||||||
|
|
||||||
const makeMapStateToProps = () => {
|
|
||||||
const getAccount = makeGetAccount();
|
|
||||||
|
|
||||||
const mapStateToProps = (state, { accountId }) => {
|
|
||||||
return {
|
|
||||||
account: getAccount(state, accountId),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
return mapStateToProps;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default @connect(makeMapStateToProps)
|
|
||||||
@injectIntl
|
|
||||||
class UnapprovedAccount extends ImmutablePureComponent {
|
|
||||||
|
|
||||||
static propTypes = {
|
|
||||||
intl: PropTypes.object.isRequired,
|
|
||||||
account: ImmutablePropTypes.record.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
handleApprove = () => {
|
|
||||||
const { dispatch, intl, account } = this.props;
|
|
||||||
dispatch(approveUsers([account.get('id')]))
|
|
||||||
.then(() => {
|
|
||||||
const message = intl.formatMessage(messages.approved, { acct: `@${account.get('acct')}` });
|
|
||||||
dispatch(snackbar.success(message));
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleReject = () => {
|
|
||||||
const { dispatch, intl, account } = this.props;
|
|
||||||
|
|
||||||
dispatch(rejectUserModal(intl, account.get('id'), () => {
|
|
||||||
const message = intl.formatMessage(messages.rejected, { acct: `@${account.get('acct')}` });
|
|
||||||
dispatch(snackbar.info(message));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { account } = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='unapproved-account'>
|
|
||||||
<div className='unapproved-account__bio'>
|
|
||||||
<div className='unapproved-account__nickname'>@{account.get('acct')}</div>
|
|
||||||
<blockquote className='md'>{account.getIn(['pleroma', 'admin', 'registration_reason'])}</blockquote>
|
|
||||||
</div>
|
|
||||||
<div className='unapproved-account__actions'>
|
|
||||||
<IconButton src={require('@tabler/icons/icons/check.svg')} onClick={this.handleApprove} />
|
|
||||||
<IconButton src={require('@tabler/icons/icons/x.svg')} onClick={this.handleReject} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
63
app/soapbox/features/admin/components/unapproved_account.tsx
Normal file
63
app/soapbox/features/admin/components/unapproved_account.tsx
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
|
import { approveUsers } from 'soapbox/actions/admin';
|
||||||
|
import snackbar from 'soapbox/actions/snackbar';
|
||||||
|
import IconButton from 'soapbox/components/icon_button';
|
||||||
|
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
|
||||||
|
import { makeGetAccount } from 'soapbox/selectors';
|
||||||
|
|
||||||
|
import { rejectUserModal } from '../../../actions/moderation';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
approved: { id: 'admin.awaiting_approval.approved_message', defaultMessage: '{acct} was approved!' },
|
||||||
|
rejected: { id: 'admin.awaiting_approval.rejected_message', defaultMessage: '{acct} was rejected.' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const getAccount = makeGetAccount();
|
||||||
|
|
||||||
|
interface IUnapprovedAccount {
|
||||||
|
accountId: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Displays an unapproved account for moderation purposes. */
|
||||||
|
const UnapprovedAccount: React.FC<IUnapprovedAccount> = ({ accountId }) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const account = useAppSelector(state => getAccount(state, accountId));
|
||||||
|
|
||||||
|
if (!account) return null;
|
||||||
|
|
||||||
|
const handleApprove = () => {
|
||||||
|
dispatch(approveUsers([account.id]))
|
||||||
|
.then(() => {
|
||||||
|
const message = intl.formatMessage(messages.approved, { acct: `@${account.acct}` });
|
||||||
|
dispatch(snackbar.success(message));
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReject = () => {
|
||||||
|
dispatch(rejectUserModal(intl, account.id, () => {
|
||||||
|
const message = intl.formatMessage(messages.rejected, { acct: `@${account.acct}` });
|
||||||
|
dispatch(snackbar.info(message));
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='unapproved-account'>
|
||||||
|
<div className='unapproved-account__bio'>
|
||||||
|
<div className='unapproved-account__nickname'>@{account.get('acct')}</div>
|
||||||
|
<blockquote className='md'>{account.pleroma.getIn(['admin', 'registration_reason'], '') as string}</blockquote>
|
||||||
|
</div>
|
||||||
|
<div className='unapproved-account__actions'>
|
||||||
|
<IconButton src={require('@tabler/icons/icons/check.svg')} onClick={handleApprove} />
|
||||||
|
<IconButton src={require('@tabler/icons/icons/x.svg')} onClick={handleReject} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UnapprovedAccount;
|
Loading…
Reference in a new issue