From ce23e48106f7c0262bbca2a8a796a278098dc352 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 28 Apr 2022 16:43:43 -0500 Subject: [PATCH] UnapprovedAccount: convert to tsx --- .../admin/components/unapproved_account.js | 77 ------------------- .../admin/components/unapproved_account.tsx | 63 +++++++++++++++ 2 files changed, 63 insertions(+), 77 deletions(-) delete mode 100644 app/soapbox/features/admin/components/unapproved_account.js create mode 100644 app/soapbox/features/admin/components/unapproved_account.tsx diff --git a/app/soapbox/features/admin/components/unapproved_account.js b/app/soapbox/features/admin/components/unapproved_account.js deleted file mode 100644 index 80ca4821d..000000000 --- a/app/soapbox/features/admin/components/unapproved_account.js +++ /dev/null @@ -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 ( -
-
-
@{account.get('acct')}
-
{account.getIn(['pleroma', 'admin', 'registration_reason'])}
-
-
- - -
-
- ); - } - -} diff --git a/app/soapbox/features/admin/components/unapproved_account.tsx b/app/soapbox/features/admin/components/unapproved_account.tsx new file mode 100644 index 000000000..f000bb173 --- /dev/null +++ b/app/soapbox/features/admin/components/unapproved_account.tsx @@ -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 = ({ 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 ( +
+
+
@{account.get('acct')}
+
{account.pleroma.getIn(['admin', 'registration_reason'], '') as string}
+
+
+ + +
+
+ ); +}; + +export default UnapprovedAccount;