From d7d7869b0e58823e9c9428af7774588075dd1b3d Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 17 Mar 2023 10:51:20 +0200 Subject: [PATCH] feat: link order to DMs --- static/components/direct-messages/direct-messages.js | 11 ++++++----- static/components/order-list/order-list.html | 7 ++++++- static/components/order-list/order-list.js | 7 ++++--- static/components/shipping-zones/shipping-zones.js | 3 --- static/components/stall-details/stall-details.html | 1 + static/components/stall-details/stall-details.js | 7 +++---- static/components/stall-list/stall-list.html | 5 ++--- static/components/stall-list/stall-list.js | 3 +++ static/js/index.js | 4 ++++ templates/nostrmarket/index.html | 2 ++ views_api.py | 5 +---- 11 files changed, 32 insertions(+), 23 deletions(-) diff --git a/static/components/direct-messages/direct-messages.js b/static/components/direct-messages/direct-messages.js index a9c58ef..96112d9 100644 --- a/static/components/direct-messages/direct-messages.js +++ b/static/components/direct-messages/direct-messages.js @@ -2,13 +2,17 @@ async function directMessages(path) { const template = await loadTemplateAsync(path) Vue.component('direct-messages', { name: 'direct-messages', - props: ['adminkey', 'inkey'], + props: ['active-public-key', 'adminkey', 'inkey'], template, + watch: { + activePublicKey: async function (n) { + await this.getDirectMessages(n) + } + }, data: function () { return { customersPublicKeys: [], - activePublicKey: '', messages: [], newMessage: '' } @@ -44,7 +48,6 @@ async function directMessages(path) { this.inkey ) this.customersPublicKeys = data - console.log('### this.customersPublicKeys', this.customersPublicKeys) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -61,7 +64,6 @@ async function directMessages(path) { } ) this.messages = this.messages.concat([data]) - console.log('### this.messages', this.messages) this.newMessage = '' this.focusOnChatBox(this.messages.length - 1) } catch (error) { @@ -69,7 +71,6 @@ async function directMessages(path) { } }, selectActiveCustomer: async function () { - console.log('### selectActiveCustomer', this.activePublicKey) await this.getDirectMessages(this.activePublicKey) }, focusOnChatBox: function (index) { diff --git a/static/components/order-list/order-list.html b/static/components/order-list/order-list.html index cdac035..2f53051 100644 --- a/static/components/order-list/order-list.html +++ b/static/components/order-list/order-list.html @@ -44,7 +44,12 @@ - {{toShortId(props.row.public_key)}} + + {{toShortId(props.row.public_key)}} + {{formatDate(props.row.time)}} diff --git a/static/components/order-list/order-list.js b/static/components/order-list/order-list.js index 482cc8a..e325fa5 100644 --- a/static/components/order-list/order-list.js +++ b/static/components/order-list/order-list.js @@ -45,7 +45,7 @@ async function orderList(path) { field: 'shipped' }, { - name: 'pubkey', + name: 'public_key', align: 'left', label: 'Customer', field: 'pubkey' @@ -91,13 +91,11 @@ async function orderList(path) { this.inkey ) this.orders = data.map(s => ({...s, expanded: false})) - console.log('### this.orders', this.orders) } catch (error) { LNbits.utils.notifyApiError(error) } }, updateOrderShipped: async function () { - console.log('### order', this.selectedOrder) this.selectedOrder.shipped = !this.selectedOrder.shipped try { await LNbits.api.request( @@ -128,6 +126,9 @@ async function orderList(path) { // do not change the status yet this.selectedOrder.shipped = !order.shipped this.showShipDialog = true + }, + customerSelected: function (customerPubkey) { + this.$emit('customer-selected', customerPubkey) } }, created: async function () { diff --git a/static/components/shipping-zones/shipping-zones.js b/static/components/shipping-zones/shipping-zones.js index 71e3ae6..173d713 100644 --- a/static/components/shipping-zones/shipping-zones.js +++ b/static/components/shipping-zones/shipping-zones.js @@ -102,13 +102,11 @@ async function shippingZones(path) { this.inkey ) this.zones = data - console.log('### data', data) } catch (error) { LNbits.utils.notifyApiError(error) } }, sendZoneFormData: async function () { - console.log('### data', this.zoneDialog.data) this.zoneDialog.showDialog = false if (this.zoneDialog.data.id) { await this.updateShippingZone(this.zoneDialog.data) @@ -118,7 +116,6 @@ async function shippingZones(path) { await this.getZones() }, createShippingZone: async function (newZone) { - console.log('### newZone', newZone) try { await LNbits.api.request( 'POST', diff --git a/static/components/stall-details/stall-details.html b/static/components/stall-details/stall-details.html index 4239f68..9b5741d 100644 --- a/static/components/stall-details/stall-details.html +++ b/static/components/stall-details/stall-details.html @@ -190,6 +190,7 @@ :adminkey="adminkey" :inkey="inkey" :stall-id="stallId" + @customer-selected="customerSelectedForOrder" > diff --git a/static/components/stall-details/stall-details.js b/static/components/stall-details/stall-details.js index e687a67..d488e98 100644 --- a/static/components/stall-details/stall-details.js +++ b/static/components/stall-details/stall-details.js @@ -119,8 +119,6 @@ async function stallDetails(path) { this.inkey ) this.stall = this.mapStall(data) - - console.log('### this.stall', this.stall) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -197,8 +195,6 @@ async function stallDetails(path) { this.inkey ) this.products = data - - console.log('### this.products', this.products) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -305,6 +301,9 @@ async function stallDetails(path) { } } this.productDialog.showDialog = true + }, + customerSelectedForOrder: function (customerPubkey) { + this.$emit('customer-selected-for-order', customerPubkey) } }, created: async function () { diff --git a/static/components/stall-list/stall-list.html b/static/components/stall-list/stall-list.html index ea738bf..bd63551 100644 --- a/static/components/stall-list/stall-list.html +++ b/static/components/stall-list/stall-list.html @@ -46,9 +46,7 @@ - - {{props.row.name}} + {{props.row.name}} {{props.row.currency}} @@ -74,6 +72,7 @@ :currencies="currencies" @stall-deleted="handleStallDeleted" @stall-updated="handleStallUpdated" + @customer-selected-for-order="customerSelectedForOrder" > diff --git a/static/components/stall-list/stall-list.js b/static/components/stall-list/stall-list.js index d41c062..dca7fb9 100644 --- a/static/components/stall-list/stall-list.js +++ b/static/components/stall-list/stall-list.js @@ -170,6 +170,9 @@ async function stallList(path) { shippingZones: [] } this.stallDialog.show = true + }, + customerSelectedForOrder: function (customerPubkey) { + this.$emit('customer-selected-for-order', customerPubkey) } }, created: async function () { diff --git a/static/js/index.js b/static/js/index.js index d530977..75e6f01 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -20,6 +20,7 @@ const merchant = async () => { return { merchant: {}, shippingZones: [], + activeChatCustomer: '', showKeys: false, importKeyDialog: { show: false, @@ -92,6 +93,9 @@ const merchant = async () => { } catch (error) { LNbits.utils.notifyApiError(error) } + }, + customerSelectedForOrder: function (customerPubkey) { + this.activeChatCustomer = customerPubkey } }, created: async function () { diff --git a/templates/nostrmarket/index.html b/templates/nostrmarket/index.html index 32d0ca0..8907395 100644 --- a/templates/nostrmarket/index.html +++ b/templates/nostrmarket/index.html @@ -37,6 +37,7 @@ :adminkey="g.user.wallets[0].adminkey" :inkey="g.user.wallets[0].inkey" :wallet-options="g.user.walletOptions" + @customer-selected-for-order="customerSelectedForOrder" > @@ -114,6 +115,7 @@
diff --git a/views_api.py b/views_api.py index bc3a9e3..cefac0a 100644 --- a/views_api.py +++ b/views_api.py @@ -645,14 +645,11 @@ async def api_update_order_status( try: assert data.shipped != None, "Shipped value is required for order" merchant = await get_merchant_for_user(wallet.wallet.user) - assert merchant, "Merchant cannot be found" + assert merchant, "Merchant cannot be found for order {data.id}" order = await update_order_shipped_status(merchant.id, data.id, data.shipped) assert order, "Cannot find updated order" - merchant = await get_merchant_for_user(merchant.id) - assert merchant, f"Merchant cannot be found for order {data.id}" - data.paid = order.paid dm_content = json.dumps(data.dict(), separators=(",", ":"), ensure_ascii=False)