refactor(FE): Filter transaction subtypes based on selected product

flags
This commit is contained in:
rstubryan
2026-02-26 16:10:19 +07:00
parent 47ee911852
commit 3099588141
@@ -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<OptionType & { quantity?: number }, boolean>
@@ -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;