feat: update and delete stall

This commit is contained in:
Vlad Stan 2023-03-02 14:18:48 +02:00
parent 6d8488d2c3
commit c1a0e721e6
2 changed files with 80 additions and 29 deletions

View file

@ -85,25 +85,25 @@
<div v-if="stall"></div> <div v-if="stall"></div>
</q-tab-panel> </q-tab-panel>
</q-tab-panels> </q-tab-panels>
<!-- <div class="row items-center q-mt-md q-mb-lg"> <div class="row items-center q-mt-md q-mb-lg">
<div class="col-6 q-pr-lg"> <div class="col-6 q-pr-lg">
<q-btn <q-btn
unelevated unelevated
color="secondary" color="secondary"
class="float-left" class="float-left"
@click="updateRelay()" @click="updateRelay()"
>Update Relay</q-btn >Update Stall</q-btn
> >
</div> </div>
<div class="col-6"> <div class="col-6">
<q-btn <q-btn
unelevated unelevated
color="pink" color="pink"
icon="cancel" icon="cancel"
class="float-right" class="float-right"
@click="deleteRelay()" @click="deleteRelay()"
>Delete Relay</q-btn >Delete Stall</q-btn
> >
</div> </div>
</div> --> </div>
</div> </div>

View file

@ -27,6 +27,15 @@ async function stallDetails(path) {
} }
}, },
methods: { 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 () { getStall: async function () {
try { try {
const {data} = await LNbits.api.request( const {data} = await LNbits.api.request(
@ -34,18 +43,60 @@ async function stallDetails(path) {
'/nostrmarket/api/v1/stall/' + this.stallId, '/nostrmarket/api/v1/stall/' + this.stallId,
this.inkey this.inkey
) )
this.stall = data this.stall = this.mapStall(data)
this.stall.shipping_zones.forEach(
z =>
(z.label = z.name
? `${z.name} (${z.countries.join(', ')})`
: z.countries.join(', '))
)
console.log('### this.stall', this.stall) console.log('### this.stall', this.stall)
} catch (error) { } catch (error) {
LNbits.utils.notifyApiError(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 () { created: async function () {
await this.getStall() await this.getStall()