From 4323040bd3a38885a8891a57e5592766117cd918 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 26 Jan 2026 22:21:11 +0700 Subject: [PATCH] feat: use TransferToLayingConfirmationModal and remove unnecessary code --- .../TransferToLayingsTable.tsx | 123 +++++++++--------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx index 63f30109..4cdb4a60 100644 --- a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx +++ b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx @@ -14,9 +14,7 @@ import { Icon } from '@iconify/react'; import Table from '@/components/Table'; import Button from '@/components/Button'; import { useModal } from '@/components/Modal'; -import ConfirmationModal from '@/components/modal/ConfirmationModal'; import CheckboxInput from '@/components/input/CheckboxInput'; -import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes'; import RequirePermission from '@/components/helper/RequirePermission'; import PopoverButton from '@/components/popover/PopoverButton'; import Badge from '@/components/Badge'; @@ -24,13 +22,14 @@ import PopoverContent from '@/components/popover/PopoverContent'; import Dropdown from '@/components/Dropdown'; import StatusBadge from '@/components/helper/StatusBadge'; import TransferToLayingFilterModal from '@/components/pages/production/transfer-to-laying/TransferToLayingFilterModal'; +import TransferToLayingConfirmationModal from '@/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal'; import { TransferToLaying, TransferToLayingFilter, } from '@/types/api/production/transfer-to-laying'; import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying'; -import { cn, formatDate } from '@/lib/helper'; +import { cn, formatDate, formatNumber } from '@/lib/helper'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; import { useTableFilter } from '@/services/hooks/useTableFilter'; import { Color } from '@/types/theme'; @@ -38,14 +37,11 @@ import { Color } from '@/types/theme'; const RowOptionsMenu = ({ props, popoverPosition = 'bottom', - approveClickHandler, - rejectClickHandler, + deleteClickHandler, }: { props: CellContext; popoverPosition: 'bottom' | 'top'; - approveClickHandler: () => void; - rejectClickHandler: () => void; deleteClickHandler: () => void; }) => { const showEditButton = @@ -54,9 +50,6 @@ const RowOptionsMenu = ({ const showDeleteButton = showEditButton; - // const showApproveButton = showEditButton; - // const showRejectButton = showEditButton; - const popoverId = `transferToLaying#${props.row.original.id}`; const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`; @@ -260,7 +253,14 @@ const TransferToLayingsTable = () => { { accessorKey: 'usage_qty', header: 'Kuantitas', - cell: (props) => props.getValue() ?? props.row.original.pending_usage_qty, + cell: (props) => { + const totalQuantity = props.row.original.targets.reduce( + (total, target) => total + target.qty, + 0 + ); + + return formatNumber(totalQuantity, 'en-US'); + }, }, { accessorKey: 'notes', @@ -304,38 +304,20 @@ const TransferToLayingsTable = () => { const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2; - const approveClickHandler = () => { - setSelectedTransferToLaying(props.row.original); - - // Set row selection - setRowSelection({ - [String(props.row.original.id)]: true, - }); - - approveModal.openModal(); - }; - - const rejectClickHandler = () => { - setSelectedTransferToLaying(props.row.original); - - // Set row selection - setRowSelection({ - [String(props.row.original.id)]: true, - }); - - rejectModal.openModal(); - }; - const deleteClickHandler = () => { setSelectedTransferToLaying(props.row.original); + + // Set row selection + setRowSelection({ + [String(props.row.original.id)]: true, + }); + deleteModal.openModal(); }; return ( @@ -377,6 +359,8 @@ const TransferToLayingsTable = () => { refreshTransferToLayings(); + setRowSelection({}); + setSelectedTransferToLaying(undefined); deleteModal.closeModal(); toast.success('Berhasil menghapus data transfer ke laying!'); setIsDeleteLoading(false); @@ -646,53 +630,70 @@ const TransferToLayingsTable = () => { onReset={filterResetHandler} /> - { + setRowSelection({}); + deleteModal.closeModal(); + }, }} /> - - - { + setRowSelection({}); + approveModal.closeModal(); + }, + }} + /> + + {/* Reject Modal */} + { + setRowSelection({}); + rejectModal.closeModal(); + }, }} primaryButton={{ - text: 'Reject', - color: 'error', isLoading: isRejectLoading, + color: 'error', onClick: confirmationModalRejectClickHandler, }} />