sforkowany z mirror/soapbox
Admin: optimistic user deletions
rodzic
4b141ef605
commit
3edf243bbe
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import { defineMessages } from 'react-intl';
|
||||
import { openModal } from 'soapbox/actions/modal';
|
||||
import { deactivateUsers, deleteUsers, deleteStatus, toggleStatusSensitivity } from 'soapbox/actions/admin';
|
||||
import { fetchAccountByUsername } from 'soapbox/actions/accounts';
|
||||
import snackbar from 'soapbox/actions/snackbar';
|
||||
import AccountContainer from 'soapbox/containers/account_container';
|
||||
import { isLocal } from 'soapbox/utils/accounts';
|
||||
|
@ -75,6 +76,7 @@ export function deleteUserModal(intl, accountId, afterConfirm = () => {}) {
|
|||
onConfirm: () => {
|
||||
dispatch(deleteUsers([acct])).then(() => {
|
||||
const message = intl.formatMessage(messages.userDeleted, { acct });
|
||||
dispatch(fetchAccountByUsername(acct));
|
||||
dispatch(snackbar.success(message));
|
||||
afterConfirm();
|
||||
}).catch(() => {});
|
||||
|
|
|
@ -18,6 +18,7 @@ import {
|
|||
ADMIN_USERS_UNTAG_REQUEST,
|
||||
ADMIN_USERS_UNTAG_FAIL,
|
||||
} from 'soapbox/actions/admin';
|
||||
import { ADMIN_USERS_DELETE_REQUEST } from 'soapbox/actions/admin';
|
||||
|
||||
const initialState = ImmutableMap();
|
||||
|
||||
|
@ -74,6 +75,21 @@ const removeTags = (state, accountIds, tags) => {
|
|||
});
|
||||
};
|
||||
|
||||
const nicknamesToIds = (state, nicknames) => {
|
||||
return nicknames.map(nickname => {
|
||||
return state.find(account => account.get('acct') === nickname, null, ImmutableMap()).get('id');
|
||||
});
|
||||
};
|
||||
|
||||
const setDeactivated = (state, nicknames) => {
|
||||
const ids = nicknamesToIds(state, nicknames);
|
||||
return state.withMutations(state => {
|
||||
ids.forEach(id => {
|
||||
state.setIn([id, 'pleroma', 'is_active'], false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default function accounts(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case ACCOUNT_IMPORT:
|
||||
|
@ -95,6 +111,8 @@ export default function accounts(state = initialState, action) {
|
|||
case ADMIN_USERS_UNTAG_REQUEST:
|
||||
case ADMIN_USERS_TAG_FAIL:
|
||||
return removeTags(state, action.accountIds, action.tags);
|
||||
case ADMIN_USERS_DELETE_REQUEST:
|
||||
return setDeactivated(state, action.nicknames);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue