Use order notes for comments

This commit is contained in:
Almira Krdzic
2018-08-26 17:23:33 +02:00
committed by GotPPay
parent bd1d8f2103
commit 54e6495795
6 changed files with 88 additions and 33 deletions

View File

@@ -62,27 +62,16 @@ const sendComment = () => ({
type: SEND_ORDER_COMMENT
})
export const addComment = (idOrder, newComment, existingComments) => {
export const addComment = (idOrder, newComment) => {
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: localStorage.getItem('username') || '-',
}
const concatenatedComments = (existingComments) ? existingComments.concat(newCommentObject) : [newCommentObject];
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}`,
method: 'put',
url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}/notes`,
method: 'post',
data: {
meta_data: [
{
key:'comments',
value: JSON.stringify(concatenatedComments),
}
]
note : newComment || 'Test comment',
customer_note: true,
}
})
.then(response => {