editComment returns status of comment after edit. UI shows appropriate notifications if PREMOD or REJECTED

This commit is contained in:
Benjamin Goering
2017-05-03 18:05:06 -07:00
parent 3ac8f09619
commit 0ba973fb44
6 changed files with 28 additions and 4 deletions
@@ -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();
}
@@ -1,5 +1,8 @@
mutation editComment ($id: ID!, $edit: EditCommentInput) {
editComment(id:$id, edit:$edit) {
comment {
status
}
errors {
translation_key
}
+12 -2
View File
@@ -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);
}
+1
View File
@@ -259,6 +259,7 @@ const editComment = async ({user, loaders: {Comments}}, {id, edit}) => {
throw error;
}
}
return {status};
};
module.exports = (context) => {
+1 -1
View File
@@ -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'}));
+6
View File
@@ -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]
}