From 88513e744bd5eb413ed25e3e283f1f9fa72d0778 Mon Sep 17 00:00:00 2001 From: "kelvin.yau" Date: Fri, 6 Mar 2026 18:14:35 +0800 Subject: [PATCH] No longer refresh after QC --- src/components/PoDetail/PoInputGrid.tsx | 26 +++++++++++++------- src/components/Qc/QcStockInModal.tsx | 32 ++++++++++++++++++------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/components/PoDetail/PoInputGrid.tsx b/src/components/PoDetail/PoInputGrid.tsx index b9cb8d9..fb66411 100644 --- a/src/components/PoDetail/PoInputGrid.tsx +++ b/src/components/PoDetail/PoInputGrid.tsx @@ -285,15 +285,23 @@ function PoInputGrid({ const stockInLineId = searchParams.get("stockInLineId"); const poLineId = searchParams.get("poLineId"); -const closeNewModal = useCallback(() => { - const newParams = new URLSearchParams(searchParams.toString()); - newParams.delete("stockInLineId"); // Remove the parameter - router.replace(`${pathname}?${newParams.toString()}`); - fetchPoDetail(itemDetail.purchaseOrderId.toString()); - setNewOpen(false); // Close the modal first - // setTimeout(() => { - // }, 300); // Add a delay to avoid immediate re-trigger of useEffect - }, [searchParams, pathname, router]); + const closeNewModal = useCallback((updatedStockInLine?: StockInLine) => { + const newParams = new URLSearchParams(searchParams.toString()); + newParams.delete("stockInLineId"); + if (typeof window !== "undefined") { + window.history.replaceState({}, "", `${pathname}?${newParams.toString()}`); + } + setNewOpen(false); + + if (updatedStockInLine?.id != null) { + setEntries((prev) => + prev.map((e) => (e.id === updatedStockInLine.id ? { ...e, ...updatedStockInLine } : e)) + ); + setStockInLine((prev) => + (prev || []).map((p) => (p.id === updatedStockInLine.id ? { ...p, ...updatedStockInLine } : p)) + ); + } + }, [pathname, searchParams]); // Open modal const openNewModal = useCallback(() => { diff --git a/src/components/Qc/QcStockInModal.tsx b/src/components/Qc/QcStockInModal.tsx index ef3bb46..33d6247 100644 --- a/src/components/Qc/QcStockInModal.tsx +++ b/src/components/Qc/QcStockInModal.tsx @@ -55,13 +55,13 @@ const style = { width: { xs: "90%", sm: "90%", md: "90%" }, height: { xs: "90%", sm: "90%", md: "90%" }, }; -interface CommonProps extends Omit { +interface CommonProps extends Omit { // itemDetail: StockInLine & { qcResult?: PurchaseQcResult[] } & { escResult?: EscalationResult[] } | undefined; inputDetail: StockInLineInput | undefined; session: SessionWithTokens | null; warehouse?: any[]; printerCombo: PrinterCombo[]; - onClose: () => void; + onClose: (updatedStockInLine?: StockInLine) => void; skipQc?: Boolean; printSource?: "stockIn" | "productionProcess"; } @@ -229,7 +229,16 @@ const QcStockInModal: React.FC = ({ ...defaultNewValue, }, }); - + + const closeWithResult = useCallback( + (updatedStockInLine?: StockInLine) => { + setStockInLineInfo(undefined); + formProps.reset({}); + onClose?.(updatedStockInLine); + }, + [onClose], + ); + const closeHandler = useCallback>( () => { setStockInLineInfo(undefined); @@ -412,6 +421,9 @@ const QcStockInModal: React.FC = ({ // const qcData = data; console.log("QC Data for submission:", qcData); + + let qcRes: StockInLine | undefined; + if (data.qcDecision == 3) { // Escalate if (data.escalationLog?.handlerId == undefined) { alert("請選擇上報負責同事!"); return; } else if (data.escalationLog?.handlerId < 1) { alert("上報負責同事資料有誤"); return; } @@ -425,12 +437,14 @@ const QcStockInModal: React.FC = ({ } console.log("Escalation Data for submission", escalationLog); - setIsSubmitting(true); //TODO improve - await postStockInLine({...qcData, escalationLog}); + setIsSubmitting(true); + const resEscalate = await postStockInLine({...qcData, escalationLog}); + qcRes = Array.isArray(resEscalate.entity) ? resEscalate.entity[0] : (resEscalate.entity as StockInLine); } else { - setIsSubmitting(true); //TODO improve - await postStockInLine(qcData); + setIsSubmitting(true); + const resNormal = await postStockInLine(qcData); + qcRes = Array.isArray(resNormal.entity) ? resNormal.entity[0] : (resNormal.entity as StockInLine); } if (qcData.qcAccept) { @@ -485,10 +499,10 @@ const QcStockInModal: React.FC = ({ } } - closeHandler({}, "backdropClick"); + closeWithResult(qcRes); // setTabIndex(1); // Need to go Putaway tab? } else { - closeHandler({}, "backdropClick"); + closeWithResult(qcRes); } setIsSubmitting(false); msg("已更新來貨狀態");