2021-03-15 16:44:48 -07:00
import React from 'react' ;
2021-01-18 12:59:02 -08:00
import { defineMessages } from 'react-intl' ;
import { openModal } from 'soapbox/actions/modal' ;
2021-01-18 18:59:07 -08:00
import { deactivateUsers , deleteUsers , deleteStatus , toggleStatusSensitivity } from 'soapbox/actions/admin' ;
2021-06-30 01:02:52 -07:00
import { fetchAccountByUsername } from 'soapbox/actions/accounts' ;
2021-01-18 12:59:02 -08:00
import snackbar from 'soapbox/actions/snackbar' ;
2021-03-15 16:44:48 -07:00
import AccountContainer from 'soapbox/containers/account_container' ;
2021-03-15 17:29:42 -07:00
import { isLocal } from 'soapbox/utils/accounts' ;
2021-01-18 12:59:02 -08:00
const messages = defineMessages ( {
2021-01-18 16:25:36 -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 @{name}' } ,
userDeactivated : { id : 'admin.users.user_deactivated_message' , defaultMessage : '@{acct} was deactivated' } ,
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 @{name}' } ,
2021-03-15 17:29:42 -07:00
deleteLocalUserCheckbox : { id : 'confirmations.admin.delete_local_user.checkbox' , defaultMessage : 'I understand that I am about to delete a local user.' } ,
2021-01-18 16:25:36 -08:00
userDeleted : { id : 'admin.users.user_deleted_message' , defaultMessage : '@{acct} was deleted' } ,
deleteStatusPrompt : { id : 'confirmations.admin.delete_status.message' , defaultMessage : 'You are about to delete a post by @{acct}. This action cannot be undone.' } ,
2021-01-18 13:57:20 -08:00
deleteStatusConfirm : { id : 'confirmations.admin.delete_status.confirm' , defaultMessage : 'Delete post' } ,
2021-01-18 16:25:36 -08:00
statusDeleted : { id : 'admin.statuses.status_deleted_message' , defaultMessage : 'Post by @{acct} was deleted' } ,
2021-01-18 19:09:35 -08:00
markStatusSensitivePrompt : { id : 'confirmations.admin.mark_status_sensitive.message' , defaultMessage : 'You are about to mark a post by @{acct} sensitive.' } ,
markStatusNotSensitivePrompt : { id : 'confirmations.admin.mark_status_not_sensitive.message' , defaultMessage : 'You are about to mark a post by @{acct} not sensitive.' } ,
2021-01-18 18:59:07 -08:00
markStatusSensitiveConfirm : { id : 'confirmations.admin.mark_status_sensitive.confirm' , defaultMessage : 'Mark post sensitive' } ,
markStatusNotSensitiveConfirm : { id : 'confirmations.admin.mark_status_not_sensitive.confirm' , defaultMessage : 'Mark post not sensitive' } ,
2021-01-18 19:09:35 -08:00
statusMarkedSensitive : { id : 'admin.statuses.status_marked_message_sensitive' , defaultMessage : 'Post by @{acct} was marked sensitive' } ,
statusMarkedNotSensitive : { id : 'admin.statuses.status_marked_message_not_sensitive' , defaultMessage : 'Post by @{acct} was marked not sensitive' } ,
2021-01-18 12:59:02 -08:00
} ) ;
export function deactivateUserModal ( intl , accountId , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
2021-01-18 16:25:36 -08:00
const name = state . getIn ( [ 'accounts' , accountId , 'username' ] ) ;
2021-01-18 12:59:02 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2021-01-18 16:25:36 -08:00
message : intl . formatMessage ( messages . deactivateUserPrompt , { acct } ) ,
confirm : intl . formatMessage ( messages . deactivateUserConfirm , { name } ) ,
2021-01-18 12:59:02 -08:00
onConfirm : ( ) => {
2021-07-13 16:11:11 -07:00
dispatch ( deactivateUsers ( [ accountId ] ) ) . then ( ( ) => {
2021-01-18 16:25:36 -08:00
const message = intl . formatMessage ( messages . userDeactivated , { acct } ) ;
2021-01-18 12:59:02 -08:00
dispatch ( snackbar . success ( message ) ) ;
afterConfirm ( ) ;
} ) . catch ( ( ) => { } ) ;
} ,
} ) ) ;
} ;
}
export function deleteUserModal ( intl , accountId , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
2021-01-18 16:25:36 -08:00
const name = state . getIn ( [ 'accounts' , accountId , 'username' ] ) ;
2021-03-15 16:59:42 -07:00
const favicon = state . getIn ( [ 'accounts' , accountId , 'pleroma' , 'favicon' ] ) ;
2021-03-15 17:29:42 -07:00
const local = isLocal ( state . getIn ( [ 'accounts' , accountId ] ) ) ;
2021-01-18 16:25:36 -08:00
2021-03-15 16:44:48 -07:00
const message = ( < >
< AccountContainer id = { accountId } / >
{ intl . formatMessage ( messages . deleteUserPrompt , { acct } ) }
< / > ) ;
2021-03-15 16:59:42 -07:00
const confirm = ( < >
{ favicon &&
< div className = 'submit__favicon' >
< img src = { favicon } alt = '' / >
< / d i v > }
{ intl . formatMessage ( messages . deleteUserConfirm , { name } ) }
< / > ) ;
2021-03-15 17:29:42 -07:00
const checkbox = local ? intl . formatMessage ( messages . deleteLocalUserCheckbox ) : false ;
2021-01-18 12:59:02 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2021-03-15 16:44:48 -07:00
message ,
2021-03-15 16:59:42 -07:00
confirm ,
2021-03-15 17:29:42 -07:00
checkbox ,
2021-01-18 12:59:02 -08:00
onConfirm : ( ) => {
2021-07-13 16:11:11 -07:00
dispatch ( deleteUsers ( [ accountId ] ) ) . then ( ( ) => {
2021-01-18 16:25:36 -08:00
const message = intl . formatMessage ( messages . userDeleted , { acct } ) ;
2021-06-30 01:02:52 -07:00
dispatch ( fetchAccountByUsername ( acct ) ) ;
2021-01-18 12:59:02 -08:00
dispatch ( snackbar . success ( message ) ) ;
afterConfirm ( ) ;
} ) . catch ( ( ) => { } ) ;
} ,
} ) ) ;
} ;
}
2021-01-18 13:57:20 -08:00
2021-01-18 18:59:07 -08:00
export function toggleStatusSensitivityModal ( intl , statusId , sensitive , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const accountId = state . getIn ( [ 'statuses' , statusId , 'account' ] ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
dispatch ( openModal ( 'CONFIRM' , {
2021-01-18 19:16:00 -08:00
message : intl . formatMessage ( sensitive === false ? messages . markStatusSensitivePrompt : messages . markStatusNotSensitivePrompt , { acct } ) ,
2021-01-18 18:59:07 -08:00
confirm : intl . formatMessage ( sensitive === false ? messages . markStatusSensitiveConfirm : messages . markStatusNotSensitiveConfirm ) ,
onConfirm : ( ) => {
dispatch ( toggleStatusSensitivity ( statusId , sensitive ) ) . then ( ( ) => {
2021-01-18 19:16:00 -08:00
const message = intl . formatMessage ( sensitive === false ? messages . statusMarkedSensitive : messages . statusMarkedNotSensitive , { acct } ) ;
2021-01-18 18:59:07 -08:00
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
afterConfirm ( ) ;
} ,
} ) ) ;
} ;
}
2021-01-18 13:57:20 -08:00
export function deleteStatusModal ( intl , statusId , afterConfirm = ( ) => { } ) {
return function ( dispatch , getState ) {
const state = getState ( ) ;
const accountId = state . getIn ( [ 'statuses' , statusId , 'account' ] ) ;
const acct = state . getIn ( [ 'accounts' , accountId , 'acct' ] ) ;
dispatch ( openModal ( 'CONFIRM' , {
2021-01-18 16:25:36 -08:00
message : intl . formatMessage ( messages . deleteStatusPrompt , { acct } ) ,
2021-01-18 13:57:20 -08:00
confirm : intl . formatMessage ( messages . deleteStatusConfirm ) ,
onConfirm : ( ) => {
dispatch ( deleteStatus ( statusId ) ) . then ( ( ) => {
2021-01-18 16:25:36 -08:00
const message = intl . formatMessage ( messages . statusDeleted , { acct } ) ;
2021-01-18 13:57:20 -08:00
dispatch ( snackbar . success ( message ) ) ;
} ) . catch ( ( ) => { } ) ;
afterConfirm ( ) ;
} ,
} ) ) ;
} ;
}