2020-12-31 20:20:31 -08:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { injectIntl , defineMessages } from 'react-intl' ;
import StatusContent from 'soapbox/components/status_content' ;
import DropdownMenu from 'soapbox/containers/dropdown_menu_container' ;
import { deleteStatus } from 'soapbox/actions/admin' ;
import snackbar from 'soapbox/actions/snackbar' ;
import { openModal } from 'soapbox/actions/modal' ;
const messages = defineMessages ( {
2020-12-31 20:40:13 -08:00
viewStatus : { id : 'admin.reports.actions.view_status' , defaultMessage : 'View post' } ,
2020-12-31 20:20:31 -08:00
deleteStatus : { id : 'admin.reports.actions.delete_status' , defaultMessage : 'Delete post' } ,
deleteStatusPrompt : { id : 'confirmations.admin.delete_status.message' , defaultMessage : 'You are about to delete a post by {acct}. This action cannot be undone.' } ,
deleteStatusConfirm : { id : 'confirmations.admin.delete_status.confirm' , defaultMessage : 'Delete post' } ,
statusDeleted : { id : 'admin.reports.status_deleted_message' , defaultMessage : 'Post by {acct} was deleted' } ,
} ) ;
export default @ connect ( )
@ injectIntl
class ReportStatus extends ImmutablePureComponent {
static propTypes = {
status : ImmutablePropTypes . map . isRequired ,
report : ImmutablePropTypes . map ,
} ;
makeMenu = ( ) => {
const { intl , status } = this . props ;
2020-12-31 20:40:13 -08:00
const acct = status . getIn ( [ 'account' , 'acct' ] ) ;
2020-12-31 20:20:31 -08:00
return [ {
2020-12-31 20:40:13 -08:00
text : intl . formatMessage ( messages . viewStatus , { acct : ` @ ${ acct } ` } ) ,
to : ` /@ ${ acct } /posts/ ${ status . get ( 'id' ) } ` ,
} , {
text : intl . formatMessage ( messages . deleteStatus , { acct : ` @ ${ acct } ` } ) ,
2020-12-31 20:20:31 -08:00
action : this . handleDeleteStatus ,
} ] ;
}
handleDeleteStatus = ( ) => {
const { intl , dispatch , status } = this . props ;
const nickname = status . getIn ( [ 'account' , 'acct' ] ) ;
const statusId = status . get ( 'id' ) ;
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . deleteStatusPrompt , { acct : ` @ ${ nickname } ` } ) ,
confirm : intl . formatMessage ( messages . deleteStatusConfirm ) ,
onConfirm : ( ) => {
dispatch ( deleteStatus ( statusId ) ) . then ( ( ) => {
const message = intl . formatMessage ( messages . statusDeleted , { acct : ` @ ${ nickname } ` } ) ;
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
this . handleCloseReport ( ) ;
} ,
} ) ) ;
}
render ( ) {
const { status } = this . props ;
const menu = this . makeMenu ( ) ;
return (
< div className = 'admin-report__status' >
< StatusContent status = { status } / >
< div className = 'admin-report__status-actions' >
< DropdownMenu items = { menu } icon = 'ellipsis-v' size = { 18 } direction = 'right' / >
< / d i v >
< / d i v >
) ;
}
}