From 7366d6490cbb831aa9ce2b75b0a9a31a49d24862 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Sun, 8 Mar 2026 16:34:59 +0700 Subject: [PATCH] refactor(FE): Validate transferToLayingId before fetching data --- .../TransferToLayingConfirmationModal.tsx | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx index 2975a865..555c1667 100644 --- a/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx +++ b/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx @@ -50,12 +50,18 @@ const TransferToLayingConfirmationModalTable = ({ transferToLayingForm?: TransferToLayingFormValues; transferToLayingId?: number; }) => { + const isValidId = + transferToLayingId !== undefined && + transferToLayingId !== null && + !isNaN(transferToLayingId) && + transferToLayingId > 0; + const { data: transferToLaying, isLoading: isLoadingTransferToLaying } = useSWR( - transferToLayingId + isValidId ? ['detail-transfer-to-laying', String(transferToLayingId)] : undefined, - ([id]) => TransferToLayingApi.getSingle(Number(id)) + ([, id]) => TransferToLayingApi.getSingle(Number(id)) ); const confirmationTableColumns: ColumnDef[] = @@ -273,12 +279,16 @@ const TransferToLayingConfirmationModal = ({ {transferToLayingIds && !transferToLayingForm && - transferToLayingIds.map((transferToLayingId, idx) => ( - - ))} + transferToLayingIds + .filter( + (id) => id !== undefined && id !== null && !isNaN(id) && id > 0 + ) + .map((transferToLayingId, idx) => ( + + ))} {withNote && (