feat(FE): Show product UOM suffix in recording form

This commit is contained in:
rstubryan
2026-01-21 14:15:09 +07:00
parent 99fc3f8cae
commit 4d7bbaf771
2 changed files with 61 additions and 0 deletions
@@ -1174,6 +1174,47 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
[stockProducts]
);
const getProductUomSuffix = useCallback(
(productWarehouseId: number, dataSource: 'stock' | 'depletion' | 'egg') => {
if (type !== 'add' && initialValues) {
let items;
if (dataSource === 'stock') {
items = initialValues.stocks;
} else if (dataSource === 'depletion') {
items = initialValues.depletions;
} else if (dataSource === 'egg') {
items = initialValues.eggs;
}
if (items) {
const item = items.find(
(i) => i.product_warehouse_id === productWarehouseId
);
if (item?.product_warehouse?.product?.uom?.name) {
return item.product_warehouse.product.uom.name;
}
}
}
let rawData;
if (dataSource === 'stock') {
rawData = stockProducts;
} else if (dataSource === 'depletion') {
rawData = depletionProductsData;
} else if (dataSource === 'egg') {
rawData = eggProductsData;
}
if (!isResponseSuccess(rawData)) return null;
const data = rawData.data as unknown as ProductWarehouse[];
const productWarehouse = data.find((pw) => pw.id === productWarehouseId);
return productWarehouse?.product.uom.name || null;
},
[stockProducts, depletionProductsData, eggProductsData, initialValues, type]
);
const hasExceededStock = useMemo(() => {
if ((type as 'add' | 'edit' | 'detail') === 'detail') return false;
return (
@@ -2451,6 +2492,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
wrapper: 'w-full min-w-24',
}}
placeholder='Masukkan jumlah pakai'
inputSuffix={
stock.product_warehouse_id
? getProductUomSuffix(
stock.product_warehouse_id,
'stock'
)
: null
}
/>
{(type as 'add' | 'edit' | 'detail') !== 'detail' &&
getStockUsageAdornment(idx)}
@@ -2646,6 +2695,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
wrapper: 'w-full min-w-24',
}}
placeholder='Masukkan jumlah deplesi'
inputSuffix={
depletion.product_warehouse_id
? getProductUomSuffix(
depletion.product_warehouse_id,
'depletion'
)
: null
}
/>
</td>
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
@@ -2839,6 +2896,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
wrapper: 'w-full min-w-24',
}}
placeholder='Masukkan jumlah telur'
inputSuffix={'Butir'}
/>
</td>
<td>
@@ -2864,6 +2922,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
wrapper: 'w-full min-w-24',
}}
placeholder='Masukkan total berat telur (Kilogram)...'
inputSuffix='Kilogram'
/>
</td>
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
+2
View File
@@ -1,11 +1,13 @@
import { BaseMetadata } from '@/types/api/api-general';
import { Warehouse } from '@/types/api/master-data/warehouse';
import { Product } from '@/types/api/master-data/product';
import { Uom } from '@/types/api/master-data/uom';
export type BaseProductWarehouse = {
id: number;
product_id: number;
warehouse_id: number;
uom: Uom;
quantity: number;
product: Product;
warehouse: Warehouse;