From 245b86e463b86a84e06622bf173562b15b6be8be Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Fri, 17 Jul 2026 21:53:33 +0800 Subject: [PATCH] inventory search update --- src/app/api/inventory/actions.ts | 16 ++++++++++++++++ .../InventorySearch/InventorySearch.tsx | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app/api/inventory/actions.ts b/src/app/api/inventory/actions.ts index 0f10e48..417c1b3 100644 --- a/src/app/api/inventory/actions.ts +++ b/src/app/api/inventory/actions.ts @@ -160,13 +160,29 @@ async function fetchInventoriesImpl(data: SearchInventory) { ); } +async function fetchInventoriesLatestImpl(data: SearchInventory) { + const queryStr = convertObjToURLSearchParams(data); + return serverFetchJson( + `${BASE_API_URL}/inventory/searchLatest/getRecordByPage?${queryStr}`, + { next: { tags: ["inventories"] } }, + ); +} + export const fetchInventories = cache(fetchInventoriesImpl); +/** Inventory search page: latest inventory row per item (no baseUnit/uomId filter). */ +export const fetchInventoriesLatest = cache(fetchInventoriesLatestImpl); + /** Bypass React cache() after mutations so lists show fresh qty. */ export async function fetchInventoriesFresh(data: SearchInventory) { return fetchInventoriesImpl(data); } +/** Bypass React cache() for inventory search page latest-inventory search. */ +export async function fetchInventoriesLatestFresh(data: SearchInventory) { + return fetchInventoriesLatestImpl(data); +} + async function fetchInventoryLotLinesImpl(data: SearchInventoryLotLine) { const queryStr = convertObjToURLSearchParams(data); return serverFetchJson( diff --git a/src/components/InventorySearch/InventorySearch.tsx b/src/components/InventorySearch/InventorySearch.tsx index 33becd7..8909955 100644 --- a/src/components/InventorySearch/InventorySearch.tsx +++ b/src/components/InventorySearch/InventorySearch.tsx @@ -12,7 +12,7 @@ import { analyzeQrCode, SearchInventory, SearchInventoryLotLine, - fetchInventories, + fetchInventoriesLatest, fetchInventoryLotLines, } from '@/app/api/inventory/actions'; import { PrinterCombo } from '@/app/api/settings/printer'; @@ -187,7 +187,7 @@ const InventorySearch: React.FC = ({ inventories, printerCombo }) => { pageSize: pagingController.pageSize, }; - const response = await fetchInventories(params); + const response = await fetchInventoriesLatest(params); if (response) { setInventoriesTotalCount(response.total); @@ -199,7 +199,7 @@ const InventorySearch: React.FC = ({ inventories, printerCombo }) => { break; case 'paging': setFilteredInventories((fi) => - uniqBy([...fi, ...response.records], 'id'), + uniqBy([...fi, ...response.records], 'itemId'), ); } }