2022-09-13 01:21:56 -07:00
|
|
|
import React, { useCallback } from 'react';
|
2022-04-28 14:43:43 -07:00
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
|
|
|
|
import { approveUsers } from 'soapbox/actions/admin';
|
2022-05-24 03:24:26 -07:00
|
|
|
import { rejectUserModal } from 'soapbox/actions/moderation';
|
2022-04-28 14:43:43 -07:00
|
|
|
import snackbar from 'soapbox/actions/snackbar';
|
2022-12-17 13:48:45 -08:00
|
|
|
import { Stack, HStack, Text, IconButton } from 'soapbox/components/ui';
|
2022-04-28 14:43:43 -07:00
|
|
|
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
|
|
|
|
import { makeGetAccount } from 'soapbox/selectors';
|
2022-12-20 07:47:46 -08:00
|
|
|
import toast from 'soapbox/toast';
|
2022-04-28 14:43:43 -07:00
|
|
|
|
|
|
|
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.' },
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IUnapprovedAccount {
|
|
|
|
accountId: string,
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Displays an unapproved account for moderation purposes. */
|
|
|
|
const UnapprovedAccount: React.FC<IUnapprovedAccount> = ({ accountId }) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
const dispatch = useAppDispatch();
|
2022-09-13 01:21:56 -07:00
|
|
|
const getAccount = useCallback(makeGetAccount(), []);
|
2022-04-28 14:43:43 -07:00
|
|
|
|
|
|
|
const account = useAppSelector(state => getAccount(state, accountId));
|
2022-05-15 06:11:59 -07:00
|
|
|
const adminAccount = useAppSelector(state => state.admin.users.get(accountId));
|
2022-04-28 14:43:43 -07:00
|
|
|
|
|
|
|
if (!account) return null;
|
|
|
|
|
|
|
|
const handleApprove = () => {
|
|
|
|
dispatch(approveUsers([account.id]))
|
|
|
|
.then(() => {
|
|
|
|
const message = intl.formatMessage(messages.approved, { acct: `@${account.acct}` });
|
2022-12-20 07:47:46 -08:00
|
|
|
toast.success(message);
|
2022-04-28 14:43:43 -07:00
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleReject = () => {
|
|
|
|
dispatch(rejectUserModal(intl, account.id, () => {
|
|
|
|
const message = intl.formatMessage(messages.rejected, { acct: `@${account.acct}` });
|
|
|
|
dispatch(snackbar.info(message));
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-12-17 13:48:45 -08:00
|
|
|
<HStack space={4} justifyContent='between'>
|
|
|
|
<Stack space={1}>
|
|
|
|
<Text weight='semibold'>
|
|
|
|
@{account.get('acct')}
|
|
|
|
</Text>
|
|
|
|
<Text tag='blockquote' size='sm'>
|
|
|
|
{adminAccount?.invite_request || ''}
|
|
|
|
</Text>
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
<HStack space={2} alignItems='center'>
|
|
|
|
<IconButton
|
|
|
|
src={require('@tabler/icons/check.svg')}
|
|
|
|
onClick={handleApprove}
|
|
|
|
theme='outlined'
|
|
|
|
iconClassName='p-1 text-gray-600 dark:text-gray-400'
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
src={require('@tabler/icons/x.svg')}
|
|
|
|
onClick={handleReject}
|
|
|
|
theme='outlined'
|
|
|
|
iconClassName='p-1 text-gray-600 dark:text-gray-400'
|
|
|
|
/>
|
|
|
|
</HStack>
|
|
|
|
</HStack>
|
2022-04-28 14:43:43 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default UnapprovedAccount;
|