-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #700 from coralproject/refactor-ban-suspend-actions
Refactor and reuse "Actions" in "Moderate" and "Community"
- Loading branch information
Showing
40 changed files
with
428 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {SHOW_BAN_USER_DIALOG, HIDE_BAN_USER_DIALOG} from '../constants/banUserDialog'; | ||
|
||
export const showBanUserDialog = ({userId, username, commentId, commentStatus}) => | ||
({type: SHOW_BAN_USER_DIALOG, userId, username, commentId, commentStatus}); | ||
|
||
export const hideBanUserDialog = () => ({type: HIDE_BAN_USER_DIALOG}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {SHOW_SUSPEND_USER_DIALOG, HIDE_SUSPEND_USER_DIALOG} from '../constants/suspendUserDialog.js'; | ||
|
||
export const showSuspendUserDialog = ({userId, username, commentId, commentStatus}) => | ||
({type: SHOW_SUSPEND_USER_DIALOG, userId, username, commentId, commentStatus}); | ||
|
||
export const hideSuspendUserDialog = () => ({type: HIDE_SUSPEND_USER_DIALOG}); | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, {PropTypes} from 'react'; | ||
import {Dialog} from 'coral-ui'; | ||
import styles from './BanUserDialog.css'; | ||
|
||
import Button from 'coral-ui/components/Button'; | ||
import t from 'coral-framework/services/i18n'; | ||
|
||
const BanUserDialog = ({open, onCancel, onPerform, username, info}) => ( | ||
<Dialog | ||
className={styles.dialog} | ||
id="banUserDialog" | ||
open={open} | ||
onCancel={onCancel} | ||
title={t('bandialog.ban_user')}> | ||
<span className={styles.close} onClick={onCancel}>×</span> | ||
<div> | ||
<div className={styles.header}> | ||
<h2>{t('bandialog.ban_user')}</h2> | ||
</div> | ||
<div className={styles.separator}> | ||
<h3>{t('bandialog.are_you_sure', username)}</h3> | ||
<i>{info}</i> | ||
</div> | ||
<div className={styles.buttons}> | ||
<Button cStyle="cancel" className={styles.cancel} onClick={onCancel} raised> | ||
{t('bandialog.cancel')} | ||
</Button> | ||
<Button cStyle="black" className={styles.ban} onClick={onPerform} raised> | ||
{t('bandialog.yes_ban_user')} | ||
</Button> | ||
</div> | ||
</div> | ||
</Dialog> | ||
); | ||
|
||
BanUserDialog.propTypes = { | ||
open: PropTypes.bool, | ||
onPerform: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
username: PropTypes.string, | ||
info: PropTypes.string, | ||
}; | ||
|
||
export default BanUserDialog; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SHOW_BAN_USER_DIALOG = 'SHOW_BAN_USER_DIALOG'; | ||
export const HIDE_BAN_USER_DIALOG = 'HIDE_BAN_USER_DIALOG'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SHOW_SUSPEND_USER_DIALOG = 'SHOW_SUSPEND_USER_DIALOG'; | ||
export const HIDE_SUSPEND_USER_DIALOG = 'HIDE_SUSPEND_USER_DIALOG'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, {Component} from 'react'; | ||
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 {compose} from 'react-apollo'; | ||
import t from 'coral-framework/services/i18n'; | ||
|
||
class BanUserDialogContainer extends Component { | ||
|
||
banUser = async () => { | ||
const {userId, commentId, commentStatus, setUserStatus, setCommentStatus, hideBanUserDialog} = this.props; | ||
await setUserStatus({userId, status: 'BANNED'}); | ||
hideBanUserDialog(); | ||
if (commentId && commentStatus && commentStatus !== 'REJECTED') { | ||
await setCommentStatus({commentId, status: 'REJECTED'}); | ||
} | ||
} | ||
|
||
getInfo() { | ||
let note = t('bandialog.note_ban_user'); | ||
if (this.props.commentStatus && this.props.commentStatus !== 'REJECTED') { | ||
note = t('bandialog.note_reject_comment'); | ||
} | ||
return t('bandialog.note', note); | ||
} | ||
|
||
render() { | ||
return ( | ||
<BanUserDialog | ||
open={this.props.open} | ||
onPerform={this.banUser} | ||
onCancel={this.props.hideBanUserDialog} | ||
username={this.props.username} | ||
info={this.getInfo()} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({banUserDialog: {open, userId, username, commentId, commentStatus}}) => ({ | ||
open, | ||
userId, | ||
username, | ||
commentId, | ||
commentStatus, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
...bindActionCreators({ | ||
hideBanUserDialog, | ||
}, dispatch), | ||
}); | ||
|
||
export default compose( | ||
withSetUserStatus, | ||
withSetCommentStatus, | ||
connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
), | ||
)(BanUserDialogContainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, {Component} from 'react'; | ||
import {connect} from 'react-redux'; | ||
import {bindActionCreators} from 'redux'; | ||
import SuspendUserDialog from '../components/SuspendUserDialog'; | ||
import {hideSuspendUserDialog} from '../actions/suspendUserDialog'; | ||
import {withSetCommentStatus, withSuspendUser} from 'coral-framework/graphql/mutations'; | ||
import {compose, gql} from 'react-apollo'; | ||
import * as notification from 'coral-admin/src/services/notification'; | ||
import t, {timeago} from 'coral-framework/services/i18n'; | ||
import withQuery from 'coral-framework/hocs/withQuery'; | ||
import get from 'lodash/get'; | ||
|
||
class SuspendUserDialogContainer extends Component { | ||
|
||
suspendUser = async ({message, until}) => { | ||
const {userId, username, commentStatus, commentId, hideSuspendUserDialog, setCommentStatus, suspendUser} = this.props; | ||
hideSuspendUserDialog(); | ||
try { | ||
const result = await suspendUser({id: userId, message, until}); | ||
if (result.data.suspendUser.errors) { | ||
throw result.data.suspendUser.errors; | ||
} | ||
notification.success( | ||
t('suspenduser.notify_suspend_until', username, timeago(until)), | ||
); | ||
if (commentId && commentStatus && commentStatus !== 'REJECTED') { | ||
return setCommentStatus({commentId, status: 'REJECTED'}) | ||
.then((result) => { | ||
if (result.data.setCommentStatus.errors) { | ||
throw result.data.setCommentStatus.errors; | ||
} | ||
}); | ||
} | ||
} | ||
catch(err) { | ||
notification.showMutationErrors(err); | ||
} | ||
}; | ||
|
||
render() { | ||
return ( | ||
<SuspendUserDialog | ||
open={this.props.open} | ||
onPerform={this.suspendUser} | ||
onCancel={this.props.hideSuspendUserDialog} | ||
organizationName={get(this.props, 'root.settings.organizationName')} | ||
username={this.props.username} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
const withOrganizationName = withQuery(gql` | ||
query CoralAdmin_SuspendUserDialog { | ||
settings { | ||
organizationName | ||
} | ||
} | ||
`); | ||
|
||
const mapStateToProps = ({suspendUserDialog: {open, userId, username, commentId, commentStatus}}) => ({ | ||
open, | ||
userId, | ||
username, | ||
commentId, | ||
commentStatus, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
...bindActionCreators({ | ||
hideSuspendUserDialog, | ||
}, dispatch), | ||
}); | ||
|
||
export default compose( | ||
connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
), | ||
withSuspendUser, | ||
withSetCommentStatus, | ||
withOrganizationName, | ||
)(SuspendUserDialogContainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {SHOW_BAN_USER_DIALOG, HIDE_BAN_USER_DIALOG} from '../constants/banUserDialog'; | ||
|
||
const initialState = { | ||
open: false, | ||
userId: null, | ||
username: '', | ||
commentId: null, | ||
commentStatus: '', | ||
}; | ||
|
||
export default function banUserDialog(state = initialState, action) { | ||
switch (action.type) { | ||
case SHOW_BAN_USER_DIALOG: | ||
return { | ||
...state, | ||
open: true, | ||
userId: action.userId, | ||
username: action.username, | ||
commentId: action.commentId, | ||
commentStatus: action.commentStatus, | ||
}; | ||
case HIDE_BAN_USER_DIALOG: | ||
return { | ||
...state, | ||
open: false, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.