diff --git a/frontend/src/actions/orders/processActions.js b/frontend/src/actions/orders/processActions.js index 922a218..808c40c 100644 --- a/frontend/src/actions/orders/processActions.js +++ b/frontend/src/actions/orders/processActions.js @@ -62,23 +62,26 @@ const sendComment = () => ({ type: SEND_ORDER_COMMENT }) -export const addComment = (idOrder, comment) => { +export const addComment = (idOrder, newComment, existingComments) => { return dispatch => { dispatch(sendComment()); //TODO: get real user name and store in comment object + const newCommentObject = { + comment : newComment, + date : moment().format("Do MMM, YY"), + username: 'username', + isOwner: 1, + } + const concatenatedComments = (existingComments) ? existingComments.concat(newCommentObject) : [newCommentObject]; + return htmlClient.fetch({ url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}`, - method: 'post', + method: 'put', data: { meta_data: [ { - key: `comment-${moment().unix()}`, - value: { - comment: comment, - addDate: moment().format("Do MMM, YY"), - username: 'username', - isOwner: 1 - } + key:'comments', + value: JSON.stringify(concatenatedComments), } ] } diff --git a/frontend/src/containers/orders/components/OrderComments.jsx b/frontend/src/containers/orders/components/OrderComments.jsx index 85fc4c3..c30bcaa 100644 --- a/frontend/src/containers/orders/components/OrderComments.jsx +++ b/frontend/src/containers/orders/components/OrderComments.jsx @@ -18,7 +18,7 @@ class OrderComments extends Component { } addNewComment(){ - this.props.dispatch(addComment(this.props.orderInfo.id, this.state.newComment)); + this.props.dispatch(addComment(this.props.orderInfo.id, this.state.newComment, this.props.orderComments)); } onEditorChange(newComment){ @@ -48,7 +48,7 @@ class OrderComments extends Component {
-
{orderComment.username} - {orderComment.addDate}
+
{orderComment.username} - {orderComment.date}