From 309958814172e8cd62bc15aae2d3c63c38a38f4c Mon Sep 17 00:00:00 2001 From: rstubryan Date: Thu, 26 Feb 2026 16:10:19 +0700 Subject: [PATCH] refactor(FE): Filter transaction subtypes based on selected product flags --- .../form/InventoryAdjustmentForm.tsx | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx b/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx index 7889bafe..19738b00 100644 --- a/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx +++ b/src/components/pages/inventory/adjustment/form/InventoryAdjustmentForm.tsx @@ -206,10 +206,19 @@ const InventoryAdjustmentForm = ({ value: pw.product.id, label: pw.product.name, quantity: pw.quantity, + flags: pw.product.flags, })) : []; }, [productWarehouses]); + const selectedProductFlags = useMemo(() => { + if (!selectedProduct) return []; + const product = productOptions.find( + (opt) => opt.value === selectedProduct.value + ); + return (product?.flags as string[]) || []; + }, [selectedProduct, productOptions]); + const ProductOption = useMemo(() => { const OptionComponent = ( props: OptionProps @@ -305,11 +314,43 @@ const InventoryAdjustmentForm = ({ const transactionType = selectedTransactionType?.value; if (transactionType === 'RECORDING') { - return [...TRANSACTION_SUBTYPE_OPTIONS.RECORDING]; + const allRecordingOptions = [...TRANSACTION_SUBTYPE_OPTIONS.RECORDING]; + + if (selectedProductFlags.length > 0) { + const isEggProduct = selectedProductFlags.some((flag) => + flag.startsWith('TELUR') + ); + const isChickenProduct = selectedProductFlags.some( + (flag) => + flag.startsWith('AYAM') || + flag === 'DOC' || + flag === 'PULLET' || + flag === 'LAYER' + ); + + if (isEggProduct) { + // Produk telur: hanya RECORDING_EGG_IN + return allRecordingOptions.filter( + (opt) => opt.value === 'RECORDING_EGG_IN' + ); + } else if (isChickenProduct) { + // Produk ayam: hanya RECORDING_DEPLETION_OUT + return allRecordingOptions.filter( + (opt) => opt.value === 'RECORDING_DEPLETION_OUT' + ); + } else { + // Produk non-telur dan non-ayam (PAKAN, OVK, dll): hanya RECORDING_STOCK_OUT + return allRecordingOptions.filter( + (opt) => opt.value === 'RECORDING_STOCK_OUT' + ); + } + } + + return allRecordingOptions; } return []; - }, [selectedTransactionType]); + }, [selectedTransactionType, selectedProductFlags]); const isTransactionSubtypeReadonly = useMemo(() => { const transactionType = selectedTransactionType?.value;