mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
refactor(FE-208,212): enhance PurchaseOrderDetail and PurchaseOrderStaffApprovalForm to conditionally allow updates based on approval step
This commit is contained in:
@@ -39,7 +39,7 @@ const PurchaseOrderStaffApprovalForm = ({
|
|||||||
useState('');
|
useState('');
|
||||||
|
|
||||||
// ===== UTILITY FUNCTIONS =====
|
// ===== UTILITY FUNCTIONS =====
|
||||||
const canUpdatePurchase = useMemo(() => {
|
const canUpdatePurchaseItems = useMemo(() => {
|
||||||
if (!initialValues?.approval) return false;
|
if (!initialValues?.approval) return false;
|
||||||
|
|
||||||
const currentStep = initialValues.approval.step_number;
|
const currentStep = initialValues.approval.step_number;
|
||||||
@@ -125,7 +125,7 @@ const PurchaseOrderStaffApprovalForm = ({
|
|||||||
validateOnChange: true,
|
validateOnChange: true,
|
||||||
validateOnBlur: true,
|
validateOnBlur: true,
|
||||||
onSubmit: async (values) => {
|
onSubmit: async (values) => {
|
||||||
if (type === 'edit' && !canUpdatePurchase) {
|
if (type === 'edit' && !canUpdatePurchaseItems) {
|
||||||
setPurchaseOrderFormErrorMessage(
|
setPurchaseOrderFormErrorMessage(
|
||||||
'Tidak bisa diupdate. Harus melewati step 4 dahulu (Tahapan Penerimaan Produk).'
|
'Tidak bisa diupdate. Harus melewati step 4 dahulu (Tahapan Penerimaan Produk).'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -107,6 +107,13 @@ const PurchaseOrderDetail = ({
|
|||||||
return purchaseOrderItems.filter((item) => item.received_date);
|
return purchaseOrderItems.filter((item) => item.received_date);
|
||||||
}, [purchaseOrderItems]);
|
}, [purchaseOrderItems]);
|
||||||
|
|
||||||
|
const canUpdatePurchaseItems = useMemo(() => {
|
||||||
|
if (!initialValues?.approval) return false;
|
||||||
|
|
||||||
|
const currentStep = initialValues.approval.step_number;
|
||||||
|
return currentStep >= 4;
|
||||||
|
}, [initialValues?.approval]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
approvals,
|
approvals,
|
||||||
isLoading: approvalsLoading,
|
isLoading: approvalsLoading,
|
||||||
@@ -286,7 +293,7 @@ const PurchaseOrderDetail = ({
|
|||||||
cell: (props) => {
|
cell: (props) => {
|
||||||
const deleteClickHandler = () => {
|
const deleteClickHandler = () => {
|
||||||
setSelectedItem(props.row.original);
|
setSelectedItem(props.row.original);
|
||||||
setRowSelection({}); // Clear row selection when doing single delete
|
setRowSelection({});
|
||||||
deleteModal.openModal();
|
deleteModal.openModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -593,9 +600,11 @@ const PurchaseOrderDetail = ({
|
|||||||
<h3 className='text-lg font-semibold text-gray-800'>
|
<h3 className='text-lg font-semibold text-gray-800'>
|
||||||
Item Pembelian
|
Item Pembelian
|
||||||
</h3>
|
</h3>
|
||||||
<RowDropdownOptions isLast2Rows>
|
{canUpdatePurchaseItems && (
|
||||||
<ItemPembelianDropdown onEdit={editModal.openModal} />
|
<RowDropdownOptions isLast2Rows>
|
||||||
</RowDropdownOptions>
|
<ItemPembelianDropdown onEdit={editModal.openModal} />
|
||||||
|
</RowDropdownOptions>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='rounded-lg border border-gray-200 overflow-hidden'>
|
<div className='rounded-lg border border-gray-200 overflow-hidden'>
|
||||||
{/* Product Table */}
|
{/* Product Table */}
|
||||||
|
|||||||
Reference in New Issue
Block a user