diff --git a/client/coral-admin/src/containers/BanUserDialog.js b/client/coral-admin/src/containers/BanUserDialog.js index 2c72b3380..67e8daf67 100644 --- a/client/coral-admin/src/containers/BanUserDialog.js +++ b/client/coral-admin/src/containers/BanUserDialog.js @@ -6,15 +6,22 @@ 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'; +import {getErrorMessages} from 'coral-framework/utils'; +import {notify} from 'coral-framework/actions/notification'; 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'}); + const {userId, commentId, commentStatus, setUserStatus, setCommentStatus, hideBanUserDialog, notify} = this.props; + try { + await setUserStatus({userId, status: 'BANNED'}); + hideBanUserDialog(); + if (commentId && commentStatus && commentStatus !== 'REJECTED') { + await setCommentStatus({commentId, status: 'REJECTED'}); + } + } + catch(err) { + notify('error', getErrorMessages(err)); } } @@ -50,6 +57,7 @@ const mapStateToProps = ({banUserDialog: {open, userId, username, commentId, com const mapDispatchToProps = (dispatch) => ({ ...bindActionCreators({ hideBanUserDialog, + notify, }, dispatch), }); diff --git a/client/coral-admin/src/containers/SuspendUserDialog.js b/client/coral-admin/src/containers/SuspendUserDialog.js index 1616acfcf..12e9843b4 100644 --- a/client/coral-admin/src/containers/SuspendUserDialog.js +++ b/client/coral-admin/src/containers/SuspendUserDialog.js @@ -17,21 +17,13 @@ class SuspendUserDialogContainer extends Component { const {userId, username, commentStatus, commentId, hideSuspendUserDialog, setCommentStatus, suspendUser, notify} = this.props; hideSuspendUserDialog(); try { - const result = await suspendUser({id: userId, message, until}); - if (result.data.suspendUser.errors) { - throw result.data.suspendUser.errors; - } + await suspendUser({id: userId, message, until}); notify( '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; - } - }); + await setCommentStatus({commentId, status: 'REJECTED'}); } } catch(err) { diff --git a/plugin-api/beta/client/hocs/withReaction.js b/plugin-api/beta/client/hocs/withReaction.js index 0656f1236..36d48316f 100644 --- a/plugin-api/beta/client/hocs/withReaction.js +++ b/plugin-api/beta/client/hocs/withReaction.js @@ -7,12 +7,13 @@ import {getDisplayName} from 'coral-framework/helpers/hoc'; import {compose, gql} from 'react-apollo'; import withFragments from 'coral-framework/hocs/withFragments'; import withMutation from 'coral-framework/hocs/withMutation'; -import {addNotification} from 'coral-framework/actions/notification'; +import {notify} from 'coral-framework/actions/notification'; import {capitalize} from 'coral-framework/helpers/strings'; -import {getMyActionSummary, getTotalActionCount} from 'coral-framework/utils'; +import {getMyActionSummary, getTotalActionCount, getErrorMessages} from 'coral-framework/utils'; import hoistStatics from 'recompose/hoistStatics'; import * as PropTypes from 'prop-types'; import {getDefinitionName} from '../utils'; +import {t, can} from 'plugin-api/beta/client/services'; // TODO: Auth logic needs refactoring. import {showSignInDialog} from 'coral-embed-stream/src/actions/auth'; @@ -248,9 +249,23 @@ export default (reaction, options = {}) => hoistStatics((WrappedComponent) => { return; } this.duringMutation = true; + + // If the current user is suspended, do nothing. + if (!can(this.props.user, 'INTERACT_WITH_COMMUNITY')) { + notify('error', t('error.NOT_AUTHORIZED')); + return; + } + return this.props.postReaction(this.props.comment) - .then((result) => {this.duringMutation = false; return Promise.resolve(result); }) - .catch((err) => {this.duringMutation = false; throw err; }); + .then((result) => { + this.duringMutation = false; + return result; + }) + .catch((err) => { + this.duringMutation = false; + this.props.notify('error', getErrorMessages(err)); + throw err; + }); } deleteReaction = () => { @@ -258,9 +273,23 @@ export default (reaction, options = {}) => hoistStatics((WrappedComponent) => { return; } this.duringMutation = true; + + // If the current user is suspended, do nothing. + if (!can(this.props.user, 'INTERACT_WITH_COMMUNITY')) { + notify('error', t('error.NOT_AUTHORIZED')); + return; + } + return this.props.deleteReaction(this.props.comment) - .then((result) => {this.duringMutation = false; return Promise.resolve(result); }) - .catch((err) => {this.duringMutation = false; throw err; }); + .then((result) => { + this.duringMutation = false; + return result; + }) + .catch((err) => { + this.duringMutation = false; + this.props.notify('error', getErrorMessages(err)); + throw err; + }); } render() { @@ -283,7 +312,7 @@ export default (reaction, options = {}) => hoistStatics((WrappedComponent) => { asset={asset} comment={comment} showSignInDialog={this.props.showSignInDialog} - addNotification={this.props.addNotification} + notify={this.props.notify} user={this.props.user} reactionSummary={reactionSummary} count={count} @@ -386,7 +415,7 @@ export default (reaction, options = {}) => hoistStatics((WrappedComponent) => { }); const mapDispatchToProps = (dispatch) => - bindActionCreators({showSignInDialog, addNotification}, dispatch); + bindActionCreators({showSignInDialog, notify}, dispatch); const enhance = compose( withFragments({ diff --git a/plugin-api/beta/client/hocs/withTags.js b/plugin-api/beta/client/hocs/withTags.js index c5d98a119..66fd7ad2e 100644 --- a/plugin-api/beta/client/hocs/withTags.js +++ b/plugin-api/beta/client/hocs/withTags.js @@ -6,8 +6,8 @@ import {getDisplayName} from 'coral-framework/helpers/hoc'; import {capitalize} from 'coral-framework/helpers/strings'; import {withAddTag, withRemoveTag} from 'coral-framework/graphql/mutations'; import withFragments from 'coral-framework/hocs/withFragments'; -import {addNotification} from 'coral-framework/actions/notification'; -import {forEachError, isTagged} from 'coral-framework/utils'; +import {notify} from 'coral-framework/actions/notification'; +import {getErrorMessages, isTagged} from 'coral-framework/utils'; import hoistStatics from 'recompose/hoistStatics'; import {getDefinitionName} from '../utils'; @@ -37,7 +37,7 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { loading = false; postTag = () => { - const {comment, asset, addNotification} = this.props; + const {comment, asset, notify} = this.props; if (this.loading) { return; @@ -45,23 +45,25 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { this.loading = true; - this.props.addTag({ + return this.props.addTag({ id: comment.id, name: TAG, assetId: asset.id, itemType: 'COMMENTS', }) - .then(() => { + .then((result) => { this.loading = false; + return result; }) .catch((err) => { this.loading = false; - forEachError(err, ({msg}) => addNotification('error', msg)); + notify('error', getErrorMessages(err)); + throw err; }); } deleteTag = () => { - const {comment, asset, addNotification} = this.props; + const {comment, asset, notify} = this.props; if (this.loading) { return; @@ -73,12 +75,14 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { assetId: asset.id, itemType: 'COMMENTS', }) - .then(() => { + .then((result) => { this.loading = false; + return result; }) .catch((err) => { this.loading = false; - forEachError(err, ({msg}) => addNotification('error', msg)); + notify('error', getErrorMessages(err)); + throw err; }); } @@ -105,7 +109,7 @@ export default (tag, options = {}) => hoistStatics((WrappedComponent) => { }); const mapDispatchToProps = (dispatch) => - bindActionCreators({addNotification}, dispatch); + bindActionCreators({notify}, dispatch); const enhance = compose( withFragments({ diff --git a/plugins/talk-plugin-like/client/LikeButton.js b/plugins/talk-plugin-like/client/LikeButton.js index 7c504c757..ece85537d 100644 --- a/plugins/talk-plugin-like/client/LikeButton.js +++ b/plugins/talk-plugin-like/client/LikeButton.js @@ -1,7 +1,7 @@ import React from 'react'; import styles from './styles.css'; import {withReaction} from 'plugin-api/beta/client/hocs'; -import {t, can} from 'plugin-api/beta/client/services'; +import {t} from 'plugin-api/beta/client/services'; import {Icon} from 'plugin-api/beta/client/components/ui'; import cn from 'classnames'; @@ -13,7 +13,6 @@ class LikeButton extends React.Component { postReaction, deleteReaction, showSignInDialog, - addNotification, alreadyReacted, user, } = this.props; @@ -24,12 +23,6 @@ class LikeButton extends React.Component { return; } - // If the current user is suspended, do nothing. - if (!can(user, 'INTERACT_WITH_COMMUNITY')) { - addNotification('error', t('error.NOT_AUTHORIZED')); - return; - } - if (alreadyReacted) { deleteReaction(); } else { diff --git a/plugins/talk-plugin-love/client/LoveButton.js b/plugins/talk-plugin-love/client/LoveButton.js index 083145963..8c6a4848c 100644 --- a/plugins/talk-plugin-love/client/LoveButton.js +++ b/plugins/talk-plugin-love/client/LoveButton.js @@ -1,7 +1,7 @@ import React from 'react'; import styles from './styles.css'; import {withReaction} from 'plugin-api/beta/client/hocs'; -import {t, can} from 'plugin-api/beta/client/services'; +import {t} from 'plugin-api/beta/client/services'; import {Icon} from 'plugin-api/beta/client/components/ui'; import cn from 'classnames'; @@ -13,7 +13,6 @@ class LoveButton extends React.Component { postReaction, deleteReaction, showSignInDialog, - addNotification, alreadyReacted, user, } = this.props; @@ -24,12 +23,6 @@ class LoveButton extends React.Component { return; } - // If the current user is suspended, do nothing. - if (!can(user, 'INTERACT_WITH_COMMUNITY')) { - addNotification('error', t('error.NOT_AUTHORIZED')); - return; - } - if (alreadyReacted) { deleteReaction(); } else { diff --git a/plugins/talk-plugin-respect/client/RespectButton.js b/plugins/talk-plugin-respect/client/RespectButton.js index d827ce67e..e77fd61c8 100644 --- a/plugins/talk-plugin-respect/client/RespectButton.js +++ b/plugins/talk-plugin-respect/client/RespectButton.js @@ -2,7 +2,7 @@ import React from 'react'; import Icon from './Icon'; import styles from './styles.css'; import {withReaction} from 'plugin-api/beta/client/hocs'; -import {t, can} from 'plugin-api/beta/client/services'; +import {t} from 'plugin-api/beta/client/services'; import cn from 'classnames'; const plugin = 'talk-plugin-respect'; @@ -14,7 +14,6 @@ class RespectButton extends React.Component { deleteReaction, showSignInDialog, alreadyReacted, - addNotification, user, } = this.props; @@ -24,12 +23,6 @@ class RespectButton extends React.Component { return; } - // If the current user is suspended, do nothing. - if (!can(user, 'INTERACT_WITH_COMMUNITY')) { - addNotification('error', t('error.NOT_AUTHORIZED')); - return; - } - if (alreadyReacted) { deleteReaction(); } else {