mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
feat(FE): Show product UOM suffix in recording form
This commit is contained in:
@@ -1174,6 +1174,47 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
[stockProducts]
|
[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(() => {
|
const hasExceededStock = useMemo(() => {
|
||||||
if ((type as 'add' | 'edit' | 'detail') === 'detail') return false;
|
if ((type as 'add' | 'edit' | 'detail') === 'detail') return false;
|
||||||
return (
|
return (
|
||||||
@@ -2451,6 +2492,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
wrapper: 'w-full min-w-24',
|
wrapper: 'w-full min-w-24',
|
||||||
}}
|
}}
|
||||||
placeholder='Masukkan jumlah pakai'
|
placeholder='Masukkan jumlah pakai'
|
||||||
|
inputSuffix={
|
||||||
|
stock.product_warehouse_id
|
||||||
|
? getProductUomSuffix(
|
||||||
|
stock.product_warehouse_id,
|
||||||
|
'stock'
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' &&
|
{(type as 'add' | 'edit' | 'detail') !== 'detail' &&
|
||||||
getStockUsageAdornment(idx)}
|
getStockUsageAdornment(idx)}
|
||||||
@@ -2646,6 +2695,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
wrapper: 'w-full min-w-24',
|
wrapper: 'w-full min-w-24',
|
||||||
}}
|
}}
|
||||||
placeholder='Masukkan jumlah deplesi'
|
placeholder='Masukkan jumlah deplesi'
|
||||||
|
inputSuffix={
|
||||||
|
depletion.product_warehouse_id
|
||||||
|
? getProductUomSuffix(
|
||||||
|
depletion.product_warehouse_id,
|
||||||
|
'depletion'
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
||||||
@@ -2839,6 +2896,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
wrapper: 'w-full min-w-24',
|
wrapper: 'w-full min-w-24',
|
||||||
}}
|
}}
|
||||||
placeholder='Masukkan jumlah telur'
|
placeholder='Masukkan jumlah telur'
|
||||||
|
inputSuffix={'Butir'}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -2864,6 +2922,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
wrapper: 'w-full min-w-24',
|
wrapper: 'w-full min-w-24',
|
||||||
}}
|
}}
|
||||||
placeholder='Masukkan total berat telur (Kilogram)...'
|
placeholder='Masukkan total berat telur (Kilogram)...'
|
||||||
|
inputSuffix='Kilogram'
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
{(type as 'add' | 'edit' | 'detail') !== 'detail' && (
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { BaseMetadata } from '@/types/api/api-general';
|
import { BaseMetadata } from '@/types/api/api-general';
|
||||||
import { Warehouse } from '@/types/api/master-data/warehouse';
|
import { Warehouse } from '@/types/api/master-data/warehouse';
|
||||||
import { Product } from '@/types/api/master-data/product';
|
import { Product } from '@/types/api/master-data/product';
|
||||||
|
import { Uom } from '@/types/api/master-data/uom';
|
||||||
|
|
||||||
export type BaseProductWarehouse = {
|
export type BaseProductWarehouse = {
|
||||||
id: number;
|
id: number;
|
||||||
product_id: number;
|
product_id: number;
|
||||||
warehouse_id: number;
|
warehouse_id: number;
|
||||||
|
uom: Uom;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
product: Product;
|
product: Product;
|
||||||
warehouse: Warehouse;
|
warehouse: Warehouse;
|
||||||
|
|||||||
Reference in New Issue
Block a user