fix: notification for orders

This commit is contained in:
Vlad Stan 2023-07-03 16:30:04 +03:00
parent 21a77d643f
commit 2b84ebc83b
5 changed files with 54 additions and 38 deletions

View file

@ -107,9 +107,9 @@ async function directMessages(path) {
this.showAddPublicKey = false
}
},
handleNewMessage: async function (dm) {
if (dm.customerPubkey === this.activePublicKey) {
this.messages.push(dm.data)
handleNewMessage: async function (data) {
if (data.customerPubkey === this.activePublicKey) {
this.messages.push(data.dm)
this.focusOnChatBox(this.messages.length - 1)
// focus back on input box
}

View file

@ -233,7 +233,8 @@ async function orderList(path) {
!this.search.publicKey ||
this.search.publicKey === data.customerPubkey
) {
const order = await this.getOrder(data.orderId)
const orderData = JSON.parse(data.dm.message)
const order = await this.getOrder(orderData.id)
this.orders.unshift(order)
}
},

View file

@ -162,21 +162,37 @@ const merchant = async () => {
this.wsConnection = new WebSocket(wsUrl)
this.wsConnection.onmessage = async e => {
const data = JSON.parse(e.data)
if (data.type === 'new-order') {
console.log('#### onmessage', data)
if (data.type === 'dm:0') {
this.$q.notify({
timeout: 5000,
type: 'positive',
message: 'New Order'
})
await this.$refs.directMessagesRef.handleNewMessage(data)
return
}
if (data.type === 'dm:1') {
await this.$refs.directMessagesRef.handleNewMessage(data)
await this.$refs.orderListRef.addOrder(data)
} else if (data.type === 'order-paid') {
return
}
if (data.type === 'dm:2') {
const orderStatus = JSON.parse(data.dm.message)
console.log('### orderStatus', orderStatus)
this.$q.notify({
timeout: 5000,
type: 'positive',
message: 'Order Paid'
message: orderStatus.message
})
await this.$refs.orderListRef.addOrder(data)
} else if (data.type === 'new-direct-message') {
if (orderStatus.paid) {
await this.$refs.orderListRef.orderPaid(orderStatus.id)
}
await this.$refs.directMessagesRef.handleNewMessage(data)
return
}
if (data.type === 'dm:-1') {
await this.$refs.directMessagesRef.handleNewMessage(data)
}
// order paid