feat: handle stall delete and update

This commit is contained in:
Vlad Stan 2023-03-02 14:37:07 +02:00
parent 5a526f86f1
commit f22e47e9ce
4 changed files with 22 additions and 12 deletions

View file

@ -91,7 +91,7 @@
unelevated unelevated
color="secondary" color="secondary"
class="float-left" class="float-left"
@click="updateRelay()" @click="updateStall()"
>Update Stall</q-btn >Update Stall</q-btn
> >
</div> </div>
@ -101,7 +101,7 @@
color="pink" color="pink"
icon="cancel" icon="cancel"
class="float-right" class="float-right"
@click="deleteRelay()" @click="deleteStall()"
>Delete Stall</q-btn >Delete Stall</q-btn
> >
</div> </div>

View file

@ -27,7 +27,7 @@ async function stallDetails(path) {
} }
}, },
methods: { methods: {
mapStall: function(stall) { mapStall: function (stall) {
stall.shipping_zones.forEach( stall.shipping_zones.forEach(
z => z =>
(z.label = z.name (z.label = z.name
@ -44,13 +44,13 @@ async function stallDetails(path) {
this.inkey this.inkey
) )
this.stall = this.mapStall(data) this.stall = this.mapStall(data)
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 () { updateStall: async function () {
try { try {
const {data} = await LNbits.api.request( const {data} = await LNbits.api.request(
'PUT', 'PUT',
@ -70,7 +70,7 @@ async function stallDetails(path) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
} }
}, },
deleteRelay: function () { deleteStall: function () {
LNbits.utils LNbits.utils
.confirmDialog( .confirmDialog(
` `
@ -96,7 +96,7 @@ async function stallDetails(path) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
} }
}) })
}, }
}, },
created: async function () { created: async function () {
await this.getStall() await this.getStall()

View file

@ -93,9 +93,9 @@
:wallet-options="walletOptions" :wallet-options="walletOptions"
:zone-options="zoneOptions" :zone-options="zoneOptions"
:currencies="currencies" :currencies="currencies"
@stall-deleted="handleStallDeleted"
@stall-updated="handleStallUpdated"
></stall-details> ></stall-details>
<!-- @stall-deleted="handleRelayDeleted"
@stall-updated="handleRelayUpdated" -->
</div> </div>
</div> </div>
</q-td> </q-td>

View file

@ -88,6 +88,7 @@ async function stallList(path) {
stall stall
) )
this.stallDialog.show = false this.stallDialog.show = false
this.stalls.unshift(data)
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
message: 'Stall created!' message: 'Stall created!'
@ -116,7 +117,6 @@ async function stallList(path) {
'/nostrmarket/api/v1/stall', '/nostrmarket/api/v1/stall',
this.inkey this.inkey
) )
console.log('### stalls', data)
this.stalls = data.map(s => ({...s, expanded: false})) this.stalls = data.map(s => ({...s, expanded: false}))
} catch (error) { } catch (error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
@ -129,18 +129,28 @@ async function stallList(path) {
'/nostrmarket/api/v1/zone', '/nostrmarket/api/v1/zone',
this.inkey this.inkey
) )
console.log('### zones', data)
this.zoneOptions = data.map(z => ({ this.zoneOptions = data.map(z => ({
...z, ...z,
label: z.name label: z.name
? `${z.name} (${z.countries.join(', ')})` ? `${z.name} (${z.countries.join(', ')})`
: z.countries.join(', ') : z.countries.join(', ')
})) }))
console.log('### this.zoneOptions', this.zoneOptions)
} catch (error) { } catch (error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
} }
}, },
handleStallDeleted: function (stallId) {
this.stalls = _.reject(this.stalls, function (obj) {
return obj.id === stallId
})
},
handleStallUpdated: function (stall) {
const index = this.stalls.findIndex(r => r.id === stall.id)
if (index !== -1) {
stall.expanded = true
this.stalls.splice(index, 1, stall)
}
},
openCreateStallDialog: async function () { openCreateStallDialog: async function () {
await this.getCurrencies() await this.getCurrencies()
await this.getZones() await this.getZones()