diff --git a/src/components/pages/purchase/form/order/PurchaseOrderForm.schema.ts b/src/components/pages/purchase/form/order/PurchaseOrderForm.schema.ts index e0a5b7e4..96836bc6 100644 --- a/src/components/pages/purchase/form/order/PurchaseOrderForm.schema.ts +++ b/src/components/pages/purchase/form/order/PurchaseOrderForm.schema.ts @@ -9,12 +9,12 @@ type PurchaseRequestStaffApprovalFormSchemaType = { product_id?: number | null; warehouse_id?: number | null; product?: { - value: number; - label: string; + value?: number; + label?: string; } | null; warehouse?: { - value: number; - label: string; + value?: number; + label?: string; } | null; qty: number; price: number | string; @@ -54,12 +54,12 @@ export type PurchaseStaffApprovalItemSchema = { product_id?: number | null; warehouse_id?: number | null; product?: { - value: number; - label: string; + value?: number; + label?: string; } | null; warehouse?: { - value: number; - label: string; + value?: number; + label?: string; } | null; qty: number; price: number | string; @@ -97,8 +97,8 @@ const PurchaseStaffApprovalItemObjectSchema: Yup.ObjectSchema= 3; }, [initialValues?.approval]); + const canShowDeleteAddButtons = useMemo(() => { + if (!initialValues?.approval) return false; + + const currentStep = initialValues.approval.step_number; + // Show delete/add buttons only up to step 3 + // Hide from step 4 onwards + return currentStep < 4; + }, [initialValues?.approval]); + const isRepeaterInputError = ( idx: number, field: 'price' | 'total_price' | 'product_id' | 'warehouse_id' @@ -344,6 +355,7 @@ const PurchaseOrderStaffApprovalForm = ({ notes: values.notes || null, items: updateItemsPayload, }; + await updateStaffApprovalHandler( initialValues?.id as number, updatePayload @@ -556,7 +568,7 @@ const PurchaseOrderStaffApprovalForm = ({ Total (Rp.) * - Action + {canShowDeleteAddButtons && Action} @@ -725,22 +737,23 @@ const PurchaseOrderStaffApprovalForm = ({
- {canUpdatePurchaseItems && ( - - )} + {canUpdatePurchaseItems && + canShowDeleteAddButtons && ( + + )}
@@ -757,7 +770,7 @@ const PurchaseOrderStaffApprovalForm = ({ handleProductChange(idx, val) } @@ -916,17 +929,19 @@ const PurchaseOrderStaffApprovalForm = ({ {/* Add Item Button */} -
- -
+ {canShowDeleteAddButtons && ( +
+ +
+ )} {/* Add divider after table except for last item */} {index < groupedPurchaseItems.length - 1 && (