|
@@ -1,6 +1,8 @@
|
|
|
import {addMenu, editMenu, getMenuList} from '@apis';
|
|
|
import {yupResolver} from '@hookform/resolvers/yup';
|
|
|
+import {useContextSection, usePage} from '@hooks';
|
|
|
import {MenuListData} from '@models';
|
|
|
+import {context, pageContext} from '@pages/menu/context';
|
|
|
import {useMutation, useQueryClient} from '@tanstack/react-query';
|
|
|
import {message} from 'antd';
|
|
|
import {useEffect, useMemo} from 'react';
|
|
@@ -57,15 +59,17 @@ function useEdit(onClose: () => void, onFetch: () => void) {
|
|
|
function useEditData(id: string) {
|
|
|
const client = useQueryClient();
|
|
|
const {id: pid} = useParams<{id: string}>();
|
|
|
+ const [{page, pageSize}] = usePage(pageContext);
|
|
|
+ const name = useContextSection(context, state => state[0].name);
|
|
|
return useMemo(function() {
|
|
|
const list = client.getQueryData<MenuListData[]>(
|
|
|
- [getMenuList.name, pid ?? '0'],
|
|
|
- {exact: false},
|
|
|
+ [getMenuList.name, pid ?? '0', page, pageSize, name],
|
|
|
);
|
|
|
+
|
|
|
const result = list?.find(val => val.id === id);
|
|
|
|
|
|
return result;
|
|
|
- }, [client, id, pid]);
|
|
|
+ }, [client, id, name, page, pageSize, pid]);
|
|
|
}
|
|
|
|
|
|
export function useFormState(
|
|
@@ -94,7 +98,7 @@ export function useFormState(
|
|
|
if (visible) {
|
|
|
setValue('menuName', editData?.name ?? '');
|
|
|
setValue('menuUrl', editData?.url ?? '');
|
|
|
- setValue('menuOrderBy', editData?.orderBy ?? '');
|
|
|
+ setValue('menuOrderBy', editData?.orderBy ?? '0');
|
|
|
clearErrors();
|
|
|
}
|
|
|
}, [clearErrors, editData, setValue, visible]);
|