change comments handling

This commit is contained in:
GotPPay
2018-08-15 22:19:24 +02:00
parent 152804d6dc
commit 768e3b919e
2 changed files with 14 additions and 11 deletions

View File

@@ -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),
}
]
}