mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 06:11:58 +08:00
Refactor for setUserStatus to setUserBanStatus
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import React, {Component} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {connect} from 'react-redux';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import BanUserDialog from '../components/BanUserDialog';
|
||||
import {hideBanUserDialog} from '../actions/banUserDialog';
|
||||
import {withSetUserStatus, withSetCommentStatus} from 'coral-framework/graphql/mutations';
|
||||
import {withSetUserBanStatus, withSetCommentStatus} from 'coral-framework/graphql/mutations';
|
||||
import {compose} from 'react-apollo';
|
||||
import t from 'coral-framework/services/i18n';
|
||||
import {getErrorMessages} from 'coral-framework/utils';
|
||||
@@ -12,9 +13,9 @@ import {notify} from 'coral-framework/actions/notification';
|
||||
class BanUserDialogContainer extends Component {
|
||||
|
||||
banUser = async () => {
|
||||
const {userId, commentId, commentStatus, setUserStatus, setCommentStatus, hideBanUserDialog, notify} = this.props;
|
||||
const {userId, commentId, commentStatus, setUserBanStatus, setCommentStatus, hideBanUserDialog, notify} = this.props;
|
||||
try {
|
||||
await setUserStatus({userId, status: 'BANNED'});
|
||||
await setUserBanStatus({id: userId, status: true});
|
||||
hideBanUserDialog();
|
||||
if (commentId && commentStatus && commentStatus !== 'REJECTED') {
|
||||
await setCommentStatus({commentId, status: 'REJECTED'});
|
||||
@@ -46,6 +47,14 @@ class BanUserDialogContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
BanUserDialogContainer.propTypes = {
|
||||
setUserBanStatus: PropTypes.func.isRequired,
|
||||
hideBanUserDialog: PropTypes.func,
|
||||
open: PropTypes.bool,
|
||||
username: PropTypes.string,
|
||||
commentStatus: PropTypes.string,
|
||||
};
|
||||
|
||||
const mapStateToProps = ({banUserDialog: {open, userId, username, commentId, commentStatus}}) => ({
|
||||
open,
|
||||
userId,
|
||||
@@ -62,7 +71,7 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
});
|
||||
|
||||
export default compose(
|
||||
withSetUserStatus,
|
||||
withSetUserBanStatus,
|
||||
withSetCommentStatus,
|
||||
connect(
|
||||
mapStateToProps,
|
||||
|
||||
@@ -13,15 +13,15 @@ function mapLeaves(o, mapper) {
|
||||
|
||||
export default {
|
||||
mutations: {
|
||||
SetUserStatus: ({variables: {status, userId}}) => ({
|
||||
SetUserBanStatus: ({variables: {status, id}}) => ({
|
||||
updateQueries: {
|
||||
TalkAdmin_Community: (prev) => {
|
||||
if (status !== 'APPROVED') {
|
||||
if (!status) {
|
||||
return prev;
|
||||
}
|
||||
const updated = update(prev, {
|
||||
users: {
|
||||
nodes: {$apply: (nodes) => nodes.filter((node) => node.id !== userId)},
|
||||
nodes: {$apply: (nodes) => nodes.filter((node) => node.id !== id)},
|
||||
},
|
||||
});
|
||||
return updated;
|
||||
|
||||
@@ -18,7 +18,7 @@ const People = (props) => {
|
||||
totalPages,
|
||||
page,
|
||||
setRole,
|
||||
setCommenterStatus,
|
||||
setUserBanStatus,
|
||||
viewUserDetail,
|
||||
} = props;
|
||||
|
||||
@@ -46,7 +46,7 @@ const People = (props) => {
|
||||
users={users}
|
||||
setRole={setRole}
|
||||
viewUserDetail={viewUserDetail}
|
||||
setCommenterStatus={setCommenterStatus}
|
||||
setUserBanStatus={setUserBanStatus}
|
||||
onHeaderClickHandler={onHeaderClickHandler}
|
||||
pageCount={totalPages}
|
||||
onPageChange={onPageChange}
|
||||
@@ -67,7 +67,7 @@ People.propTypes = {
|
||||
onSearchChange: PropTypes.func,
|
||||
totalPages: PropTypes.number,
|
||||
onPageChange: PropTypes.func,
|
||||
setCommenterStatus: PropTypes.func.isRequired,
|
||||
setUserBanStatus: PropTypes.func.isRequired,
|
||||
setRole: PropTypes.func.isRequired,
|
||||
viewUserDetail: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ const getStatus = (status) => {
|
||||
return status.banned.status ? 'BANNED' : 'ACTIVE';
|
||||
};
|
||||
|
||||
const Table = ({users, setRole, onHeaderClickHandler, setCommenterStatus, viewUserDetail, pageCount, page, onPageChange}) => (
|
||||
const Table = ({users, setRole, onHeaderClickHandler, setUserBanStatus, viewUserDetail, pageCount, page, onPageChange}) => (
|
||||
<div>
|
||||
<table className={`mdl-data-table ${styles.dataTable}`}>
|
||||
<thead>
|
||||
@@ -59,7 +59,7 @@ const Table = ({users, setRole, onHeaderClickHandler, setCommenterStatus, viewUs
|
||||
containerClassName="talk-admin-community-people-dd-status"
|
||||
value={getStatus(row.status)}
|
||||
placeholder={t('community.status')}
|
||||
onChange={(status) => setCommenterStatus(row.id, status)}>
|
||||
onChange={(status) => setUserBanStatus({id: row.id, status: status !== 'BANNED'})}>
|
||||
<Option value={'ACTIVE'} label={t('community.active')} />
|
||||
<Option value={'BANNED'} label={t('community.banned')} />
|
||||
</Dropdown>
|
||||
@@ -92,7 +92,7 @@ Table.propTypes = {
|
||||
users: PropTypes.array,
|
||||
onHeaderClickHandler: PropTypes.func.isRequired,
|
||||
setRole: PropTypes.func.isRequired,
|
||||
setCommenterStatus: PropTypes.func.isRequired,
|
||||
setUserBanStatus: PropTypes.func.isRequired,
|
||||
viewUserDetail: PropTypes.func.isRequired,
|
||||
pageCount: PropTypes.number.isRequired,
|
||||
page: PropTypes.number.isRequired,
|
||||
|
||||
@@ -3,7 +3,7 @@ import {bindActionCreators} from 'redux';
|
||||
import {compose, gql} from 'react-apollo';
|
||||
import withQuery from 'coral-framework/hocs/withQuery';
|
||||
import {getDefinitionName} from 'coral-framework/utils';
|
||||
import {withSetUserStatus, withRejectUsername} from 'coral-framework/graphql/mutations';
|
||||
import {withSetUserBanStatus, withRejectUsername} from 'coral-framework/graphql/mutations';
|
||||
import FlaggedAccounts from '../containers/FlaggedAccounts';
|
||||
import FlaggedUser from '../containers/FlaggedUser';
|
||||
import {hideRejectUsernameDialog} from '../../../actions/community';
|
||||
@@ -48,7 +48,7 @@ const withData = withQuery(gql`
|
||||
|
||||
export default compose(
|
||||
connect(mapStateToProps, mapDispatchToProps),
|
||||
withSetUserStatus,
|
||||
withSetUserBanStatus,
|
||||
withRejectUsername,
|
||||
withData
|
||||
)(Community);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {withFragments} from 'plugin-api/beta/client/hocs';
|
||||
import {Spinner} from 'coral-ui';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import {withSetUserStatus} from 'coral-framework/graphql/mutations';
|
||||
import {withSetUserBanStatus} from 'coral-framework/graphql/mutations';
|
||||
import {showBanUserDialog} from 'actions/banUserDialog';
|
||||
import {showSuspendUserDialog} from 'actions/suspendUserDialog';
|
||||
import {showRejectUsernameDialog} from '../../../actions/community';
|
||||
@@ -25,9 +25,9 @@ class FlaggedAccountsContainer extends Component {
|
||||
}
|
||||
|
||||
approveUser = ({userId}) => {
|
||||
return this.props.setUserStatus({
|
||||
userId,
|
||||
status: 'APPROVED'
|
||||
return this.props.setUserBanStatus({
|
||||
id: userId,
|
||||
status: false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ FlaggedAccountsContainer.propTypes = {
|
||||
showSuspendUserDialog: PropTypes.func,
|
||||
showRejectUsernameDialog: PropTypes.func,
|
||||
viewUserDetail: PropTypes.func,
|
||||
setUserStatus: PropTypes.func,
|
||||
setUserBanStatus: PropTypes.func,
|
||||
data: PropTypes.object,
|
||||
root: PropTypes.object
|
||||
};
|
||||
@@ -121,7 +121,7 @@ const mapDispatchToProps = (dispatch) =>
|
||||
|
||||
export default compose(
|
||||
connect(null, mapDispatchToProps),
|
||||
withSetUserStatus,
|
||||
withSetUserBanStatus,
|
||||
withFragments({
|
||||
root: gql`
|
||||
fragment TalkAdminCommunity_FlaggedAccounts_root on RootQuery {
|
||||
|
||||
@@ -11,13 +11,12 @@ import {
|
||||
updateSorting,
|
||||
setPage,
|
||||
hideRejectUsernameDialog,
|
||||
setCommenterStatus,
|
||||
setRole,
|
||||
setSearchValue,
|
||||
} from '../../../actions/community';
|
||||
|
||||
class PeopleContainer extends React.Component {
|
||||
timer=null;
|
||||
timer = null;
|
||||
|
||||
fetchUsers = (query = {}) => {
|
||||
const {community} = this.props;
|
||||
@@ -70,7 +69,7 @@ class PeopleContainer extends React.Component {
|
||||
onHeaderClickHandler={this.onHeaderClickHandler}
|
||||
onPageChange={this.onPageChange}
|
||||
totalPages={this.props.community.totalPagesPeople}
|
||||
setCommenterStatus={this.props.setCommenterStatus}
|
||||
setUserBanStatus={this.props.setUserBanStatus}
|
||||
setRole={this.props.setRole}
|
||||
page={this.props.community.pagePeople}
|
||||
viewUserDetail={this.props.viewUserDetail}
|
||||
@@ -83,7 +82,7 @@ PeopleContainer.propTypes = {
|
||||
fetchUsers: PropTypes.func,
|
||||
updateSorting: PropTypes.func,
|
||||
setRole: PropTypes.func.isRequired,
|
||||
setCommenterStatus: PropTypes.func.isRequired,
|
||||
setUserBanStatus: PropTypes.func.isRequired,
|
||||
setSearchValue: PropTypes.func.isRequired,
|
||||
viewUserDetail: PropTypes.func.isRequired,
|
||||
community: PropTypes.object,
|
||||
@@ -95,7 +94,6 @@ const mapDispatchToProps = (dispatch) =>
|
||||
fetchUsers,
|
||||
updateSorting,
|
||||
hideRejectUsernameDialog,
|
||||
setCommenterStatus,
|
||||
setRole,
|
||||
viewUserDetail,
|
||||
setSearchValue,
|
||||
|
||||
@@ -8,7 +8,6 @@ export default {
|
||||
'SuspendUserResponse',
|
||||
'RejectUsernameResponse',
|
||||
'CreateCommentResponse',
|
||||
'SetUserStatusResponse',
|
||||
'CreateFlagResponse',
|
||||
'EditCommentResponse',
|
||||
'PostFlagResponse',
|
||||
|
||||
@@ -196,20 +196,20 @@ export const withRejectUsername = withMutation(
|
||||
})
|
||||
});
|
||||
|
||||
export const withSetUserStatus = withMutation(
|
||||
export const withsetUserBanStatus = withMutation(
|
||||
gql`
|
||||
mutation SetUserStatus($userId: ID!, $status: USER_STATUS!) {
|
||||
setUserStatus(id: $userId, status: $status) {
|
||||
...SetUserStatusResponse
|
||||
mutation SetUserBanStatus($id: ID!, $status: Boolean!) {
|
||||
setUserBanStatus(id: $id, status: $status) {
|
||||
...SetUserBanStatusResponse
|
||||
}
|
||||
}
|
||||
`, {
|
||||
props: ({mutate}) => ({
|
||||
setUserStatus: ({userId, status}) => {
|
||||
setUserBanStatus: ({id, status}) => {
|
||||
return mutate({
|
||||
variables: {
|
||||
userId,
|
||||
status
|
||||
id,
|
||||
status,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export {default as connect} from 'coral-framework/hocs/connect';
|
||||
export {default as withEmit} from 'coral-framework/hocs/withEmit';
|
||||
export {
|
||||
withIgnoreUser,
|
||||
withSetUserStatus,
|
||||
withSetUserBanStatus,
|
||||
withStopIgnoringUser,
|
||||
withSetCommentStatus,
|
||||
} from 'coral-framework/graphql/mutations';
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {compose} from 'react-apollo';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import {closeBanDialog, closeMenu} from '../actions';
|
||||
import {notify} from 'plugin-api/beta/client/actions/notification';
|
||||
import {connect, withSetCommentStatus, withSetUserStatus} from 'plugin-api/beta/client/hocs';
|
||||
import {connect, withSetCommentStatus, withSetUserBanStatus} from 'plugin-api/beta/client/hocs';
|
||||
import {getErrorMessages} from 'plugin-api/beta/client/utils';
|
||||
import BanUserDialog from '../components/BanUserDialog';
|
||||
|
||||
@@ -19,13 +20,13 @@ class BanUserDialogContainer extends React.Component {
|
||||
closeMenu,
|
||||
closeBanDialog,
|
||||
setCommentStatus,
|
||||
setUserStatus
|
||||
setUserBanStatus
|
||||
} = this.props;
|
||||
|
||||
try {
|
||||
await setUserStatus({
|
||||
userId: authorId,
|
||||
status: 'BANNED'
|
||||
await setUserBanStatus({
|
||||
id: authorId,
|
||||
status: true,
|
||||
});
|
||||
|
||||
closeMenu();
|
||||
@@ -54,23 +55,28 @@ class BanUserDialogContainer extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
BanUserDialogContainer.propTypes = {
|
||||
showBanDialog: PropTypes.func,
|
||||
closeBanDialog: PropTypes.func,
|
||||
};
|
||||
|
||||
const mapStateToProps = ({talkPluginModerationActions: state}) => ({
|
||||
showBanDialog: state.showBanDialog,
|
||||
commentId: state.commentId,
|
||||
authorId: state.authorId
|
||||
authorId: state.authorId,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) =>
|
||||
bindActionCreators({
|
||||
notify,
|
||||
closeBanDialog,
|
||||
closeMenu
|
||||
closeMenu,
|
||||
}, dispatch);
|
||||
|
||||
const enhance = compose(
|
||||
connect(mapStateToProps, mapDispatchToProps),
|
||||
withSetCommentStatus,
|
||||
withSetUserStatus
|
||||
withSetUserBanStatus
|
||||
);
|
||||
|
||||
export default enhance(BanUserDialogContainer);
|
||||
|
||||
Reference in New Issue
Block a user