import React, { ChangeEventHandler, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { verifyUser, unverifyUser, suggestUsers, unsuggestUsers, setBadges as saveBadges, } from 'soapbox/actions/admin'; import { deactivateUserModal, deleteUserModal } from 'soapbox/actions/moderation'; import snackbar from 'soapbox/actions/snackbar'; import Account from 'soapbox/components/account'; import List, { ListItem } from 'soapbox/components/list'; import MissingIndicator from 'soapbox/components/missing-indicator'; import OutlineBox from 'soapbox/components/outline-box'; import { Button, Text, HStack, Modal, Stack, Toggle } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector, useFeatures, useOwnAccount } from 'soapbox/hooks'; import { makeGetAccount } from 'soapbox/selectors'; import { isLocal } from 'soapbox/utils/accounts'; import { getBadges } from 'soapbox/utils/badges'; import BadgeInput from './badge-input'; import StaffRolePicker from './staff-role-picker'; const getAccount = makeGetAccount(); const messages = defineMessages({ userVerified: { id: 'admin.users.user_verified_message', defaultMessage: '@{acct} was verified' }, userUnverified: { id: 'admin.users.user_unverified_message', defaultMessage: '@{acct} was unverified' }, setDonorSuccess: { id: 'admin.users.set_donor_message', defaultMessage: '@{acct} was set as a donor' }, removeDonorSuccess: { id: 'admin.users.remove_donor_message', defaultMessage: '@{acct} was removed as a donor' }, userSuggested: { id: 'admin.users.user_suggested_message', defaultMessage: '@{acct} was suggested' }, userUnsuggested: { id: 'admin.users.user_unsuggested_message', defaultMessage: '@{acct} was unsuggested' }, badgesSaved: { id: 'admin.users.badges_saved_message', defaultMessage: 'Custom badges updated.' }, }); interface IAccountModerationModal { /** Action to close the modal. */ onClose: (type: string) => void, /** ID of the account to moderate. */ accountId: string, } /** Moderator actions against accounts. */ const AccountModerationModal: React.FC = ({ onClose, accountId }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const ownAccount = useOwnAccount(); const features = useFeatures(); const account = useAppSelector(state => getAccount(state, accountId)); const accountBadges = account ? getBadges(account) : []; const [badges, setBadges] = useState(accountBadges); const handleClose = () => onClose('ACCOUNT_MODERATION'); if (!account || !ownAccount) { return ( ); } const handleAdminFE = () => { window.open(`/pleroma/admin/#/users/${account.id}/`, '_blank'); }; const handleVerifiedChange: ChangeEventHandler = (e) => { const { checked } = e.target; const message = checked ? messages.userVerified : messages.userUnverified; const action = checked ? verifyUser : unverifyUser; dispatch(action(account.id)) .then(() => dispatch(snackbar.success(intl.formatMessage(message, { acct: account.acct })))) .catch(() => {}); }; const handleSuggestedChange: ChangeEventHandler = (e) => { const { checked } = e.target; const message = checked ? messages.userSuggested : messages.userUnsuggested; const action = checked ? suggestUsers : unsuggestUsers; dispatch(action([account.id])) .then(() => dispatch(snackbar.success(intl.formatMessage(message, { acct: account.acct })))) .catch(() => {}); }; const handleDeactivate = () => { dispatch(deactivateUserModal(intl, account.id)); }; const handleDelete = () => { dispatch(deleteUserModal(intl, account.id)); }; const handleSaveBadges = () => { dispatch(saveBadges(account.id, accountBadges, badges)) .then(() => dispatch(snackbar.success(intl.formatMessage(messages.badgesSaved)))) .catch(() => {}); }; return ( } onClose={handleClose} > {(ownAccount.admin && isLocal(account)) && ( }>
)} }> {features.suggestionsV2 && ( }> )} }>
} onClick={handleDeactivate} /> } onClick={handleDelete} /> {features.adminFE && ( )}
); }; export default AccountModerationModal;