feat: dinamically refresh orders
This commit is contained in:
parent
4974192b21
commit
8d1998c33b
4 changed files with 40 additions and 12 deletions
|
|
@ -141,6 +141,18 @@ async function orderList(path) {
|
|||
LNbits.utils.notifyApiError(error)
|
||||
}
|
||||
},
|
||||
getOrder: async function (orderId) {
|
||||
try {
|
||||
const {data} = await LNbits.api.request(
|
||||
'GET',
|
||||
`/nostrmarket/api/v1/order/${orderId}`,
|
||||
this.inkey
|
||||
)
|
||||
return {...data, expanded: false}
|
||||
} catch (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
}
|
||||
},
|
||||
updateOrderShipped: async function () {
|
||||
this.selectedOrder.shipped = !this.selectedOrder.shipped
|
||||
try {
|
||||
|
|
@ -163,6 +175,16 @@ async function orderList(path) {
|
|||
}
|
||||
this.showShipDialog = false
|
||||
},
|
||||
addOrder: async function (data) {
|
||||
if (
|
||||
!this.search.publicKey ||
|
||||
this.search.publicKey === data.customerPubkey
|
||||
) {
|
||||
const order = await this.getOrder(data.orderId)
|
||||
this.orders.unshift(order)
|
||||
}
|
||||
},
|
||||
|
||||
showShipOrderDialog: function (order) {
|
||||
this.selectedOrder = order
|
||||
this.shippingMessage = order.shipped
|
||||
|
|
|
|||
|
|
@ -107,21 +107,26 @@ const merchant = async () => {
|
|||
filterOrdersForCustomer: function (customerPubkey) {
|
||||
this.orderPubkey = customerPubkey
|
||||
},
|
||||
waitForNotifications: function () {
|
||||
waitForNotifications: async function () {
|
||||
try {
|
||||
const scheme = location.protocol === 'http:' ? 'ws' : 'wss'
|
||||
const port = location.port ? `:${location.port}` : ''
|
||||
const wsUrl = `${scheme}://${document.domain}${port}/api/v1/ws/${this.merchant.id}`
|
||||
const wsConnection = new WebSocket(wsUrl)
|
||||
console.log('### waiting for events')
|
||||
wsConnection.onmessage = e => {
|
||||
wsConnection.onmessage = async e => {
|
||||
console.log('### e', e)
|
||||
const data = JSON.parse(e.data)
|
||||
if (data.type === 'new-order') {
|
||||
this.$q.notify({
|
||||
timeout: 5000,
|
||||
type: 'positive',
|
||||
message: 'New Update',
|
||||
caption: `something here`
|
||||
message: 'New Order'
|
||||
})
|
||||
await this.$refs.orderListRef.addOrder(data)
|
||||
} else if (data.type === 'new-customer') {
|
||||
} else if (data.type === 'new-direct-message') {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.$q.notify({
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@
|
|||
<div class="row">
|
||||
<div class="col-12">
|
||||
<order-list
|
||||
ref="orderListRef"
|
||||
:adminkey="g.user.wallets[0].adminkey"
|
||||
:inkey="g.user.wallets[0].inkey"
|
||||
:customer-pubkey-filter="orderPubkey"
|
||||
|
|
|
|||
|
|
@ -647,10 +647,10 @@ async def api_delete_product(
|
|||
######################################## ORDERS ########################################
|
||||
|
||||
|
||||
nostrmarket_ext.get("/api/v1/order/{order_id}")
|
||||
|
||||
|
||||
async def api_get_order(order_id: str, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
@nostrmarket_ext.get("/api/v1/order/{order_id}")
|
||||
async def api_get_order(
|
||||
order_id: str, wallet: WalletTypeInfo = Depends(require_invoice_key)
|
||||
):
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue