Merge branch 'user-deletions' into 'develop'

Admin: optimistic user deletions

See merge request soapbox-pub/soapbox-fe!556
actually-fix-tabs-bar
Alex Gleason 2021-06-30 08:04:15 +00:00
commit cf06c06085
2 zmienionych plików z 20 dodań i 0 usunięć

Wyświetl plik

@ -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(() => {});

Wyświetl plik

@ -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;
}