diff --git a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx index 02bf443d..5324db03 100644 --- a/src/components/pages/purchase/order/PurchaseOrderDetail.tsx +++ b/src/components/pages/purchase/order/PurchaseOrderDetail.tsx @@ -413,6 +413,56 @@ const PurchaseOrderDetail = ({ refetchData, ]); + // ===== APPROVAL/REJECTION HANDLERS ===== + const managerApprovalHandler = async (notes: string) => { + const payload: CreateManagerApprovalRequestPayload = { + action: 'APPROVED', + notes: notes || null, + }; + + await createManagerApprovalHandler(payload); + await refreshApprovals(); + await refetchData?.(); + setApprovalNotes(''); + confirmationModalWithNotes.closeModal(); + }; + + const staffRejectionHandler = async (notes: string) => { + const payload: CreateStaffApprovalRequestPayload = { + action: 'REJECTED', + notes: notes || null, + }; + + await createStaffApprovalHandler(payload); + await refetchData?.(); + setApprovalNotes(''); + staffRejectionModal.closeModal(); + }; + + const acceptRejectionHandler = async (notes: string) => { + const payload: CreateAcceptApprovalRequestPayload = { + action: 'REJECTED', + notes: notes || null, + }; + + await createAcceptApprovalHandler(payload); + await refetchData?.(); + setApprovalNotes(''); + acceptRejectionModal.closeModal(); + }; + + const managerRejectionHandler = async (notes: string) => { + const payload: CreateManagerApprovalRequestPayload = { + action: 'REJECTED', + notes: notes || null, + }; + + await createManagerApprovalHandler(payload); + await refetchData?.(); + setApprovalNotes(''); + managerRejectionModal.closeModal(); + }; + if (!initialValues) { return null; } @@ -976,18 +1026,7 @@ const PurchaseOrderDetail = ({ primaryButton={{ text: 'Ya, Lanjutkan', color: 'success', - onClick: async (notes) => { - const payload: CreateManagerApprovalRequestPayload = { - action: 'APPROVED', - notes: notes || null, - }; - - await createManagerApprovalHandler(payload); - await refreshApprovals(); - await refetchData?.(); - setApprovalNotes(''); - confirmationModalWithNotes.closeModal(); - }, + onClick: managerApprovalHandler, }} secondaryButton={{ text: 'Batal', @@ -1083,17 +1122,7 @@ const PurchaseOrderDetail = ({ primaryButton={{ text: 'Ya, Tolak', color: 'error', - onClick: async (notes) => { - const payload: CreateStaffApprovalRequestPayload = { - action: 'REJECTED', - notes: notes || null, - }; - - await createStaffApprovalHandler(payload); - await refetchData?.(); - setApprovalNotes(''); - staffRejectionModal.closeModal(); - }, + onClick: staffRejectionHandler, }} secondaryButton={{ text: 'Batal', @@ -1115,17 +1144,7 @@ const PurchaseOrderDetail = ({ primaryButton={{ text: 'Ya, Tolak', color: 'error', - onClick: async (notes) => { - const payload: CreateAcceptApprovalRequestPayload = { - action: 'REJECTED', - notes: notes || null, - }; - - await createAcceptApprovalHandler(payload); - await refetchData?.(); - setApprovalNotes(''); - acceptRejectionModal.closeModal(); - }, + onClick: acceptRejectionHandler, }} secondaryButton={{ text: 'Batal', @@ -1147,17 +1166,7 @@ const PurchaseOrderDetail = ({ primaryButton={{ text: 'Ya, Tolak', color: 'error', - onClick: async (notes) => { - const payload: CreateManagerApprovalRequestPayload = { - action: 'REJECTED', - notes: notes || null, - }; - - await createManagerApprovalHandler(payload); - await refetchData?.(); - setApprovalNotes(''); - managerRejectionModal.closeModal(); - }, + onClick: managerRejectionHandler, }} secondaryButton={{ text: 'Batal',