mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE-208): update deletion logic in PurchaseOrderDetail to allow item deletion only at approval step 3
This commit is contained in:
@@ -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,27 +438,31 @@ 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',
|
? [
|
||||||
cell: (props) => {
|
{
|
||||||
const deleteClickHandler = () => {
|
header: 'Aksi',
|
||||||
setSelectedItem(props.row.original);
|
cell: (props: { row: Row<PurchaseItem> }) => {
|
||||||
setRowSelection({});
|
const deleteClickHandler = () => {
|
||||||
deleteModal.openModal();
|
setSelectedItem(props.row.original);
|
||||||
};
|
setRowSelection({});
|
||||||
|
deleteModal.openModal();
|
||||||
|
};
|
||||||
|
|
||||||
return canDeleteItems ? (
|
return (
|
||||||
<Button
|
<Button
|
||||||
type='button'
|
type='button'
|
||||||
color='error'
|
color='error'
|
||||||
className='text-sm'
|
className='text-sm'
|
||||||
onClick={deleteClickHandler}
|
onClick={deleteClickHandler}
|
||||||
>
|
>
|
||||||
<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>[] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user