From ceb316d3da0ae11dbbf4e8666b3ff1aa6bff92f2 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Tue, 3 Mar 2026 09:15:57 +0700 Subject: [PATCH] refactor(FE): Refactor subtype label mapping and fix depletion subtype value --- .../adjustment/InventoryAdjustmentTable.tsx | 24 ++++++++++++------- .../form/InventoryAdjustmentForm.tsx | 4 ++-- src/config/constant.ts | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx b/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx index 6d8a17e2..ec5ebe44 100644 --- a/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx +++ b/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx @@ -14,6 +14,7 @@ import { useTableFilter } from '@/services/hooks/useTableFilter'; import { InventoryAdjustment } from '@/types/api/inventory/adjustment'; import StatusBadge from '@/components/helper/StatusBadge'; import InventoryAdjustmentTableSkeleton from '@/components/pages/inventory/adjustment/skeleton/InventoryAdjustmentTableSkeleton'; +import { TRANSACTION_SUBTYPE_OPTIONS } from '@/config/constant'; const InventoryAdjustmentTable = () => { const { @@ -102,16 +103,23 @@ const InventoryAdjustmentTable = () => { const subtype = row.row.original.transaction_subtype; const increase = row.row.original.increase; - const subtypeLabelMap: Record = { - PURCHASE_IN: 'Pembelian', - MARKETING_OUT: 'Penjualan', - RECORDING_STOCK_OUT: 'Recording Stock', - RECORDING_DEPLETION_OUT: 'Recording Depletion', - RECORDING_EGG_IN: 'Recording Egg', - ADJUSTMENT_OUT: 'Penyesuaian', + const getSubtypeLabel = (subtypeValue: string): string => { + if (subtypeValue === TRANSACTION_SUBTYPE_OPTIONS.PEMBELIAN.value) { + return TRANSACTION_SUBTYPE_OPTIONS.PEMBELIAN.label; + } + if (subtypeValue === TRANSACTION_SUBTYPE_OPTIONS.PENJUALAN.value) { + return TRANSACTION_SUBTYPE_OPTIONS.PENJUALAN.label; + } + const recordingOption = TRANSACTION_SUBTYPE_OPTIONS.RECORDING.find( + (opt) => opt.value === subtypeValue + ); + if (recordingOption) { + return recordingOption.label; + } + return subtypeValue || '-'; }; - const label = subtypeLabelMap[subtype] || subtype || '-'; + const label = getSubtypeLabel(subtype); return ( opt.value === 'RECORDING_EGG_IN' ); } else if (isChickenProduct) { - // Produk ayam: hanya RECORDING_DEPLETION_OUT + // Produk ayam: hanya RECORDING_DEPLETION_IN return allRecordingOptions.filter( - (opt) => opt.value === 'RECORDING_DEPLETION_OUT' + (opt) => opt.value === 'RECORDING_DEPLETION_IN' ); } else { // Produk non-telur dan non-ayam (PAKAN, OVK, dll): hanya RECORDING_STOCK_OUT diff --git a/src/config/constant.ts b/src/config/constant.ts index a754b3a9..99c5ff9d 100644 --- a/src/config/constant.ts +++ b/src/config/constant.ts @@ -624,7 +624,7 @@ export const TRANSACTION_SUBTYPE_OPTIONS = { PENJUALAN: { label: 'Penjualan', value: 'MARKETING_OUT' }, RECORDING: [ { label: 'Recording Stock', value: 'RECORDING_STOCK_OUT' }, - { label: 'Recording Depletion', value: 'RECORDING_DEPLETION_OUT' }, + { label: 'Recording Depletion', value: 'RECORDING_DEPLETION_IN' }, { label: 'Recording Egg', value: 'RECORDING_EGG_IN' }, ], } as const;