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 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 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 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 15:20:46 -08:00
render ( ) {
const { report } = this . props ;
2020-12-31 15:54:08 -08:00
const menu = this . makeMenu ( ) ;
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' >
< Avatar account = { report . get ( 'account' ) } size = { 32 } / >
< / 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}'
values = { { acct : ` @ ${ report . getIn ( [ 'account' , 'acct' ] ) } ` } }
/ >
< / h 4 >
< div class = 'admin-report__quote' >
< blockquote className = 'md' > { report . get ( 'content' ) } < / b l o c k q u o t e >
< span className = 'byline' > & mdash ; @ { report . getIn ( [ 'actor' , 'acct' ] ) } < / s p a n >
< / 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 >
) ;
}
}