From 0ba973fb4417d2fc47cadc91c65ff4e43e08357f Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Wed, 3 May 2017 18:05:06 -0700 Subject: [PATCH] editComment returns status of comment after edit. UI shows appropriate notifications if PREMOD or REJECTED --- .../src/EditableCommentContent.js | 6 +++++- .../graphql/mutations/editComment.graphql | 3 +++ client/coral-plugin-commentbox/CommentBox.js | 14 ++++++++++++-- graph/mutators/comment.js | 1 + graph/resolvers/root_mutation.js | 2 +- graph/typeDefs.graphql | 6 ++++++ 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/client/coral-embed-stream/src/EditableCommentContent.js b/client/coral-embed-stream/src/EditableCommentContent.js index 6a22b958a..3116ec96b 100644 --- a/client/coral-embed-stream/src/EditableCommentContent.js +++ b/client/coral-embed-stream/src/EditableCommentContent.js @@ -1,5 +1,5 @@ import React, {PropTypes} from 'react'; -import {CommentForm} from 'coral-plugin-commentbox/CommentBox'; +import {notifyForNewCommentStatus, CommentForm} from 'coral-plugin-commentbox/CommentBox'; import styles from './Comment.css'; import {Icon} from 'coral-ui'; @@ -94,6 +94,10 @@ export class EditableCommentContent extends React.Component { throw error; } } + if (successfullyEdited) { + const status = response.data.editComment.comment.status; + notifyForNewCommentStatus(this.props.addNotification, status); + } if (successfullyEdited && typeof stopEditing === 'function') { stopEditing(); } diff --git a/client/coral-framework/graphql/mutations/editComment.graphql b/client/coral-framework/graphql/mutations/editComment.graphql index e143af064..05e532002 100644 --- a/client/coral-framework/graphql/mutations/editComment.graphql +++ b/client/coral-framework/graphql/mutations/editComment.graphql @@ -1,5 +1,8 @@ mutation editComment ($id: ID!, $edit: EditCommentInput) { editComment(id:$id, edit:$edit) { + comment { + status + } errors { translation_key } diff --git a/client/coral-plugin-commentbox/CommentBox.js b/client/coral-plugin-commentbox/CommentBox.js index 7b20e9b99..5b60fac2e 100644 --- a/client/coral-plugin-commentbox/CommentBox.js +++ b/client/coral-plugin-commentbox/CommentBox.js @@ -8,6 +8,16 @@ import classnames from 'classnames'; const name = 'coral-plugin-commentbox'; +// Given a newly posted comment's status, show a notification to the user +// if needed +export const notifyForNewCommentStatus = (addNotification, status) => { + if (status === 'REJECTED') { + addNotification('error', lang.t('comment-post-banned-word')); + } else if (status === 'PREMOD') { + addNotification('success', lang.t('comment-post-notif-premod')); + } +}; + /** * Common UI for Creating or Editing a Comment */ @@ -189,11 +199,11 @@ class CommentBox extends Component { // Execute postSubmit Hooks this.state.hooks.postSubmit.forEach(hook => hook(data)); + notifyForNewCommentStatus(addNotification, postedComment.status); + if (postedComment.status === 'REJECTED') { - addNotification('error', lang.t('comment-post-banned-word')); !isReply && updateCountCache(assetId, countCache); } else if (postedComment.status === 'PREMOD') { - addNotification('success', lang.t('comment-post-notif-premod')); !isReply && updateCountCache(assetId, countCache); } diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 4bb228adb..c813ac112 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -259,6 +259,7 @@ const editComment = async ({user, loaders: {Comments}}, {id, edit}) => { throw error; } } + return {status}; }; module.exports = (context) => { diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 6a91ec3f2..6305ee140 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -6,7 +6,7 @@ const RootMutation = { return wrapResponse('comment')(Comment.create(comment)); }, editComment(_, args, {mutators: {Comment}}) { - return wrapResponse(null)(Comment.editComment(args)); + return wrapResponse('comment')(Comment.editComment(args)); }, createLike(_, {like: {item_id, item_type}}, {mutators: {Action}}) { return wrapResponse('like')(Action.create({item_id, item_type, action_type: 'LIKE'})); diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index c28e38d00..c7ce02ff1 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -794,7 +794,13 @@ input EditCommentInput { body: String! } +type CommentInfoAfterEdit { + # New status of the edited comment + status: COMMENT_STATUS! +} + type EditCommentResponse implements Response { + comment: CommentInfoAfterEdit! # An array of errors relating to the mutation that occured. errors: [UserError] }