2022-09-13 01:21:56 -07:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2022-04-28 11:35:52 -07:00
|
|
|
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 snackbar from 'soapbox/actions/snackbar';
|
|
|
|
import Avatar from 'soapbox/components/avatar';
|
2022-04-28 19:55:02 -07:00
|
|
|
import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper';
|
2022-04-28 19:36:28 -07:00
|
|
|
import { Button, HStack } from 'soapbox/components/ui';
|
2022-04-28 11:35:52 -07:00
|
|
|
import DropdownMenu from 'soapbox/containers/dropdown_menu_container';
|
|
|
|
import Accordion from 'soapbox/features/ui/components/accordion';
|
2022-09-13 01:21:56 -07:00
|
|
|
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
|
|
|
import { makeGetReport } from 'soapbox/selectors';
|
2022-04-28 11:35:52 -07:00
|
|
|
|
|
|
|
import ReportStatus from './report_status';
|
|
|
|
|
2022-05-15 06:11:59 -07:00
|
|
|
import type { List as ImmutableList } from 'immutable';
|
|
|
|
import type { Account, AdminReport, Status } from 'soapbox/types/entities';
|
2022-04-28 11:35:52 -07:00
|
|
|
|
|
|
|
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 {
|
2022-09-13 01:21:56 -07:00
|
|
|
id: string;
|
2022-04-28 11:35:52 -07:00
|
|
|
}
|
|
|
|
|
2022-09-13 01:21:56 -07:00
|
|
|
const Report: React.FC<IReport> = ({ id }) => {
|
2022-04-28 11:35:52 -07:00
|
|
|
const intl = useIntl();
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
2022-09-13 01:21:56 -07:00
|
|
|
const getReport = useCallback(makeGetReport(), []);
|
|
|
|
|
|
|
|
const report = useAppSelector((state) => getReport(state, id) as AdminReport | undefined);
|
|
|
|
|
2022-04-28 11:35:52 -07:00
|
|
|
const [accordionExpanded, setAccordionExpanded] = useState(false);
|
|
|
|
|
2022-09-13 01:21:56 -07:00
|
|
|
if (!report) return null;
|
|
|
|
|
2022-05-15 06:11:59 -07:00
|
|
|
const account = report.account as Account;
|
|
|
|
const targetAccount = report.target_account as Account;
|
|
|
|
|
2022-04-28 11:35:52 -07:00
|
|
|
const makeMenu = () => {
|
|
|
|
return [{
|
2022-05-15 06:11:59 -07:00
|
|
|
text: intl.formatMessage(messages.deactivateUser, { name: targetAccount.username as string }),
|
2022-04-28 11:35:52 -07:00
|
|
|
action: handleDeactivateUser,
|
2022-07-09 09:20:02 -07:00
|
|
|
icon: require('@tabler/icons/user-off.svg'),
|
2022-04-28 11:35:52 -07:00
|
|
|
}, {
|
2022-05-15 06:11:59 -07:00
|
|
|
text: intl.formatMessage(messages.deleteUser, { name: targetAccount.username as string }),
|
2022-04-28 11:35:52 -07:00
|
|
|
action: handleDeleteUser,
|
2022-07-09 09:20:02 -07:00
|
|
|
icon: require('@tabler/icons/user-minus.svg'),
|
2022-04-28 11:35:52 -07:00
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCloseReport = () => {
|
2022-05-15 06:11:59 -07:00
|
|
|
dispatch(closeReports([report.id])).then(() => {
|
|
|
|
const message = intl.formatMessage(messages.reportClosed, { name: targetAccount.username as string });
|
2022-04-28 11:35:52 -07:00
|
|
|
dispatch(snackbar.success(message));
|
|
|
|
}).catch(() => {});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDeactivateUser = () => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const accountId = targetAccount.id;
|
2022-04-28 11:35:52 -07:00
|
|
|
dispatch(deactivateUserModal(intl, accountId, () => handleCloseReport()));
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleDeleteUser = () => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const accountId = targetAccount.id as string;
|
2022-04-28 11:35:52 -07:00
|
|
|
dispatch(deleteUserModal(intl, accountId, () => handleCloseReport()));
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleAccordionToggle = (setting: boolean) => {
|
|
|
|
setAccordionExpanded(setting);
|
|
|
|
};
|
|
|
|
|
|
|
|
const menu = makeMenu();
|
2022-05-15 06:11:59 -07:00
|
|
|
const statuses = report.statuses as ImmutableList<Status>;
|
2022-04-28 11:35:52 -07:00
|
|
|
const statusCount = statuses.count();
|
2022-05-15 06:11:59 -07:00
|
|
|
const acct = targetAccount.acct as string;
|
|
|
|
const reporterAcct = account.acct as string;
|
2022-04-28 11:35:52 -07:00
|
|
|
|
|
|
|
return (
|
2022-05-15 06:11:59 -07:00
|
|
|
<div className='admin-report' key={report.id}>
|
2022-04-28 11:35:52 -07:00
|
|
|
<div className='admin-report__avatar'>
|
2022-05-15 06:11:59 -07:00
|
|
|
<HoverRefWrapper accountId={targetAccount.id as string} inline>
|
2022-04-28 19:55:02 -07:00
|
|
|
<Link to={`/@${acct}`} title={acct}>
|
2022-05-15 06:11:59 -07:00
|
|
|
<Avatar account={targetAccount} size={32} />
|
2022-04-28 19:55:02 -07:00
|
|
|
</Link>
|
|
|
|
</HoverRefWrapper>
|
2022-04-28 11:35:52 -07:00
|
|
|
</div>
|
|
|
|
<div className='admin-report__content'>
|
|
|
|
<h4 className='admin-report__title'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='admin.reports.report_title'
|
|
|
|
defaultMessage='Report on {acct}'
|
2022-04-28 19:55:02 -07:00
|
|
|
values={{ acct: (
|
2022-05-15 06:11:59 -07:00
|
|
|
<HoverRefWrapper accountId={account.id as string} inline>
|
2022-04-28 19:55:02 -07:00
|
|
|
<Link to={`/@${acct}`} title={acct}>@{acct}</Link>
|
|
|
|
</HoverRefWrapper>
|
|
|
|
) }}
|
2022-04-28 11:35:52 -07:00
|
|
|
/>
|
|
|
|
</h4>
|
|
|
|
<div className='admin-report__statuses'>
|
|
|
|
{statusCount > 0 && (
|
|
|
|
<Accordion
|
|
|
|
headline={`Reported posts (${statusCount})`}
|
|
|
|
expanded={accordionExpanded}
|
|
|
|
onToggle={handleAccordionToggle}
|
|
|
|
>
|
|
|
|
{statuses.map(status => <ReportStatus report={report} status={status} key={status.id} />)}
|
|
|
|
</Accordion>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className='admin-report__quote'>
|
2022-05-15 06:11:59 -07:00
|
|
|
{(report.comment || '').length > 0 && (
|
|
|
|
<blockquote className='md' dangerouslySetInnerHTML={{ __html: report.comment }} />
|
2022-04-28 19:36:28 -07:00
|
|
|
)}
|
2022-04-28 19:55:02 -07:00
|
|
|
<span className='byline'>
|
|
|
|
—
|
2022-05-15 06:11:59 -07:00
|
|
|
<HoverRefWrapper accountId={account.id as string} inline>
|
2022-04-28 19:55:02 -07:00
|
|
|
<Link to={`/@${reporterAcct}`} title={reporterAcct}>@{reporterAcct}</Link>
|
|
|
|
</HoverRefWrapper>
|
|
|
|
</span>
|
2022-04-28 11:35:52 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-28 19:36:28 -07:00
|
|
|
<HStack space={2} alignItems='start'>
|
2022-04-28 11:35:52 -07:00
|
|
|
<Button onClick={handleCloseReport}>
|
|
|
|
<FormattedMessage id='admin.reports.actions.close' defaultMessage='Close' />
|
|
|
|
</Button>
|
|
|
|
|
2022-07-09 09:20:02 -07:00
|
|
|
<DropdownMenu items={menu} src={require('@tabler/icons/dots-vertical.svg')} />
|
2022-04-28 19:36:28 -07:00
|
|
|
</HStack>
|
2022-04-28 11:35:52 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Report;
|