mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE): Add stock availability badge to product dropdown
This commit is contained in:
@@ -28,6 +28,8 @@ import SelectInput, {
|
|||||||
OptionType,
|
OptionType,
|
||||||
useSelect,
|
useSelect,
|
||||||
} from '@/components/input/SelectInput';
|
} from '@/components/input/SelectInput';
|
||||||
|
import { components as ReactSelectComponents, OptionProps } from 'react-select';
|
||||||
|
import StatusBadge from '@/components/helper/StatusBadge';
|
||||||
import TextArea from '@/components/input/TextArea';
|
import TextArea from '@/components/input/TextArea';
|
||||||
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
import AlertErrorList from '@/components/helper/form/FormErrors';
|
import AlertErrorList from '@/components/helper/form/FormErrors';
|
||||||
@@ -203,10 +205,36 @@ const InventoryAdjustmentForm = ({
|
|||||||
? productWarehouses.data.map((pw) => ({
|
? productWarehouses.data.map((pw) => ({
|
||||||
value: pw.product.id,
|
value: pw.product.id,
|
||||||
label: pw.product.name,
|
label: pw.product.name,
|
||||||
|
quantity: pw.quantity,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
}, [productWarehouses]);
|
}, [productWarehouses]);
|
||||||
|
|
||||||
|
const ProductOption = useMemo(() => {
|
||||||
|
const OptionComponent = (
|
||||||
|
props: OptionProps<OptionType & { quantity?: number }, boolean>
|
||||||
|
) => {
|
||||||
|
const { data, children } = props;
|
||||||
|
const quantity = data.quantity ?? 0;
|
||||||
|
const isAvailable = quantity > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ReactSelectComponents.Option {...props}>
|
||||||
|
<div className='flex items-center justify-between gap-2'>
|
||||||
|
<span className='flex-1'>{children}</span>
|
||||||
|
<StatusBadge
|
||||||
|
color={isAvailable ? 'success' : 'error'}
|
||||||
|
text={isAvailable ? 'Tersedia' : 'Kosong'}
|
||||||
|
className={{ badge: 'whitespace-nowrap w-fit' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ReactSelectComponents.Option>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
OptionComponent.displayName = 'ProductOption';
|
||||||
|
return OptionComponent;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const kandangOptions = useMemo(() => {
|
const kandangOptions = useMemo(() => {
|
||||||
let options: OptionType[] = [];
|
let options: OptionType[] = [];
|
||||||
|
|
||||||
@@ -646,6 +674,7 @@ const InventoryAdjustmentForm = ({
|
|||||||
onChange={productChangeHandler}
|
onChange={productChangeHandler}
|
||||||
onInputChange={setProductInputValue}
|
onInputChange={setProductInputValue}
|
||||||
options={productOptions}
|
options={productOptions}
|
||||||
|
optionComponent={ProductOption}
|
||||||
onMenuScrollToBottom={loadMoreProducts}
|
onMenuScrollToBottom={loadMoreProducts}
|
||||||
isLoading={isLoadingProductOptions}
|
isLoading={isLoadingProductOptions}
|
||||||
isError={
|
isError={
|
||||||
@@ -658,6 +687,14 @@ const InventoryAdjustmentForm = ({
|
|||||||
? 'Pilih Produk'
|
? 'Pilih Produk'
|
||||||
: 'Pilih Kandang terlebih dahulu'
|
: 'Pilih Kandang terlebih dahulu'
|
||||||
}
|
}
|
||||||
|
inputPrefix={
|
||||||
|
selectedProduct
|
||||||
|
? 'Stock: ' +
|
||||||
|
(productOptions.find(
|
||||||
|
(opt) => opt.value === selectedProduct?.value
|
||||||
|
)?.quantity ?? 0)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
isClearable
|
isClearable
|
||||||
isSearchable
|
isSearchable
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user