import React, { useCallback, useState } from 'react'; import { useIntl, FormattedMessage, defineMessages } from 'react-intl'; import { Link } from 'react-router-dom'; import { closeReports } from 'soapbox/actions/admin'; import { deactivateUserModal, deleteUserModal } from 'soapbox/actions/moderation'; import HoverRefWrapper from 'soapbox/components/hover-ref-wrapper'; import { Accordion, Avatar, Button, Stack, HStack, Text } from 'soapbox/components/ui'; import DropdownMenu from 'soapbox/containers/dropdown-menu-container'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { makeGetReport } from 'soapbox/selectors'; import toast from 'soapbox/toast'; import ReportStatus from './report-status'; import type { List as ImmutableList } from 'immutable'; import type { Account, AdminReport, Status } from 'soapbox/types/entities'; const messages = defineMessages({ reportClosed: { id: 'admin.reports.report_closed_message', defaultMessage: 'Report on @{name} was closed' }, deactivateUser: { id: 'admin.users.actions.deactivate_user', defaultMessage: 'Deactivate @{name}' }, deleteUser: { id: 'admin.users.actions.delete_user', defaultMessage: 'Delete @{name}' }, }); interface IReport { id: string; } const Report: React.FC = ({ id }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const getReport = useCallback(makeGetReport(), []); const report = useAppSelector((state) => getReport(state, id) as AdminReport | undefined); const [accordionExpanded, setAccordionExpanded] = useState(false); if (!report) return null; const account = report.account as Account; const targetAccount = report.target_account as Account; const makeMenu = () => { return [{ text: intl.formatMessage(messages.deactivateUser, { name: targetAccount.username }), action: handleDeactivateUser, icon: require('@tabler/icons/hourglass-empty.svg'), }, { text: intl.formatMessage(messages.deleteUser, { name: targetAccount.username }), action: handleDeleteUser, icon: require('@tabler/icons/trash.svg'), destructive: true, }]; }; const handleCloseReport = () => { dispatch(closeReports([report.id])).then(() => { const message = intl.formatMessage(messages.reportClosed, { name: targetAccount.username as string }); toast.success(message); }).catch(() => {}); }; const handleDeactivateUser = () => { const accountId = targetAccount.id; dispatch(deactivateUserModal(intl, accountId, () => handleCloseReport())); }; const handleDeleteUser = () => { const accountId = targetAccount.id as string; dispatch(deleteUserModal(intl, accountId, () => handleCloseReport())); }; const handleAccordionToggle = (setting: boolean) => { setAccordionExpanded(setting); }; const menu = makeMenu(); const statuses = report.statuses as ImmutableList; const statusCount = statuses.count(); const acct = targetAccount.acct as string; const reporterAcct = account.acct as string; return ( @{acct} ) }} /> {statusCount > 0 && ( {statuses.map(status => ( ))} )} {(report.comment || '').length > 0 && ( )} @{reporterAcct} ); }; export default Report;