2021-03-15 16:44:48 -07:00
import React from 'react' ;
2022-06-19 11:38:51 -07:00
import { defineMessages , IntlShape } from 'react-intl' ;
2022-01-10 14:25:06 -08:00
2021-06-30 01:02:52 -07:00
import { fetchAccountByUsername } from 'soapbox/actions/accounts' ;
2022-01-10 14:17:52 -08:00
import { deactivateUsers , deleteUsers , deleteStatus , toggleStatusSensitivity } from 'soapbox/actions/admin' ;
2022-02-02 05:33:12 -08:00
import { openModal } from 'soapbox/actions/modals' ;
2021-01-18 12:59:02 -08:00
import snackbar from 'soapbox/actions/snackbar' ;
2022-09-16 11:30:55 -07:00
import OutlineBox from 'soapbox/components/outline-box' ;
import { Stack , Text } from 'soapbox/components/ui' ;
2022-11-15 08:13:54 -08: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
2022-06-19 11:38:51 -07:00
import type { AppDispatch , RootState } from 'soapbox/store' ;
2021-01-18 12:59:02 -08:00
const messages = defineMessages ( {
2021-12-30 08:38:57 -08:00
deactivateUserHeading : { id : 'confirmations.admin.deactivate_user.heading' , defaultMessage : 'Deactivate @{acct}' } ,
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' } ,
2021-12-30 08:38:57 -08:00
deleteUserHeading : { id : 'confirmations.admin.delete_user.heading' , defaultMessage : 'Delete @{acct}' } ,
2021-01-18 16:25:36 -08:00
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' } ,
2021-12-30 08:38:57 -08:00
deleteStatusHeading : { id : 'confirmations.admin.delete_status.heading' , defaultMessage : 'Delete post' } ,
2021-01-18 16:25:36 -08:00
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-12-30 08:38:57 -08:00
rejectUserHeading : { id : 'confirmations.admin.reject_user.heading' , defaultMessage : 'Reject @{acct}' } ,
2021-12-14 08:00:20 -08:00
rejectUserPrompt : { id : 'confirmations.admin.reject_user.message' , defaultMessage : 'You are about to reject @{acct} registration request. This action cannot be undone.' } ,
rejectUserConfirm : { id : 'confirmations.admin.reject_user.confirm' , defaultMessage : 'Reject @{name}' } ,
2021-01-18 16:25:36 -08:00
statusDeleted : { id : 'admin.statuses.status_deleted_message' , defaultMessage : 'Post by @{acct} was deleted' } ,
2021-12-30 08:38:57 -08:00
markStatusSensitiveHeading : { id : 'confirmations.admin.mark_status_sensitive.heading' , defaultMessage : 'Mark post sensitive' } ,
markStatusNotSensitiveHeading : { id : 'confirmations.admin.mark_status_not_sensitive.heading' , defaultMessage : 'Mark post not sensitive.' } ,
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
} ) ;
2022-06-19 11:38:51 -07:00
const deactivateUserModal = ( intl : IntlShape , accountId : string , afterConfirm = ( ) = > { } ) = >
( dispatch : AppDispatch , getState : ( ) = > RootState ) = > {
2021-01-18 12:59:02 -08:00
const state = getState ( ) ;
2022-06-19 11:38:51 -07:00
const acct = state . accounts . get ( accountId ) ! . acct ;
const name = state . accounts . get ( accountId ) ! . username ;
2021-01-18 16:25:36 -08:00
2022-09-16 10:37:28 -07:00
const message = (
< Stack space = { 4 } >
< OutlineBox >
< AccountContainer id = { accountId } / >
< / OutlineBox >
< Text >
{ intl . formatMessage ( messages . deactivateUserPrompt , { acct } ) }
< / Text >
< / Stack >
) ;
2021-01-18 12:59:02 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2022-07-09 09:20:02 -07:00
icon : require ( '@tabler/icons/user-off.svg' ) ,
2021-12-30 08:38:57 -08:00
heading : intl.formatMessage ( messages . deactivateUserHeading , { acct } ) ,
2022-09-16 10:37:28 -07:00
message ,
2021-01-18 16:25:36 -08:00
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 ( ( ) = > { } ) ;
} ,
} ) ) ;
} ;
2022-06-19 11:38:51 -07:00
const deleteUserModal = ( intl : IntlShape , accountId : string , afterConfirm = ( ) = > { } ) = >
( dispatch : AppDispatch , getState : ( ) = > RootState ) = > {
2021-01-18 12:59:02 -08:00
const state = getState ( ) ;
2022-06-19 11:38:51 -07:00
const account = state . accounts . get ( accountId ) ! ;
const acct = account . acct ;
const name = account . username ;
const local = isLocal ( account ) ;
2021-01-18 16:25:36 -08:00
2022-09-16 10:37:28 -07:00
const message = (
< Stack space = { 4 } >
< OutlineBox >
< AccountContainer id = { accountId } / >
< / OutlineBox >
2021-03-15 16:44:48 -07:00
2022-09-16 10:37:28 -07:00
< Text >
{ intl . formatMessage ( messages . deleteUserPrompt , { acct } ) }
< / Text >
< / Stack >
) ;
2021-03-15 16:59:42 -07:00
2022-09-16 10:37:28 -07:00
const confirm = 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' , {
2022-07-09 09:20:02 -07:00
icon : require ( '@tabler/icons/user-minus.svg' ) ,
2021-12-30 08:38:57 -08:00
heading : intl.formatMessage ( messages . deleteUserHeading , { acct } ) ,
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
2022-06-19 11:38:51 -07:00
const rejectUserModal = ( intl : IntlShape , accountId : string , afterConfirm = ( ) = > { } ) = >
( dispatch : AppDispatch , getState : ( ) = > RootState ) = > {
2021-12-14 08:00:20 -08:00
const state = getState ( ) ;
2022-06-19 11:38:51 -07:00
const acct = state . accounts . get ( accountId ) ! . acct ;
const name = state . accounts . get ( accountId ) ! . username ;
2021-12-14 08:00:20 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2022-07-09 09:20:02 -07:00
icon : require ( '@tabler/icons/user-off.svg' ) ,
2021-12-30 08:38:57 -08:00
heading : intl.formatMessage ( messages . rejectUserHeading , { acct } ) ,
2021-12-14 08:00:20 -08:00
message : intl.formatMessage ( messages . rejectUserPrompt , { acct } ) ,
confirm : intl.formatMessage ( messages . rejectUserConfirm , { name } ) ,
onConfirm : ( ) = > {
dispatch ( deleteUsers ( [ accountId ] ) )
. then ( ( ) = > {
afterConfirm ( ) ;
} )
. catch ( ( ) = > { } ) ;
} ,
} ) ) ;
} ;
2022-06-19 11:38:51 -07:00
const toggleStatusSensitivityModal = ( intl : IntlShape , statusId : string , sensitive : boolean , afterConfirm = ( ) = > { } ) = >
( dispatch : AppDispatch , getState : ( ) = > RootState ) = > {
2021-01-18 18:59:07 -08:00
const state = getState ( ) ;
2022-06-19 11:38:51 -07:00
const accountId = state . statuses . get ( statusId ) ! . account ;
const acct = state . accounts . get ( accountId ) ! . acct ;
2021-01-18 18:59:07 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2022-07-09 09:20:02 -07:00
icon : require ( '@tabler/icons/alert-triangle.svg' ) ,
2021-12-30 08:38:57 -08:00
heading : intl.formatMessage ( sensitive === false ? messages.markStatusSensitiveHeading : messages.markStatusNotSensitiveHeading ) ,
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 ( ) ;
} ,
} ) ) ;
} ;
2022-06-19 11:38:51 -07:00
const deleteStatusModal = ( intl : IntlShape , statusId : string , afterConfirm = ( ) = > { } ) = >
( dispatch : AppDispatch , getState : ( ) = > RootState ) = > {
2021-01-18 13:57:20 -08:00
const state = getState ( ) ;
2022-06-19 11:38:51 -07:00
const accountId = state . statuses . get ( statusId ) ! . account ;
const acct = state . accounts . get ( accountId ) ! . acct ;
2021-01-18 13:57:20 -08:00
dispatch ( openModal ( 'CONFIRM' , {
2022-07-09 09:20:02 -07:00
icon : require ( '@tabler/icons/trash.svg' ) ,
2021-12-30 08:38:57 -08:00
heading : intl.formatMessage ( messages . deleteStatusHeading ) ,
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 ( ) ;
} ,
} ) ) ;
} ;
2022-06-19 11:38:51 -07:00
export {
deactivateUserModal ,
deleteUserModal ,
rejectUserModal ,
toggleStatusSensitivityModal ,
deleteStatusModal ,
} ;