diff --git a/client/coral-admin/src/actions/comments.js b/client/coral-admin/src/actions/comments.js index f89cb5dd3..79af56fd0 100644 --- a/client/coral-admin/src/actions/comments.js +++ b/client/coral-admin/src/actions/comments.js @@ -41,17 +41,6 @@ export const fetchModerationQueueComments = () => { }; }; - -// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error})); - -// Update a comment. Now to update a comment we need to send back the whole object - -export const updateComment = (store, comment) => { - coralApi(`/comments/${comment.get('id')}/status`, {method: 'PUT', body: {status: comment.get('status')}}) - .then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res})) - .catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error})); -}; - // Create a new comment export const createComment = (name, body) => { return dispatch => { @@ -71,9 +60,14 @@ export const createComment = (name, body) => { * Action disptacher related to comments */ -export const updateStatus = (status, id) => (dispatch, getState) => { - dispatch({type: 'COMMENT_STATUS_UPDATE', id, status}); - dispatch({type: 'COMMENT_UPDATE', comment: getState().comments.get('byId').get(id)}); +// Update a comment. Now to update a comment we need to send back the whole object +export const updateStatus = (status, comment) => { + return dispatch => { + dispatch({type: actions.COMMENT_STATUS_UPDATE, id: comment.id, status}); + return coralApi(`/comments/${comment.id}/status`, {method: 'PUT', body: {status: comment.status}}) + .then(res => dispatch({type: actions.COMMENT_UPDATE_SUCCESS, res})) + .catch(error => dispatch({type: actions.COMMENT_UPDATE_FAILED, error})); + }; }; export const flagComment = id => (dispatch, getState) => { diff --git a/client/coral-admin/src/actions/users.js b/client/coral-admin/src/actions/users.js index f1c9e6972..07d7dff3a 100644 --- a/client/coral-admin/src/actions/users.js +++ b/client/coral-admin/src/actions/users.js @@ -3,13 +3,6 @@ import coralApi from '../../../coral-framework/helpers/response'; /** * Action disptacher related to users */ -// export const banUser = (status, userId, commentId) => { -// return dispatch => { -// dispatch({type: 'USER_BAN', status, userId, commentId}); -// dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH'}); -// }; -// }; - // change status of a user export const userStatusUpdate = (status, userId, commentId) => { return dispatch => { diff --git a/client/coral-admin/src/components/Comment.js b/client/coral-admin/src/components/Comment.js index 84c0e0541..291825c71 100644 --- a/client/coral-admin/src/components/Comment.js +++ b/client/coral-admin/src/components/Comment.js @@ -79,7 +79,7 @@ const getActionButton = (action, i, props) => { cStyle={action} icon={props.actionsMap[action].icon} key={i} - onClick={() => props.onClickAction(props.actionsMap[action].status, comment.id)} + onClick={() => props.onClickAction(props.actionsMap[action].status, comment)} /> ); }; diff --git a/client/coral-admin/src/constants/comments.js b/client/coral-admin/src/constants/comments.js index db954ad2c..7e6c46fb1 100644 --- a/client/coral-admin/src/constants/comments.js +++ b/client/coral-admin/src/constants/comments.js @@ -6,3 +6,6 @@ export const COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS = 'COMMENTS_MODERATION_QUEU export const COMMENT_CREATE_SUCCESS = 'COMMENT_CREATE_SUCCESS'; export const COMMENT_CREATE_FAILED = 'COMMENT_CREATE_FAILED'; export const COMMENT_STREAM_FETCH_SUCCESS = 'COMMENT_STREAM_FETCH_SUCCESS'; +export const COMMENT_UPDATE_SUCCESS = 'COMMENT_UPDATE_SUCCESS'; +export const COMMENT_UPDATE_FAILED = 'COMMENT_UPDATE_FAILED'; +export const COMMENT_STATUS_UPDATE = 'COMMENT_STATUS_UPDATE'; diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js index 3df0d210b..40d8d9dce 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js @@ -58,9 +58,9 @@ class ModerationQueue extends React.Component { } // Dispatch the update status action - onCommentAction (action, id) { + onCommentAction (action, comment) { // If not banning then change the status to approved or flagged as action = status - this.props.dispatch(updateStatus(action, id)); + this.props.dispatch(updateStatus(action, comment)); } showBanUserDialog (userId, userName, commentId) { @@ -109,7 +109,7 @@ class ModerationQueue extends React.Component { commentIds={premodIds} comments={comments.byId} users={users.byId} - onClickAction={(action, commentId) => this.onCommentAction(action, commentId)} + onClickAction={(action, comment) => this.onCommentAction(action, comment)} onClickShowBanDialog={(userId, userName, commentId) => this.showBanUserDialog(userId, userName, commentId)} actions={['reject', 'approve', 'ban']} loading={comments.loading} /> @@ -126,7 +126,7 @@ class ModerationQueue extends React.Component { commentIds={rejectedIds} comments={comments.byId} users={users.byId} - onClickAction={(action, id) => this.onCommentAction(action, id)} + onClickAction={(action, comment) => this.onCommentAction(action, comment)} actions={['approve']} loading={comments.loading} /> @@ -137,7 +137,7 @@ class ModerationQueue extends React.Component { commentIds={flaggedIds} comments={comments.byId} users={users.byId} - onClickAction={(action, id) => this.onCommentAction(action, id)} + onClickAction={(action, comment) => this.onCommentAction(action, comment)} actions={['reject', 'approve']} loading={comments.loading} /> diff --git a/client/coral-admin/src/services/store.js b/client/coral-admin/src/services/store.js index 88b2650e0..0700dc579 100644 --- a/client/coral-admin/src/services/store.js +++ b/client/coral-admin/src/services/store.js @@ -2,7 +2,6 @@ import {createStore, applyMiddleware} from 'redux'; import thunk from 'redux-thunk'; import mainReducer from 'reducers'; -import talkAdapter from 'services/talk-adapter'; /** * Create the store by merging the app reducers with @@ -14,5 +13,5 @@ import talkAdapter from 'services/talk-adapter'; export default createStore( mainReducer, window.devToolsExtension && window.devToolsExtension(), - applyMiddleware(thunk, talkAdapter) + applyMiddleware(thunk) ); diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js deleted file mode 100644 index 6c9f3978c..000000000 --- a/client/coral-admin/src/services/talk-adapter.js +++ /dev/null @@ -1,31 +0,0 @@ -import coralApi from '../../../coral-framework/helpers/response'; - -/** - * The adapter is a redux middleware that interecepts the actions that need - * to interface with the backend, do the job and return the results. - * The idea is that if we expose the required actions to handle to devs, the - * moderation app can be platform agnostic. This same client could work not only - * for the coral but also for wordpress comments, disqus and many more. - */ - -// Intercept redux actions and act over the ones we are interested -export default store => next => action => { - - switch (action.type) { - case 'COMMENT_UPDATE': - updateComment(store, action.comment); - break; - } - - next(action); -}; - -// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error})); - -// Update a comment. Now to update a comment we need to send back the whole object - -const updateComment = (store, comment) => { - coralApi(`/comments/${comment.get('id')}/status`, {method: 'PUT', body: {status: comment.get('status')}}) - .then(res => store.dispatch({type: 'COMMENT_UPDATE_SUCCESS', res})) - .catch(error => store.dispatch({type: 'COMMENT_UPDATE_FAILED', error})); -};