change comments handling
This commit is contained in:
@@ -62,23 +62,26 @@ const sendComment = () => ({
|
|||||||
type: SEND_ORDER_COMMENT
|
type: SEND_ORDER_COMMENT
|
||||||
})
|
})
|
||||||
|
|
||||||
export const addComment = (idOrder, comment) => {
|
export const addComment = (idOrder, newComment, existingComments) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(sendComment());
|
dispatch(sendComment());
|
||||||
//TODO: get real user name and store in comment object
|
//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({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}`,
|
url: `${API_SERVER}/wp-json/wc/v2/orders/${idOrder}`,
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: {
|
data: {
|
||||||
meta_data: [
|
meta_data: [
|
||||||
{
|
{
|
||||||
key: `comment-${moment().unix()}`,
|
key:'comments',
|
||||||
value: {
|
value: JSON.stringify(concatenatedComments),
|
||||||
comment: comment,
|
|
||||||
addDate: moment().format("Do MMM, YY"),
|
|
||||||
username: 'username',
|
|
||||||
isOwner: 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class OrderComments extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addNewComment(){
|
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){
|
onEditorChange(newComment){
|
||||||
@@ -48,7 +48,7 @@ class OrderComments extends Component {
|
|||||||
<Row key={'order-comment-' + index}>
|
<Row key={'order-comment-' + index}>
|
||||||
<Col xl={{size:6, offset:this.getOffset(orderComment.isOwner)}}>
|
<Col xl={{size:6, offset:this.getOffset(orderComment.isOwner)}}>
|
||||||
<div className={'order-comment ' + this.getClassByOwner(orderComment.isOwner)} key={'order-comment-' + index}>
|
<div className={'order-comment ' + this.getClassByOwner(orderComment.isOwner)} key={'order-comment-' + index}>
|
||||||
<div className="order-comment-header">{orderComment.username} - {orderComment.addDate}</div>
|
<div className="order-comment-header">{orderComment.username} - {orderComment.date}</div>
|
||||||
<div dangerouslySetInnerHTML={{__html: orderComment.comment}}></div>
|
<div dangerouslySetInnerHTML={{__html: orderComment.comment}}></div>
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
Reference in New Issue
Block a user