2020-12-31 15:20:46 -08:00
import React from 'react' ;
2020-12-31 15:54:08 -08:00
import { connect } from 'react-redux' ;
2020-12-31 20:56:17 -08:00
import { Link } from 'react-router-dom' ;
2020-12-31 15:20:46 -08:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2020-12-31 15:54:08 -08:00
import { injectIntl , FormattedMessage , defineMessages } from 'react-intl' ;
2020-12-31 15:20:46 -08:00
import Avatar from 'soapbox/components/avatar' ;
2020-12-31 16:24:52 -08:00
import Button from 'soapbox/components/button' ;
2020-12-31 15:54:08 -08:00
import DropdownMenu from 'soapbox/containers/dropdown_menu_container' ;
2020-12-31 18:47:15 -08:00
import Accordion from 'soapbox/features/ui/components/accordion' ;
2020-12-31 20:20:31 -08:00
import ReportStatus from './report_status' ;
2020-12-31 16:59:10 -08:00
import { closeReports , deactivateUsers , deleteUsers } from 'soapbox/actions/admin' ;
2020-12-31 15:54:08 -08:00
import snackbar from 'soapbox/actions/snackbar' ;
2020-12-31 16:51:51 -08:00
import { openModal } from 'soapbox/actions/modal' ;
2020-12-31 15:20:46 -08:00
2020-12-31 15:54:08 -08:00
const messages = defineMessages ( {
2020-12-31 16:24:52 -08:00
reportClosed : { id : 'admin.reports.report_closed_message' , defaultMessage : 'Report on {acct} was closed' } ,
2020-12-31 16:59:10 -08:00
deactivateUser : { id : 'admin.reports.actions.deactivate_user' , defaultMessage : 'Deactivate {acct}' } ,
2020-12-31 16:51:51 -08:00
deactivateUserPrompt : { id : 'confirmations.admin.deactivate_user.message' , defaultMessage : 'You are about to deactivate {acct}. Deactivating a user is a reversible action.' } ,
deactivateUserConfirm : { id : 'confirmations.admin.deactivate_user.confirm' , defaultMessage : 'Deactivate {acct}' } ,
2020-12-31 16:59:10 -08:00
userDeactivated : { id : 'admin.reports.user_deactivated_message' , defaultMessage : '{acct} was deactivated' } ,
deleteUser : { id : 'admin.reports.actions.delete_user' , defaultMessage : 'Delete {acct}' } ,
deleteUserPrompt : { id : 'confirmations.admin.delete_user.message' , defaultMessage : 'You are about to delete {acct}. THIS IS A DESTRUCTIVE ACTION THAT CANNOT BE UNDONE.' } ,
deleteUserConfirm : { id : 'confirmations.admin.delete_user.confirm' , defaultMessage : 'Delete {acct}' } ,
userDeleted : { id : 'admin.reports.user_deleted_message' , defaultMessage : '{acct} was deleted' } ,
2020-12-31 15:54:08 -08:00
} ) ;
export default @ connect ( )
@ injectIntl
class Report extends ImmutablePureComponent {
2020-12-31 15:20:46 -08:00
static propTypes = {
report : ImmutablePropTypes . map . isRequired ,
} ;
2020-12-31 18:47:15 -08:00
state = {
accordionExpanded : false ,
} ;
2020-12-31 15:54:08 -08:00
makeMenu = ( ) => {
const { intl , report } = this . props ;
return [ {
text : intl . formatMessage ( messages . deactivateUser , { acct : ` @ ${ report . getIn ( [ 'account' , 'acct' ] ) } ` } ) ,
action : this . handleDeactivateUser ,
2020-12-31 16:59:10 -08:00
} , {
text : intl . formatMessage ( messages . deleteUser , { acct : ` @ ${ report . getIn ( [ 'account' , 'acct' ] ) } ` } ) ,
action : this . handleDeleteUser ,
2020-12-31 15:54:08 -08:00
} ] ;
}
2020-12-31 16:24:52 -08:00
handleCloseReport = ( ) => {
const { intl , dispatch , report } = this . props ;
const nickname = report . getIn ( [ 'account' , 'acct' ] ) ;
dispatch ( closeReports ( [ report . get ( 'id' ) ] ) ) . then ( ( ) => {
const message = intl . formatMessage ( messages . reportClosed , { acct : ` @ ${ nickname } ` } ) ;
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
}
2020-12-31 15:54:08 -08:00
handleDeactivateUser = ( ) => {
const { intl , dispatch , report } = this . props ;
const nickname = report . getIn ( [ 'account' , 'acct' ] ) ;
2020-12-31 16:51:51 -08:00
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . deactivateUserPrompt , { acct : ` @ ${ nickname } ` } ) ,
confirm : intl . formatMessage ( messages . deactivateUserConfirm , { acct : ` @ ${ nickname } ` } ) ,
onConfirm : ( ) => {
dispatch ( deactivateUsers ( [ nickname ] ) ) . then ( ( ) => {
const message = intl . formatMessage ( messages . userDeactivated , { acct : ` @ ${ nickname } ` } ) ;
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
this . handleCloseReport ( ) ;
} ,
} ) ) ;
2020-12-31 15:54:08 -08:00
}
2020-12-31 16:59:10 -08:00
handleDeleteUser = ( ) => {
const { intl , dispatch , report } = this . props ;
const nickname = report . getIn ( [ 'account' , 'acct' ] ) ;
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . deleteUserPrompt , { acct : ` @ ${ nickname } ` } ) ,
confirm : intl . formatMessage ( messages . deleteUserConfirm , { acct : ` @ ${ nickname } ` } ) ,
onConfirm : ( ) => {
dispatch ( deleteUsers ( [ nickname ] ) ) . then ( ( ) => {
const message = intl . formatMessage ( messages . userDeleted , { acct : ` @ ${ nickname } ` } ) ;
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
this . handleCloseReport ( ) ;
} ,
} ) ) ;
}
2020-12-31 18:47:15 -08:00
handleAccordionToggle = setting => {
this . setState ( { accordionExpanded : setting } ) ;
}
2020-12-31 15:20:46 -08:00
render ( ) {
const { report } = this . props ;
2020-12-31 18:47:15 -08:00
const { accordionExpanded } = this . state ;
2020-12-31 15:54:08 -08:00
const menu = this . makeMenu ( ) ;
2020-12-31 18:50:22 -08:00
const statuses = report . get ( 'statuses' ) ;
const statusCount = statuses . count ( ) ;
2020-12-31 20:56:17 -08:00
const acct = report . getIn ( [ 'account' , 'acct' ] ) ;
const reporterAcct = report . getIn ( [ 'actor' , 'acct' ] ) ;
2020-12-31 15:20:46 -08:00
return (
< div className = 'admin-report' key = { report . get ( 'id' ) } >
2020-12-31 15:54:08 -08:00
< div className = 'admin-report__avatar' >
2020-12-31 20:56:17 -08:00
< Link to = { ` /@ ${ acct } ` } title = { acct } >
< Avatar account = { report . get ( 'account' ) } size = { 32 } / >
< / L i n k >
2020-12-31 15:54:08 -08:00
< / d i v >
2020-12-31 15:20:46 -08:00
< div className = 'admin-report__content' >
< h4 className = 'admin-report__title' >
< FormattedMessage
id = 'admin.reports.report_title'
defaultMessage = 'Report on {acct}'
2020-12-31 20:56:17 -08:00
values = { { acct : < Link to = { ` /@ ${ acct } ` } title = { acct } > @ { acct } < / L i n k > } }
2020-12-31 15:20:46 -08:00
/ >
< / h 4 >
2020-12-31 18:47:15 -08:00
< div className = 'admin-report__statuses' >
2020-12-31 18:50:22 -08:00
{ statusCount > 0 && (
< Accordion
headline = { ` Reported posts ( ${ statusCount } ) ` }
expanded = { accordionExpanded }
onToggle = { this . handleAccordionToggle }
>
2020-12-31 21:16:50 -08:00
{ statuses . map ( status => < ReportStatus report = { report } status = { status } key = { status . get ( 'id' ) } / > ) }
2020-12-31 18:50:22 -08:00
< / A c c o r d i o n >
) }
2020-12-31 18:47:15 -08:00
< / d i v >
< div className = 'admin-report__quote' >
2020-12-31 20:46:21 -08:00
{ report . get ( 'content' , '' ) . length > 0 &&
< blockquote className = 'md' dangerouslySetInnerHTML = { { _ _html : report . get ( 'content' ) } } / >
}
2020-12-31 20:56:17 -08:00
< span className = 'byline' > & mdash ; < Link to = { ` /@ ${ reporterAcct } ` } title = { reporterAcct } > @ { reporterAcct } < / L i n k > < / s p a n >
2020-12-31 15:20:46 -08:00
< / d i v >
< / d i v >
2020-12-31 15:54:08 -08:00
< div className = 'admin-report__actions' >
2020-12-31 16:24:52 -08:00
< Button className = 'button-alternative' size = { 30 } onClick = { this . handleCloseReport } >
< FormattedMessage id = 'admin.reports.actions.close' defaultMessage = 'Close' / >
< / B u t t o n >
2020-12-31 15:54:08 -08:00
< DropdownMenu items = { menu } icon = 'ellipsis-v' size = { 24 } direction = 'right' / >
< / d i v >
2020-12-31 15:20:46 -08:00
< / d i v >
) ;
}
}