From fd0b475b848a7222a668d09865b4691edd40bb0f Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Thu, 23 Nov 2017 08:07:13 -0300 Subject: [PATCH] banUser and unBanUser - removing setUserStatus --- .../src/routes/Community/components/People.js | 9 +- .../src/routes/Community/components/Table.js | 135 ++++++++---------- .../src/routes/Community/containers/People.js | 13 +- client/coral-framework/graphql/fragments.js | 3 +- plugin-api/beta/client/hocs/index.js | 3 +- .../client/containers/BanUserDialog.js | 8 +- 6 files changed, 82 insertions(+), 89 deletions(-) diff --git a/client/coral-admin/src/routes/Community/components/People.js b/client/coral-admin/src/routes/Community/components/People.js index f46415e13..4057eaf67 100644 --- a/client/coral-admin/src/routes/Community/components/People.js +++ b/client/coral-admin/src/routes/Community/components/People.js @@ -18,8 +18,7 @@ const People = (props) => { totalPages, page, setRole, - banUser, - unBanUser, + setUserBanStatus, viewUserDetail, } = props; @@ -47,8 +46,7 @@ const People = (props) => { users={users} setRole={setRole} viewUserDetail={viewUserDetail} - banUser={banUser} - unBanUser={unBanUser} + setUserBanStatus={setUserBanStatus} onHeaderClickHandler={onHeaderClickHandler} pageCount={totalPages} onPageChange={onPageChange} @@ -69,8 +67,7 @@ People.propTypes = { onSearchChange: PropTypes.func, totalPages: PropTypes.number, onPageChange: PropTypes.func, - banUser: PropTypes.func.isRequired, - unBanUser: PropTypes.func.isRequired, + setUserBanStatus: PropTypes.func.isRequired, setRole: PropTypes.func.isRequired, viewUserDetail: PropTypes.func.isRequired, }; diff --git a/client/coral-admin/src/routes/Community/components/Table.js b/client/coral-admin/src/routes/Community/components/Table.js index 9f949cc59..97b1db996 100644 --- a/client/coral-admin/src/routes/Community/components/Table.js +++ b/client/coral-admin/src/routes/Community/components/Table.js @@ -23,84 +23,75 @@ const headers = [ field: 'role' } ]; - -const Table = ({users, setRole, onHeaderClickHandler, banUser, unBanUser, viewUserDetail, pageCount, page, onPageChange}) => { - - const getStatus = (status) => { - return status.banned.status ? 'BANNED' : 'ACTIVE'; - }; - - const setUserBanStatus = (id, bannedStatus) => { - return bannedStatus ? unBanUser(id) : banUser(id); - }; - - return ( -
- - - - {headers.map((header, i) =>( - - ))} - - - - {users.map((row, i)=> ( - - - - - - - ))} - -
onHeaderClickHandler({field: header.field})}> - {header.title} -
- - {row.profiles.map(({id}) => id)} - - {row.created_at} - - setUserBanStatus(row.id, status === 'BANNED')}> - - - setRole(row.id, role)}> - -
- -
- ); +const getStatus = (status) => { + return status.banned.status ? 'BANNED' : 'ACTIVE'; }; +const Table = ({users, setRole, onHeaderClickHandler, setUserBanStatus, viewUserDetail, pageCount, page, onPageChange}) => ( +
+ + + + {headers.map((header, i) =>( + + ))} + + + + {users.map((row, i)=> ( + + + + + + + ))} + +
onHeaderClickHandler({field: header.field})}> + {header.title} +
+ + {row.profiles.map(({id}) => id)} + + {row.created_at} + + setUserBanStatus(row.id, status === 'BANNED')}> + + + setRole(row.id, role)}> + +
+ +
+); + Table.propTypes = { users: PropTypes.array, onHeaderClickHandler: PropTypes.func.isRequired, setRole: PropTypes.func.isRequired, - banUser: PropTypes.func.isRequired, - unBanUser: PropTypes.func.isRequired, + setUserBanStatus: PropTypes.func.isRequired, viewUserDetail: PropTypes.func.isRequired, pageCount: PropTypes.number.isRequired, page: PropTypes.number.isRequired, diff --git a/client/coral-admin/src/routes/Community/containers/People.js b/client/coral-admin/src/routes/Community/containers/People.js index d857aa367..48a5acdd6 100644 --- a/client/coral-admin/src/routes/Community/containers/People.js +++ b/client/coral-admin/src/routes/Community/containers/People.js @@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux'; import {compose} from 'react-apollo'; import People from '../components/People'; import PropTypes from 'prop-types'; -import {withSetUserBanStatus} from 'coral-framework/graphql/mutations'; +import {withUnBanUser, withBanUser} from 'coral-framework/graphql/mutations'; import {viewUserDetail} from '../../../actions/userDetail'; @@ -63,8 +63,9 @@ class PeopleContainer extends React.Component { this.fetchUsers({page}); } - setUserBanStatus = async (input) => { - await this.props.setUserBanStatus(input); + setUserBanStatus = async (id, bannedStatus) => { + const {banUser, unBanUser} = this.props; + await bannedStatus ? banUser({id, message: ''}) : unBanUser({id}); this.fetchUsers(); } @@ -89,7 +90,8 @@ PeopleContainer.propTypes = { fetchUsers: PropTypes.func, updateSorting: PropTypes.func, setRole: PropTypes.func.isRequired, - setUserBanStatus: PropTypes.func.isRequired, + banUser: PropTypes.func.isRequired, + unBanUser: PropTypes.func.isRequired, setSearchValue: PropTypes.func.isRequired, viewUserDetail: PropTypes.func.isRequired, community: PropTypes.object, @@ -108,5 +110,6 @@ const mapDispatchToProps = (dispatch) => export default compose( connect(null, mapDispatchToProps), - withSetUserBanStatus, + withBanUser, + withUnBanUser, )(PeopleContainer); diff --git a/client/coral-framework/graphql/fragments.js b/client/coral-framework/graphql/fragments.js index 4fb84f18e..fa45b69da 100644 --- a/client/coral-framework/graphql/fragments.js +++ b/client/coral-framework/graphql/fragments.js @@ -4,7 +4,8 @@ import {createDefaultResponseFragments} from '../utils'; export default { ...createDefaultResponseFragments( 'ChangeUsernameResponse', - 'SetUserBanStatusResponse', + 'BanUsersResponse', + 'UnBanUserResponse', 'SetUserSuspensionStatusResponse', 'SetCommentStatusResponse', 'SuspendUserResponse', diff --git a/plugin-api/beta/client/hocs/index.js b/plugin-api/beta/client/hocs/index.js index 0723141bd..15cbab034 100644 --- a/plugin-api/beta/client/hocs/index.js +++ b/plugin-api/beta/client/hocs/index.js @@ -7,7 +7,8 @@ export {default as connect} from 'coral-framework/hocs/connect'; export {default as withEmit} from 'coral-framework/hocs/withEmit'; export { withIgnoreUser, - withSetUserBanStatus, + withBanUser, + withUnBanUser, withStopIgnoringUser, withSetCommentStatus, } from 'coral-framework/graphql/mutations'; diff --git a/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js b/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js index 0d6578f58..b783b3655 100644 --- a/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js +++ b/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js @@ -5,7 +5,7 @@ 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, withSetUserBanStatus} from 'plugin-api/beta/client/hocs'; +import {connect, withSetCommentStatus, withBanUser} from 'plugin-api/beta/client/hocs'; import {getErrorMessages} from 'plugin-api/beta/client/utils'; import BanUserDialog from '../components/BanUserDialog'; @@ -20,11 +20,11 @@ class BanUserDialogContainer extends React.Component { closeMenu, closeBanDialog, setCommentStatus, - setUserBanStatus + banUser, } = this.props; try { - await setUserBanStatus({ + await banUser({ id: authorId, status: true, }); @@ -76,7 +76,7 @@ const mapDispatchToProps = (dispatch) => const enhance = compose( connect(mapStateToProps, mapDispatchToProps), withSetCommentStatus, - withSetUserBanStatus + withBanUser, ); export default enhance(BanUserDialogContainer);