Admin: optimistic user deletions
This commit is contained in:
parent
4b141ef605
commit
3edf243bbe
2 changed files with 20 additions and 0 deletions
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||||
import { defineMessages } from 'react-intl';
|
import { defineMessages } from 'react-intl';
|
||||||
import { openModal } from 'soapbox/actions/modal';
|
import { openModal } from 'soapbox/actions/modal';
|
||||||
import { deactivateUsers, deleteUsers, deleteStatus, toggleStatusSensitivity } from 'soapbox/actions/admin';
|
import { deactivateUsers, deleteUsers, deleteStatus, toggleStatusSensitivity } from 'soapbox/actions/admin';
|
||||||
|
import { fetchAccountByUsername } from 'soapbox/actions/accounts';
|
||||||
import snackbar from 'soapbox/actions/snackbar';
|
import snackbar from 'soapbox/actions/snackbar';
|
||||||
import AccountContainer from 'soapbox/containers/account_container';
|
import AccountContainer from 'soapbox/containers/account_container';
|
||||||
import { isLocal } from 'soapbox/utils/accounts';
|
import { isLocal } from 'soapbox/utils/accounts';
|
||||||
|
@ -75,6 +76,7 @@ export function deleteUserModal(intl, accountId, afterConfirm = () => {}) {
|
||||||
onConfirm: () => {
|
onConfirm: () => {
|
||||||
dispatch(deleteUsers([acct])).then(() => {
|
dispatch(deleteUsers([acct])).then(() => {
|
||||||
const message = intl.formatMessage(messages.userDeleted, { acct });
|
const message = intl.formatMessage(messages.userDeleted, { acct });
|
||||||
|
dispatch(fetchAccountByUsername(acct));
|
||||||
dispatch(snackbar.success(message));
|
dispatch(snackbar.success(message));
|
||||||
afterConfirm();
|
afterConfirm();
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
ADMIN_USERS_UNTAG_REQUEST,
|
ADMIN_USERS_UNTAG_REQUEST,
|
||||||
ADMIN_USERS_UNTAG_FAIL,
|
ADMIN_USERS_UNTAG_FAIL,
|
||||||
} from 'soapbox/actions/admin';
|
} from 'soapbox/actions/admin';
|
||||||
|
import { ADMIN_USERS_DELETE_REQUEST } from 'soapbox/actions/admin';
|
||||||
|
|
||||||
const initialState = ImmutableMap();
|
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) {
|
export default function accounts(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case ACCOUNT_IMPORT:
|
case ACCOUNT_IMPORT:
|
||||||
|
@ -95,6 +111,8 @@ export default function accounts(state = initialState, action) {
|
||||||
case ADMIN_USERS_UNTAG_REQUEST:
|
case ADMIN_USERS_UNTAG_REQUEST:
|
||||||
case ADMIN_USERS_TAG_FAIL:
|
case ADMIN_USERS_TAG_FAIL:
|
||||||
return removeTags(state, action.accountIds, action.tags);
|
return removeTags(state, action.accountIds, action.tags);
|
||||||
|
case ADMIN_USERS_DELETE_REQUEST:
|
||||||
|
return setDeactivated(state, action.nicknames);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue