优化体验: 缓存表单数据

dev/chat
Lei OT 2 years ago
parent d5f32690a4
commit b7af5b1cd3

@ -1,16 +1,25 @@
import { create } from 'zustand';
import { RealTimeAPI } from '@/lib/realTimeAPI';
import { olog, isEmpty } from '@/utils/utils';
import { receivedMsgTypeMapped, handleNotification } from '@/lib/msgUtils';
import { fetchConversationsList, fetchTemplates, fetchMessages } from '@/actions/ConversationActions';
import { devtools } from 'zustand/middleware';
import { WS_URL } from '@/config';
export const useFormStore = create(devtools((set, get) => ({
export const useFormStore = create(
devtools((set, get) => ({
// 历史记录页面
chatHistoryForm: {},
setChatHistoryForm: (chatHistoryForm) => set({ chatHistoryForm, chatHistorySelectChat: {} }),
chatHistorySelectChat: {},
setChatHistorySelectChat: (chatHistorySelectChat) => set({ chatHistorySelectChat }),
})));
// 订单跟踪页面
orderFollowForm: {
type: 'today',
orderStatus: '新状态',
orderNumber: '订单号',
orderLabel: '订单标签',
startDate: '走团时间',
},
setOrderFollowForm: (orderFollowForm) => set({ orderFollowForm }),
orderFollowAdvanceChecked: false,
setOrderFollowAdvanceChecked: (orderFollowAdvanceChecked) => set({ orderFollowAdvanceChecked }),
}))
);
export default useFormStore;

@ -9,10 +9,13 @@ import { Conditional } from '@/components/Conditional'
import useOrderStore from '@/stores/OrderStore'
import useAuthStore from '@/stores/AuthStore'
import { copy } from '@/utils/commons'
import useFormStore from '@/stores/FormStore';
import { useShallow } from 'zustand/react/shallow';
const { RangePicker } = DatePicker
const AdvanceSearchForm = memo(function ({ onSubmit }) {
// eslint-disable-next-line react/display-name
const AdvanceSearchForm = memo(function ({ initialValues, onSubmit }) {
const DATE_RANGE_PRESETS = [
{
@ -311,14 +314,16 @@ function OrderGroupTable({ formValues }) {
function OrderFollow() {
const [advanceChecked, toggleAdvance] = useState(false)
const [formValues, setFormValues] = useState({
type: 'today',
orderStatus: '新状态',
orderNumber: '订单号',
orderLabel: '订单标签',
startDate: '走团时间'
})
// const [advanceChecked, toggleAdvance] = useState(false)
// const [formValues, setFormValues] = useState({
// type: 'today',
// orderStatus: '',
// orderNumber: '',
// orderLabel: '',
// startDate: ''
// })
const [formValues, setFormValues] = useFormStore(useShallow((state) => [state.orderFollowForm, state.setOrderFollowForm]));
const [advanceChecked, toggleAdvance] = useFormStore(useShallow((state) => [state.orderFollowAdvanceChecked, state.setOrderFollowAdvanceChecked]));
const handleSubmit = useCallback((values) => {
setFormValues({ ...values, type: 'advance' })

Loading…
Cancel
Save