From e0e2b0c406c08284b3b44d17a64176f24eaa71de Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 22 Apr 2026 13:58:25 +0700 Subject: [PATCH] fix: load more location and vendors and adjust reset handler --- .../expense/filter/ExpensesFilterModal.tsx | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/components/pages/expense/filter/ExpensesFilterModal.tsx b/src/components/pages/expense/filter/ExpensesFilterModal.tsx index 1885785f..67e4b0ac 100644 --- a/src/components/pages/expense/filter/ExpensesFilterModal.tsx +++ b/src/components/pages/expense/filter/ExpensesFilterModal.tsx @@ -1,6 +1,6 @@ 'use client'; -import { RefObject } from 'react'; +import { RefObject, useCallback } from 'react'; import { useFormik } from 'formik'; import { Icon } from '@iconify/react'; @@ -39,54 +39,51 @@ const ExpensesFilterModal = ({ setInputValue: setLocationInputValue, options: locationOptions, isLoadingOptions: isLoadingLocationOptions, + loadMore: loadMoreLocations, } = useSelect(LocationApi.basePath, 'id', 'name'); const { setInputValue: setVendorInputValue, options: vendorOptions, isLoadingOptions: isLoadingVendorOptions, + loadMore: loadMoreVendors, } = useSelect(SupplierApi.basePath, 'id', 'name'); const formik = useFormik({ initialValues: initialValues || { transaction_date: null, realization_date: null, - location_id: null, - vendor_id: null, + location: null, + vendor: null, }, validationSchema: ExpensesFilterSchema, onSubmit: async (values) => { onSubmit?.(values); closeModalHandler(); }, - onReset: () => { - onReset?.(); - closeModalHandler(); - }, }); - const locationValue = formik.values.location_id - ? locationOptions.find( - (opt) => String(opt.value) === formik.values.location_id - ) || null - : null; + const { resetForm } = formik; - const vendorValue = formik.values.vendor_id - ? vendorOptions.find( - (opt) => String(opt.value) === formik.values.vendor_id - ) || null - : null; + const formikResetHandler = useCallback(() => { + resetForm({ + values: { + transaction_date: null, + realization_date: null, + location: null, + vendor: null, + }, + }); + onReset?.(); + closeModalHandler(); + }, [resetForm, onReset, closeModalHandler]); const locationChangeHandler = (val: OptionType | OptionType[] | null) => { - const locationId = - val && !Array.isArray(val) ? (String(val.value) as string) : null; - formik.setFieldValue('location_id', locationId); + formik.setFieldValue('location', val as OptionType | null); }; const vendorChangeHandler = (val: OptionType | OptionType[] | null) => { - const vendorId = - val && !Array.isArray(val) ? (String(val.value) as string) : null; - formik.setFieldValue('vendor_id', vendorId); + formik.setFieldValue('vendor', val as OptionType | null); }; return ( @@ -98,7 +95,7 @@ const ExpensesFilterModal = ({ >
{/* Modal Header */} @@ -160,10 +157,11 @@ const ExpensesFilterModal = ({ label='Lokasi' placeholder='Pilih Lokasi' options={locationOptions} - value={locationValue} + value={formik.values.location} onChange={locationChangeHandler} onInputChange={setLocationInputValue} isLoading={isLoadingLocationOptions} + onMenuScrollToBottom={loadMoreLocations} isClearable isSearchable={true} className={{ wrapper: 'w-full' }} @@ -173,10 +171,11 @@ const ExpensesFilterModal = ({ label='Vendor' placeholder='Pilih Vendor' options={vendorOptions} - value={vendorValue} + value={formik.values.vendor} onChange={vendorChangeHandler} onInputChange={setVendorInputValue} isLoading={isLoadingVendorOptions} + onMenuScrollToBottom={loadMoreVendors} isClearable isSearchable={true} className={{ wrapper: 'w-full' }}