refactor(FE-208): update deletion logic in PurchaseOrderDetail to allow item deletion only at approval step 3

This commit is contained in:
rstubryan
2025-11-21 20:30:06 +07:00
parent 1a74a9d33f
commit ffea96edf9
@@ -1,7 +1,12 @@
'use client'; 'use client';
import { useCallback, useMemo, useState } from 'react'; import { useCallback, useMemo, useState } from 'react';
import { ColumnDef, SortingState, Row, Table as TableType } from '@tanstack/react-table'; import {
ColumnDef,
SortingState,
Row,
Table as TableType,
} from '@tanstack/react-table';
import ApprovalSteps, { import ApprovalSteps, {
useApprovalSteps, useApprovalSteps,
@@ -160,7 +165,7 @@ const PurchaseOrderDetail = ({
const canDeleteItems = useMemo(() => { const canDeleteItems = useMemo(() => {
if (!initialValues?.approval) return false; if (!initialValues?.approval) return false;
return initialValues.approval.step_number >= 3; return initialValues.approval.step_number === 3;
}, [initialValues?.approval]); }, [initialValues?.approval]);
const handleApprovalClick = () => { const handleApprovalClick = () => {
@@ -342,7 +347,13 @@ const PurchaseOrderDetail = ({
} finally { } finally {
setIsDeleteLoading(false); setIsDeleteLoading(false);
} }
}, [initialValues?.id, searchParams, selectedItem, selectedRowIds, refetchData]); }, [
initialValues?.id,
searchParams,
selectedItem,
selectedRowIds,
refetchData,
]);
if (!initialValues) { if (!initialValues) {
return null; return null;
@@ -427,16 +438,18 @@ const PurchaseOrderDetail = ({
header: 'Total (Rp.)', header: 'Total (Rp.)',
cell: (props) => formatCurrency(props.getValue() as number), cell: (props) => formatCurrency(props.getValue() as number),
}, },
...(canDeleteItems
? [
{ {
header: 'Aksi', header: 'Aksi',
cell: (props) => { cell: (props: { row: Row<PurchaseItem> }) => {
const deleteClickHandler = () => { const deleteClickHandler = () => {
setSelectedItem(props.row.original); setSelectedItem(props.row.original);
setRowSelection({}); setRowSelection({});
deleteModal.openModal(); deleteModal.openModal();
}; };
return canDeleteItems ? ( return (
<Button <Button
type='button' type='button'
color='error' color='error'
@@ -445,9 +458,11 @@ const PurchaseOrderDetail = ({
> >
<Icon icon='mdi:trash-can' width={16} height={16} /> <Icon icon='mdi:trash-can' width={16} height={16} />
</Button> </Button>
) : null; );
}, },
}, },
]
: []),
]; ];
const goodsReceiptColumns: ColumnDef<PurchaseItem>[] = [ const goodsReceiptColumns: ColumnDef<PurchaseItem>[] = [