From e3274a3353f158d53dd6fd1cd435a6d1e4170b9e Mon Sep 17 00:00:00 2001 From: rstubryan Date: Wed, 19 Nov 2025 11:37:32 +0700 Subject: [PATCH] refactor(FE-208,212): streamline approval button handling in PurchaseOrderDetail --- .../purchase/order/PurchaseOrderDetail.tsx | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx index a65fc054..c266df9c 100644 --- a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx +++ b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx @@ -149,13 +149,38 @@ const PurchaseOrderDetail = ({ }); }, [goodsReceiptItems]); - const canUpdatePurchaseItems = useMemo(() => { + const approvalStep = useMemo(() => { + if (!initialValues?.approval) return null; + return initialValues.approval.step_number; + }, [initialValues?.approval]); + + const showApprovalButton = + approvalStep !== null && approvalStep >= 1 && approvalStep <= 3; + + const handleApprovalClick = () => { + if (!approvalStep) return; + + switch (approvalStep) { + case 1: + staffApprovalModal.openModal(); + break; + case 2: + confirmationModalWithNotes.openModal(); + break; + case 3: + acceptApprovalModal.openModal(); + break; + default: + break; + } + }; + + useMemo(() => { if (!initialValues?.approval) return false; const currentStep = initialValues.approval.step_number; return currentStep >= 4; }, [initialValues?.approval]); - const canShowPurchaseOrderInvoice = useMemo(() => { if (!initialValues?.approval) return false; @@ -498,39 +523,17 @@ const PurchaseOrderDetail = ({
{/* Approval and Action Buttons */}
- - - - - + {showApprovalButton && ( + + )}
{/* Steps */} @@ -779,9 +782,7 @@ const PurchaseOrderDetail = ({
{groupedGoodsReceiptItems.map((productData, index) => (
-
+
{/* Product Header */}
{productData.productIndex}.{' '}