feat: easily increment quantity (#473)

* fix vue version issue

* new patch API endpoint

* doc-gen

* new API class method for patch operations

* add quantity patch UI support

* fix typegen errors

* fix ts errors
This commit is contained in:
Hayden 2023-06-02 14:56:40 -07:00 committed by GitHub
parent 4dd036abb2
commit ef1531e561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 353 additions and 163 deletions

View file

@ -39,6 +39,30 @@
lastRoute.value = route.fullPath;
});
async function adjustQuantity(amount: number) {
if (!item.value) {
return;
}
const newQuantity = item.value.quantity + amount;
if (newQuantity < 0) {
toast.error("Quantity cannot be negative");
return;
}
const resp = await api.items.patch(item.value.id, {
id: item.value.id,
quantity: newQuantity,
});
if (resp.error) {
toast.error("Failed to adjust quantity");
return;
}
item.value.quantity = newQuantity;
}
type FilteredAttachments = {
attachments: ItemAttachment[];
warranty: ItemAttachment[];
@ -130,6 +154,7 @@
{
name: "Quantity",
text: item.value?.quantity,
slot: "quantity",
},
{
name: "Serial Number",
@ -475,7 +500,21 @@
<PageQRCode />
</div>
</template>
<DetailsSection :details="itemDetails" />
<DetailsSection :details="itemDetails">
<template #quantity="{ detail }">
{{ detail.text }}
<span
class="opacity-0 group-hover:opacity-100 ml-4 my-0 duration-75 transition-opacity inline-flex gap-2"
>
<button class="btn btn-circle btn-xs" @click="adjustQuantity(-1)">
<Icon name="mdi-minus" class="h-3 w-3" />
</button>
<button class="btn btn-circle btn-xs" @click="adjustQuantity(1)">
<Icon name="mdi-plus" class="h-3 w-3" />
</button>
</span>
</template>
</DetailsSection>
</BaseCard>
<NuxtPage :item="item" :page-key="itemId" />