mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-212): enhance approval step logic in PurchaseOrderStaffApprovalForm for better item management
This commit is contained in:
@@ -891,7 +891,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
toast.error(
|
||||
`Tidak bisa memilih gudang yang sama. Gudang asal tidak boleh sama dengan ${destinationWarehouseName}.`
|
||||
);
|
||||
return; // Prevent setting the value
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,14 +60,23 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
return 'add';
|
||||
}
|
||||
|
||||
const firstApproval = rawDataApprovals[0];
|
||||
const hasOnlyInitialStep =
|
||||
rawDataApprovals.length === 1 &&
|
||||
firstApproval?.step_number === 1 &&
|
||||
('action' in firstApproval ? firstApproval.action === 'CREATED' : false);
|
||||
const currentStep = initialValues?.approval?.step_number || 1;
|
||||
|
||||
return hasOnlyInitialStep ? 'add' : 'edit';
|
||||
}, [rawDataApprovals, propType]);
|
||||
switch (currentStep) {
|
||||
case 1:
|
||||
// Step 1 (Pengajuan) - Ini dari @PurchaseRequestForm
|
||||
return 'add';
|
||||
case 2:
|
||||
// Step 2 (Staff Purchase) - Staff approval pertama kali
|
||||
return 'add';
|
||||
case 3:
|
||||
// Step 3 (Manager Purchase) - Manager approval, boleh edit/delete/add items
|
||||
return 'edit';
|
||||
default:
|
||||
// Step 4+ (Penerimaan Barang dan selesai), tidak boleh edit kalau sudah disetujui
|
||||
return 'edit';
|
||||
}
|
||||
}, [rawDataApprovals, propType, initialValues?.approval?.step_number]);
|
||||
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
@@ -93,8 +102,16 @@ const PurchaseOrderStaffApprovalForm = ({
|
||||
if (!initialValues?.approval) return false;
|
||||
|
||||
const currentStep = initialValues.approval.step_number;
|
||||
return currentStep < 4;
|
||||
}, [initialValues?.approval]);
|
||||
|
||||
// Step 2 (Staff Purchase) dengan mode 'add' tidak boleh add/delete items
|
||||
// User hanya boleh input harga dan total harga untuk items yang sudah ada
|
||||
if (currentStep === 2 && type === 'add') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3 (Manager Purchase) boleh add/delete items
|
||||
return currentStep === 3;
|
||||
}, [initialValues?.approval, type]);
|
||||
|
||||
const isRepeaterInputError = (
|
||||
idx: number,
|
||||
|
||||
Reference in New Issue
Block a user