fix: adjust formik schema for warehouse

This commit is contained in:
ValdiANS
2026-03-16 09:41:23 +07:00
parent 0c8a833e00
commit 0f7a2bd796
2 changed files with 10 additions and 21 deletions
@@ -80,13 +80,13 @@ const InventoryAdjustmentTable = () => {
const formik = useFormik<AdjustmentFilterType>({ const formik = useFormik<AdjustmentFilterType>({
initialValues: { initialValues: {
product_id: null, product_id: null,
warehouse_id: null, warehouse: null,
transaction_type: null, transaction_type: null,
}, },
validationSchema: AdjustmentFilterSchema, validationSchema: AdjustmentFilterSchema,
onSubmit: (values, { setSubmitting }) => { onSubmit: (values, { setSubmitting }) => {
updateFilter('productFilter', values.product_id || ''); updateFilter('productFilter', values.product_id || '');
updateFilter('warehouseFilter', values.warehouse_id || ''); updateFilter('warehouseFilter', String(values.warehouse?.value) || '');
updateFilter('transactionTypeFilter', values.transaction_type || ''); updateFilter('transactionTypeFilter', values.transaction_type || '');
filterModal.closeModal(); filterModal.closeModal();
setSubmitting(false); setSubmitting(false);
@@ -142,14 +142,11 @@ const InventoryAdjustmentTable = () => {
[formik] [formik]
); );
const handleFilterWarehouseChange = useCallback( const handleFilterWarehouseChange = (
(val: OptionType | OptionType[] | null) => { val: OptionType | OptionType[] | null
const warehouse = val as OptionType | null; ) => {
const warehouseId = warehouse?.value ? String(warehouse.value) : null; formik.setFieldValue('warehouse', val);
formik.setFieldValue('warehouse_id', warehouseId); };
},
[formik]
);
const handleFilterTransactionTypeChange = useCallback( const handleFilterTransactionTypeChange = useCallback(
(val: OptionType | OptionType[] | null) => { (val: OptionType | OptionType[] | null) => {
@@ -170,15 +167,6 @@ const InventoryAdjustmentTable = () => {
); );
}, [formik.values.product_id, productOptions]); }, [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(() => { const transactionTypeValue = useMemo(() => {
if (!formik.values.transaction_type) return null; if (!formik.values.transaction_type) return null;
return ( return (
@@ -502,7 +490,7 @@ const InventoryAdjustmentTable = () => {
label='Gudang' label='Gudang'
placeholder='Pilih Gudang' placeholder='Pilih Gudang'
options={warehouseOptions} options={warehouseOptions}
value={warehouseIdValue} value={formik.values.warehouse}
onChange={handleFilterWarehouseChange} onChange={handleFilterWarehouseChange}
onInputChange={setWarehouseInputValue} onInputChange={setWarehouseInputValue}
isLoading={isLoadingWarehouseOptions} isLoading={isLoadingWarehouseOptions}
@@ -1,4 +1,5 @@
import { string, object } from 'yup'; import { string, object } from 'yup';
import { OptionType } from '@/components/input/SelectInput';
export const AdjustmentFilterSchema = object().shape({ export const AdjustmentFilterSchema = object().shape({
product_id: string().nullable(), product_id: string().nullable(),
@@ -8,6 +9,6 @@ export const AdjustmentFilterSchema = object().shape({
export type AdjustmentFilterType = { export type AdjustmentFilterType = {
product_id: string | null; product_id: string | null;
warehouse_id: string | null;
transaction_type: string | null; transaction_type: string | null;
warehouse: OptionType<number> | null;
}; };