Reports: allow deactivating a user
This commit is contained in:
parent
a16e709ff4
commit
95c4ba4234
|
@ -24,6 +24,10 @@ export const ADMIN_USERS_APPROVE_REQUEST = 'ADMIN_USERS_APPROVE_REQUEST';
|
|||
export const ADMIN_USERS_APPROVE_SUCCESS = 'ADMIN_USERS_APPROVE_SUCCESS';
|
||||
export const ADMIN_USERS_APPROVE_FAIL = 'ADMIN_USERS_APPROVE_FAIL';
|
||||
|
||||
export const ADMIN_USERS_DEACTIVATE_REQUEST = 'ADMIN_USERS_DEACTIVATE_REQUEST';
|
||||
export const ADMIN_USERS_DEACTIVATE_SUCCESS = 'ADMIN_USERS_DEACTIVATE_SUCCESS';
|
||||
export const ADMIN_USERS_DEACTIVATE_FAIL = 'ADMIN_USERS_DEACTIVATE_FAIL';
|
||||
|
||||
export function fetchConfig() {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({ type: ADMIN_CONFIG_FETCH_REQUEST });
|
||||
|
@ -76,6 +80,19 @@ export function fetchUsers(params) {
|
|||
};
|
||||
}
|
||||
|
||||
export function deactivateUsers(nicknames) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({ type: ADMIN_USERS_DEACTIVATE_REQUEST, nicknames });
|
||||
return api(getState)
|
||||
.patch('/api/pleroma/admin/users/deactivate', { nicknames })
|
||||
.then(({ data: { users } }) => {
|
||||
dispatch({ type: ADMIN_USERS_DEACTIVATE_SUCCESS, users, nicknames });
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_USERS_DEACTIVATE_FAIL, error, nicknames });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteUsers(nicknames) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({ type: ADMIN_USERS_DELETE_REQUEST, nicknames });
|
||||
|
|
|
@ -1,21 +1,53 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { injectIntl, FormattedMessage, defineMessages } from 'react-intl';
|
||||
import Avatar from 'soapbox/components/avatar';
|
||||
import DropdownMenu from 'soapbox/containers/dropdown_menu_container';
|
||||
import { deactivateUsers } from 'soapbox/actions/admin';
|
||||
import snackbar from 'soapbox/actions/snackbar';
|
||||
|
||||
export default class Report extends ImmutablePureComponent {
|
||||
const messages = defineMessages({
|
||||
deactivateUser: { id: 'admin.reports.actions.deactivate_user', defaultMessage: 'Deactivate {acct}' },
|
||||
deactivated: { id: 'admin.reports.deactivated_message', defaultMessage: '{acct} was deactivated' },
|
||||
});
|
||||
|
||||
export default @connect()
|
||||
@injectIntl
|
||||
class Report extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
report: ImmutablePropTypes.map.isRequired,
|
||||
};
|
||||
|
||||
makeMenu = () => {
|
||||
const { intl, report } = this.props;
|
||||
|
||||
return [{
|
||||
text: intl.formatMessage(messages.deactivateUser, { acct: `@${report.getIn(['account', 'acct'])}` }),
|
||||
action: this.handleDeactivateUser,
|
||||
}];
|
||||
}
|
||||
|
||||
handleDeactivateUser = () => {
|
||||
const { intl, dispatch, report } = this.props;
|
||||
const nickname = report.getIn(['account', 'acct']);
|
||||
dispatch(deactivateUsers([nickname])).then(() => {
|
||||
const message = intl.formatMessage(messages.deactivated, { acct: nickname });
|
||||
dispatch(snackbar.success(message));
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { report } = this.props;
|
||||
const menu = this.makeMenu();
|
||||
|
||||
return (
|
||||
<div className='admin-report' key={report.get('id')}>
|
||||
<div className='admin-report__avatar'>
|
||||
<Avatar account={report.get('account')} size={32} />
|
||||
</div>
|
||||
<div className='admin-report__content'>
|
||||
<h4 className='admin-report__title'>
|
||||
<FormattedMessage
|
||||
|
@ -29,6 +61,9 @@ export default class Report extends ImmutablePureComponent {
|
|||
<span className='byline'>— @{report.getIn(['actor', 'acct'])}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='admin-report__actions'>
|
||||
<DropdownMenu items={menu} icon='ellipsis-v' size={24} direction='right' />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@
|
|||
border-bottom: 1px solid var(--brand-color--faint);
|
||||
|
||||
&__content {
|
||||
padding-left: 16px;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
&__title {
|
||||
|
@ -140,4 +140,8 @@
|
|||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
&__actions {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue