This commit is contained in:
@@ -13,3 +13,14 @@ export const ProviderMappingWorkflow = {
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const BulkArchiveSelection = {
|
||||
parameters: {
|
||||
docs: {
|
||||
description: {
|
||||
story:
|
||||
"The physical inventory section supports selecting active copies and archiving them in one authenticated operation.",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ import AdminListingStatus from "@/components/molecules/AdminListingStatus.vue";
|
||||
import {
|
||||
createAdminInventory,
|
||||
createAdminProduct,
|
||||
archiveAdminInventory,
|
||||
listAdminCategories,
|
||||
listAdminConditions,
|
||||
listAdminInventory,
|
||||
@@ -47,6 +48,7 @@ import {
|
||||
const { principal } = useAuth();
|
||||
const products = ref([]);
|
||||
const inventory = ref([]);
|
||||
const selectedInventoryIds = ref([]);
|
||||
const listings = ref([]);
|
||||
const sales = ref([]);
|
||||
const acquisitions = ref([]);
|
||||
@@ -193,6 +195,24 @@ async function createInventory() {
|
||||
}
|
||||
}
|
||||
|
||||
async function archiveSelectedInventory() {
|
||||
if (!selectedInventoryIds.value.length) return;
|
||||
isSaving.value = true;
|
||||
try {
|
||||
const archivedItems = await archiveAdminInventory(
|
||||
selectedInventoryIds.value,
|
||||
csrfToken(),
|
||||
);
|
||||
const archivedById = new Map(archivedItems.map((item) => [item.id, item]));
|
||||
inventory.value = inventory.value.map((item) => archivedById.get(item.id) ?? item);
|
||||
selectedInventoryIds.value = [];
|
||||
} catch (requestError) {
|
||||
error.value = requestError;
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createListing() {
|
||||
const item = inventory.value.find(
|
||||
(candidate) => candidate.id === listingInventoryId.value,
|
||||
@@ -927,6 +947,16 @@ onMounted(load);
|
||||
aria-labelledby="inventory-title"
|
||||
>
|
||||
<h2 id="inventory-title">Physical inventory</h2>
|
||||
<div class="admin-list__actions">
|
||||
<button
|
||||
class="button button--secondary"
|
||||
type="button"
|
||||
:disabled="isSaving || !selectedInventoryIds.length"
|
||||
@click="archiveSelectedInventory"
|
||||
>
|
||||
Archive selected
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="!inventory.length && !isLoading" class="state state--empty">
|
||||
No physical copies yet.
|
||||
</p>
|
||||
@@ -936,7 +966,17 @@ onMounted(load);
|
||||
:key="item.id"
|
||||
:data-product-id="item.productId"
|
||||
>
|
||||
<span>{{ item.id }}</span> · {{ item.status }}
|
||||
<label v-if="item.status === 'ACTIVE'">
|
||||
<input
|
||||
v-model="selectedInventoryIds"
|
||||
type="checkbox"
|
||||
:value="item.id"
|
||||
:aria-label="`Select inventory item ${item.id}`"
|
||||
/>
|
||||
<span>{{ item.id }}</span>
|
||||
</label>
|
||||
<span v-else>{{ item.id }}</span>
|
||||
· {{ item.status }}
|
||||
<RouterLink
|
||||
:to="{ name: 'admin-image-manager', params: { id: item.id } }"
|
||||
>Manage images</RouterLink
|
||||
|
||||
@@ -22,4 +22,12 @@ export function createAdminProduct(input, csrfToken) {
|
||||
|
||||
export function createAdminInventory(input, csrfToken) {
|
||||
return request('/admin/inventory', { method: 'POST', headers: { 'x-csrf-token': csrfToken }, body: JSON.stringify(input) });
|
||||
}
|
||||
|
||||
export function archiveAdminInventory(inventoryItemIds, csrfToken) {
|
||||
return request('/admin/bulk', {
|
||||
method: 'POST',
|
||||
headers: { 'x-csrf-token': csrfToken },
|
||||
body: JSON.stringify({ action: 'ARCHIVE', inventoryItemIds }),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user