From 876d564f267f33887f88914666b9b99c09419091 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Mon, 19 Jan 2026 14:06:04 +0700 Subject: [PATCH] fix: refactor confirmationModalDeleteClickHandler function --- .../TransferToLayingsTable.tsx | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx index 860c4616..727d49cd 100644 --- a/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx +++ b/src/components/pages/production/transfer-to-laying/TransferToLayingsTable.tsx @@ -31,7 +31,7 @@ import RequirePermission from '@/components/helper/RequirePermission'; import { TransferToLaying } from '@/types/api/production/transfer-to-laying'; import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying'; import { cn, formatDate } from '@/lib/helper'; -import { isResponseSuccess } from '@/lib/api-helper'; +import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; import { useTableFilter } from '@/services/hooks/useTableFilter'; import { ROWS_OPTIONS } from '@/config/constant'; import { Flock } from '@/types/api/master-data/flock'; @@ -397,17 +397,21 @@ const TransferToLayingsTable = () => { const confirmationModalDeleteClickHandler = async () => { setIsDeleteLoading(true); - try { - await TransferToLayingApi.delete(selectedTransferToLaying?.id as number); + const deleteResponse = await TransferToLayingApi.delete( + selectedTransferToLaying?.id as number + ); - toast.success('Berhasil menghapus data transfer ke laying!'); - refreshTransferToLayings(); - } catch (error) { - toast.success('Gagal menghapus data transfer ke laying!'); - } finally { - deleteModal.closeModal(); + if (isResponseError(deleteResponse)) { + toast.error(deleteResponse.message); setIsDeleteLoading(false); + return; } + + refreshTransferToLayings(); + + deleteModal.closeModal(); + toast.success('Berhasil menghapus data transfer ke laying!'); + setIsDeleteLoading(false); }; const confirmationModalApproveClickHandler = async (notes: string) => {