From 0676411dd5d65344e5340ef747889d04e5f11327 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Fri, 17 Oct 2025 19:23:19 +0700 Subject: [PATCH] refactor(FE-62,65): enhance product quantity display and stock information in MovementForm --- .../inventory/movement/form/MovementForm.tsx | 109 +++++++++++------- 1 file changed, 66 insertions(+), 43 deletions(-) diff --git a/src/components/pages/inventory/movement/form/MovementForm.tsx b/src/components/pages/inventory/movement/form/MovementForm.tsx index 2ec06e66..d77f2de4 100644 --- a/src/components/pages/inventory/movement/form/MovementForm.tsx +++ b/src/components/pages/inventory/movement/form/MovementForm.tsx @@ -266,6 +266,13 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { location?: string; } + interface ProductWarehouseOptionType extends OptionType { + product_id: number; + warehouse_id: number; + warehouse_name: string; + quantity: number; + } + // Warehouse selection const [warehouseSelectInputValue, setWarehouseSelectInputValue] = useState(''); @@ -304,8 +311,8 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { ); const productWarehouseOptions = isResponseSuccess(productWarehouses) ? productWarehouses?.data.map((pw) => ({ - value: pw.id, - label: pw.product.name, + value: pw.product.id, + label: `${pw.product.name} - ${pw.warehouse.name} (Stock: ${pw.quantity.toLocaleString('id-ID')})`, product_id: pw.product.id, warehouse_id: pw.warehouse.id, warehouse_name: pw.warehouse.name, @@ -438,6 +445,33 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { [productWarehouseOptions, type] ); + const getProductQtyAdornment = useCallback( + (productIdx: number) => { + if (type === 'detail') return null; + const product = formik.values.products?.[productIdx]; + if (!product || !product.product_id) return null; + + const availableStock = getAvailableStock(product.product_id); + const requestedQty = Number(product.product_qty) || 0; + const remainingStock = availableStock - requestedQty; + + if (requestedQty > 0) { + return ( + + (sisa: {remainingStock.toLocaleString('id-ID')}) + + ); + } + + return ( + + (tersedia: {availableStock.toLocaleString('id-ID')}) + + ); + }, + [formik.values.products, getAvailableStock, type] + ); + const getProductQtyError = useCallback( (productIdx: number) => { if (type === 'detail') return null; @@ -813,7 +847,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { ); formik.setFieldValue( `products.${idx}.product_id`, - (val as OptionType)?.value + (val as ProductWarehouseOptionType)?.value ); }} options={productWarehouseOptions} @@ -837,46 +871,35 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => { /> -
- - {type !== 'detail' && product.product_id && ( -
- - Stok tersedia: - {' '} - {getAvailableStock( - product.product_id - ).toLocaleString('id-ID')} -
- )} -
+ {type !== 'detail' && (