|
@@ -2,6 +2,7 @@ import {addSell} from '@apis';
|
|
|
import {yupResolver} from '@hookform/resolvers/yup';
|
|
|
import {useMutateAddOrder} from '@hooks';
|
|
|
import {AddSellParams} from '@models';
|
|
|
+import {useLatest} from 'ahooks';
|
|
|
import dayjs, {Dayjs} from 'dayjs';
|
|
|
import {useEffect} from 'react';
|
|
|
import {useForm} from 'react-hook-form';
|
|
@@ -89,7 +90,7 @@ export function useFormState({
|
|
|
visible: boolean;
|
|
|
onClose: () => void;
|
|
|
onFetch: () => void;
|
|
|
- onSearch: (val: string) => void;
|
|
|
+ onSearch: () => void;
|
|
|
}) {
|
|
|
const {clearErrors, reset, control, handleSubmit} = useForm<FormState>({
|
|
|
resolver: yupResolver(validate),
|
|
@@ -112,15 +113,17 @@ export function useFormState({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+ const clearSearch = useLatest(onSearch);
|
|
|
+
|
|
|
useEffect(
|
|
|
function () {
|
|
|
if (visible) {
|
|
|
clearErrors();
|
|
|
reset();
|
|
|
- onSearch('');
|
|
|
+ clearSearch.current();
|
|
|
}
|
|
|
},
|
|
|
- [clearErrors, onSearch, reset, visible],
|
|
|
+ [clearErrors, clearSearch, reset, visible],
|
|
|
);
|
|
|
|
|
|
const [isLoading, mutate] = useMutateAddOrder(addSell, onFetch, onClose);
|