From c1a0e721e6478873f3576fa48c00001a6147bff3 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 2 Mar 2023 14:18:48 +0200 Subject: [PATCH] feat: update and delete stall --- .../stall-details/stall-details.html | 42 ++++++------ .../components/stall-details/stall-details.js | 67 ++++++++++++++++--- 2 files changed, 80 insertions(+), 29 deletions(-) diff --git a/static/components/stall-details/stall-details.html b/static/components/stall-details/stall-details.html index 73a11d2..00b3b29 100644 --- a/static/components/stall-details/stall-details.html +++ b/static/components/stall-details/stall-details.html @@ -85,25 +85,25 @@
- +
+
+ Update Stall +
+
+ Delete Stall +
+
diff --git a/static/components/stall-details/stall-details.js b/static/components/stall-details/stall-details.js index 0caf1a3..86b09b3 100644 --- a/static/components/stall-details/stall-details.js +++ b/static/components/stall-details/stall-details.js @@ -27,6 +27,15 @@ async function stallDetails(path) { } }, methods: { + mapStall: function(stall) { + stall.shipping_zones.forEach( + z => + (z.label = z.name + ? `${z.name} (${z.countries.join(', ')})` + : z.countries.join(', ')) + ) + return stall + }, getStall: async function () { try { const {data} = await LNbits.api.request( @@ -34,18 +43,60 @@ async function stallDetails(path) { '/nostrmarket/api/v1/stall/' + this.stallId, this.inkey ) - this.stall = data - this.stall.shipping_zones.forEach( - z => - (z.label = z.name - ? `${z.name} (${z.countries.join(', ')})` - : z.countries.join(', ')) - ) + this.stall = this.mapStall(data) + console.log('### this.stall', this.stall) } catch (error) { LNbits.utils.notifyApiError(error) } - } + }, + updateRelay: async function () { + try { + const {data} = await LNbits.api.request( + 'PUT', + '/nostrmarket/api/v1/stall/' + this.stallId, + this.adminkey, + this.stall + ) + this.stall = this.mapStall(data) + this.$emit('stall-updated', this.stall) + this.$q.notify({ + type: 'positive', + message: 'Stall Updated', + timeout: 5000 + }) + } catch (error) { + console.warn(error) + LNbits.utils.notifyApiError(error) + } + }, + deleteRelay: function () { + LNbits.utils + .confirmDialog( + ` + Products and orders will be deleted also! + Are you sure you want to delete this relay? + ` + ) + .onOk(async () => { + try { + await LNbits.api.request( + 'DELETE', + '/nostrmarket/api/v1/stall/' + this.stallId, + this.adminkey + ) + this.$emit('stall-deleted', this.stallId) + this.$q.notify({ + type: 'positive', + message: 'Stall Deleted', + timeout: 5000 + }) + } catch (error) { + console.warn(error) + LNbits.utils.notifyApiError(error) + } + }) + }, }, created: async function () { await this.getStall()