Admin: refactor fetchUsers() action

remove-account-counters-reducer
Alex Gleason 2021-07-13 17:27:11 -05:00
rodzic 3043924045
commit 732fba73f5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
4 zmienionych plików z 10 dodań i 9 usunięć

Wyświetl plik

@ -125,17 +125,19 @@ export function closeReports(ids) {
return patchReports(ids, 'closed');
}
export function fetchUsers(params) {
export function fetchUsers(filters = [], page = 1, pageSize = 50) {
return (dispatch, getState) => {
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, params });
const params = { filters: filters.join(), page, page_size: pageSize };
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
return api(getState)
.get('/api/pleroma/admin/users', { params })
.then(({ data: { users, count, page_size: pageSize } }) => {
dispatch(fetchRelationships(users.map(user => user.id)));
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users, count, pageSize, params });
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users, count, pageSize, filters, page });
return { users, count, pageSize };
}).catch(error => {
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, params });
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize });
});
};
}

Wyświetl plik

@ -39,8 +39,7 @@ class AwaitingApproval extends ImmutablePureComponent {
componentDidMount() {
const { dispatch } = this.props;
const params = { page: 1, filters: 'local,need_approval' };
dispatch(fetchUsers(params))
dispatch(fetchUsers(['local', 'need_approval']))
.then(() => this.setState({ isLoading: false }))
.catch(() => {});
}

Wyświetl plik

@ -34,9 +34,9 @@ class UserIndex extends ImmutablePureComponent {
fetchNextPage = () => {
const nextPage = this.state.page + 1;
const filters = this.state.filters.toJS().join();
const filters = this.state.filters.toJS();
this.props.dispatch(fetchUsers({ filters, page: nextPage }))
this.props.dispatch(fetchUsers(filters, nextPage))
.then(({ users, count }) => {
const newIds = users.map(user => user.id);

Wyświetl plik

@ -430,7 +430,7 @@ class UI extends React.PureComponent {
if (isStaff(account)) {
this.props.dispatch(fetchReports({ state: 'open' }));
this.props.dispatch(fetchUsers({ page: 1, filters: 'local,need_approval' }));
this.props.dispatch(fetchUsers(['local', 'need_approval']));
}
if (isAdmin(account)) {