From 0479cb92ad7eed989d0398088fe7316f3a34939f Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Thu, 18 Sep 2025 17:17:34 +0800 Subject: [PATCH] update --- src/app/api/pickOrder/actions.ts | 44 +++++++++++++------ .../FinishedGoodSearch/FinishedGoodSearch.tsx | 23 ++++++++-- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/app/api/pickOrder/actions.ts b/src/app/api/pickOrder/actions.ts index a97835b..2cd18f7 100644 --- a/src/app/api/pickOrder/actions.ts +++ b/src/app/api/pickOrder/actions.ts @@ -201,20 +201,15 @@ export interface PickExecutionIssueData { pickerName: string; handledBy?: number; } -export interface AutoAssignReleaseResponse { +export type AutoAssignReleaseResponse = { id: number | null; - name: string; - code: string; - type?: string; - message: string | null; - errorPosition: string; - entity?: { - consoCode?: string; - pickOrderIds?: number[]; - hasActiveOrders: boolean; - }; -} - + name?: string | null; + code?: string | null; + type?: string | null; + message?: string | null; + errorPosition?: string | null; + entity?: any; +}; export interface PickOrderCompletionResponse { id: number | null; name: string; @@ -266,6 +261,11 @@ export interface FGPickOrderResponse { truckNo: string; qrCodeData: number; } +export interface AutoAssignReleaseByStoreRequest { + userId: number; + storeId: string; // "2/F" | "4/F" +} + export const fetchFGPickOrders = async (pickOrderId: number) => { const response = await serverFetchJson( `${BASE_API_URL}/pickOrder/fg-pick-orders/${pickOrderId}`, @@ -298,7 +298,23 @@ export const autoAssignAndReleasePickOrder = async (userId: number): Promise => { + const payload: AutoAssignReleaseByStoreRequest = { userId, storeId }; + const response = await serverFetchJson( + `${BASE_API_URL}/pickOrder/auto-assign-release-by-store`, + { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(payload), + next: { tags: ["pickorder"] }, + } + ); + revalidateTag("pickorder"); + return response; +}; export const checkPickOrderCompletion = async (userId: number): Promise => { const response = await serverFetchJson( `${BASE_API_URL}/pickOrder/check-pick-completion/${userId}`, diff --git a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx index b4df7bc..3c065f5 100644 --- a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx +++ b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx @@ -24,7 +24,7 @@ import NewCreateItem from "./newcreatitem"; import AssignAndRelease from "./AssignAndRelease"; import AssignTo from "./assignTo"; import { fetchAllItemsInClient, ItemCombo } from "@/app/api/settings/item/actions"; -import { fetchPickOrderClient, autoAssignAndReleasePickOrder } from "@/app/api/pickOrder/actions"; +import { fetchPickOrderClient, autoAssignAndReleasePickOrder, autoAssignAndReleasePickOrderByStore } from "@/app/api/pickOrder/actions"; import Jobcreatitem from "./Jobcreatitem"; import { useSession } from "next-auth/react"; import { SessionWithTokens } from "@/config/authConfig"; @@ -52,7 +52,15 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => { const [tabIndex, setTabIndex] = useState(0); const [totalCount, setTotalCount] = useState(); const [isAssigning, setIsAssigning] = useState(false); - + const handleAssignByStore = async (storeId: "2/F" | "4/F") => { + if (!currentUserId) { + console.error("Missing user id in session"); + return; + } + const res = await autoAssignAndReleasePickOrderByStore(currentUserId, storeId); + console.log("Assign by store result:", res); + // Optionally show toast/refresh list here + }; // ✅ Manual assignment handler - uses the action function const handleManualAssign = useCallback(async () => { if (!currentUserId || isAssigning) return; @@ -286,10 +294,17 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => { +