diff --git a/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx b/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx index 90b68b7d..f8bd4443 100644 --- a/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx +++ b/src/components/pages/inventory/adjustment/InventoryAdjustmentTable.tsx @@ -80,13 +80,13 @@ const InventoryAdjustmentTable = () => { const formik = useFormik({ initialValues: { product_id: null, - warehouse_id: null, + warehouse: null, transaction_type: null, }, validationSchema: AdjustmentFilterSchema, onSubmit: (values, { setSubmitting }) => { updateFilter('productFilter', values.product_id || ''); - updateFilter('warehouseFilter', values.warehouse_id || ''); + updateFilter('warehouseFilter', String(values.warehouse?.value) || ''); updateFilter('transactionTypeFilter', values.transaction_type || ''); filterModal.closeModal(); setSubmitting(false); @@ -142,14 +142,11 @@ const InventoryAdjustmentTable = () => { [formik] ); - const handleFilterWarehouseChange = useCallback( - (val: OptionType | OptionType[] | null) => { - const warehouse = val as OptionType | null; - const warehouseId = warehouse?.value ? String(warehouse.value) : null; - formik.setFieldValue('warehouse_id', warehouseId); - }, - [formik] - ); + const handleFilterWarehouseChange = ( + val: OptionType | OptionType[] | null + ) => { + formik.setFieldValue('warehouse', val); + }; const handleFilterTransactionTypeChange = useCallback( (val: OptionType | OptionType[] | null) => { @@ -170,15 +167,6 @@ const InventoryAdjustmentTable = () => { ); }, [formik.values.product_id, productOptions]); - const warehouseIdValue = useMemo(() => { - if (!formik.values.warehouse_id) return null; - return ( - warehouseOptions.find( - (opt) => String(opt.value) === formik.values.warehouse_id - ) || null - ); - }, [formik.values.warehouse_id, warehouseOptions]); - const transactionTypeValue = useMemo(() => { if (!formik.values.transaction_type) return null; return ( @@ -502,7 +490,7 @@ const InventoryAdjustmentTable = () => { label='Gudang' placeholder='Pilih Gudang' options={warehouseOptions} - value={warehouseIdValue} + value={formik.values.warehouse} onChange={handleFilterWarehouseChange} onInputChange={setWarehouseInputValue} isLoading={isLoadingWarehouseOptions} diff --git a/src/components/pages/inventory/adjustment/filter/AdjustmentFilter.ts b/src/components/pages/inventory/adjustment/filter/AdjustmentFilter.ts index 4568618f..e4015e07 100644 --- a/src/components/pages/inventory/adjustment/filter/AdjustmentFilter.ts +++ b/src/components/pages/inventory/adjustment/filter/AdjustmentFilter.ts @@ -1,4 +1,5 @@ import { string, object } from 'yup'; +import { OptionType } from '@/components/input/SelectInput'; export const AdjustmentFilterSchema = object().shape({ product_id: string().nullable(), @@ -8,6 +9,6 @@ export const AdjustmentFilterSchema = object().shape({ export type AdjustmentFilterType = { product_id: string | null; - warehouse_id: string | null; transaction_type: string | null; + warehouse: OptionType | null; };