feat: 顾问的已关闭会话

dev/timezone
Lei OT 1 year ago
parent fb98258793
commit 2b08435ab9

@ -2,7 +2,7 @@ import { create } from 'zustand';
import { RealTimeAPI } from '@/channel/realTimeAPI'; import { RealTimeAPI } from '@/channel/realTimeAPI';
import { olog, isEmpty } from '@/utils/commons'; import { olog, isEmpty } from '@/utils/commons';
import { receivedMsgTypeMapped, handleNotification } from '@/channel/whatsappUtils'; import { receivedMsgTypeMapped, handleNotification } from '@/channel/whatsappUtils';
import { fetchConversationsList, fetchTemplates, fetchMessages } from '@/actions/ConversationActions'; import { fetchConversationsList, fetchTemplates, fetchConversationsSearch } from '@/actions/ConversationActions';
import { devtools } from 'zustand/middleware'; import { devtools } from 'zustand/middleware';
import { WS_URL } from '@/config'; import { WS_URL } from '@/config';
@ -32,6 +32,7 @@ const initialConversationState = {
// templates: [], // templates: [],
closedConversationsList: [], // 已关闭的对话列表
conversationsList: [], // 对话列表 conversationsList: [], // 对话列表
currentConversation: {}, // 当前对话 currentConversation: {}, // 当前对话
@ -151,6 +152,7 @@ const conversationSlice = (set, get) => ({
conversationsListLoading: false, conversationsListLoading: false,
conversationsList: [], conversationsList: [],
currentConversation: {}, currentConversation: {},
closedConversationsList: [],
setConversationsListLoading: (conversationsListLoading) => set({ conversationsListLoading }), setConversationsListLoading: (conversationsListLoading) => set({ conversationsListLoading }),
@ -161,6 +163,11 @@ const conversationSlice = (set, get) => ({
const conversationsMapped = conversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {}); const conversationsMapped = conversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
return set({ conversationsList, activeConversations: conversationsMapped }); return set({ conversationsList, activeConversations: conversationsMapped });
}, },
setClosedConversationList: (closedConversationsList) => {
const { activeConversations, } = get();
const listMapped = closedConversationsList.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
return set({ closedConversationsList, activeConversations: { ...activeConversations, ...listMapped } });
},
addToConversationList: (newList) => { addToConversationList: (newList) => {
const { activeConversations, conversationsList } = get(); const { activeConversations, conversationsList } = get();
const conversationsIds = Object.keys(activeConversations); const conversationsIds = Object.keys(activeConversations);
@ -351,7 +358,7 @@ export const useConversationStore = create(
// side effects // side effects
fetchInitialData: async (userIds) => { fetchInitialData: async (userIds) => {
const { addToConversationList, setTemplates, setInitial, } = get(); const { addToConversationList, setTemplates, setInitial, setClosedConversationList } = get();
const conversationsList = await fetchConversationsList({ opisn: userIds }); const conversationsList = await fetchConversationsList({ opisn: userIds });
addToConversationList(conversationsList); addToConversationList(conversationsList);
@ -359,8 +366,10 @@ export const useConversationStore = create(
const templates = await fetchTemplates(); const templates = await fetchTemplates();
setTemplates(templates); setTemplates(templates);
setInitial(true); const closedList = await fetchConversationsSearch({ opisn: userIds, session_enable: 0 });
setClosedConversationList(closedList);
setInitial(true);
}, },
reset: () => set(initialConversationState), reset: () => set(initialConversationState),

@ -1,7 +1,7 @@
import { useEffect, useState, useRef } from 'react'; import { useEffect, useState, useRef } from 'react';
import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { useParams, useNavigate, useLocation } from 'react-router-dom';
import { Dropdown, Input, Button, } from 'antd'; import { Dropdown, Input, Button, Empty, Tooltip } from 'antd';
import { PlusOutlined, WhatsAppOutlined, LoadingOutlined } from '@ant-design/icons'; import { PlusOutlined, WhatsAppOutlined, LoadingOutlined, HistoryOutlined, FireOutlined } from '@ant-design/icons';
import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, postNewConversationItem } from '@/actions/ConversationActions'; import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, postNewConversationItem } from '@/actions/ConversationActions';
import { ChatItem } from 'react-chat-elements'; import { ChatItem } from 'react-chat-elements';
import ConversationsNewItem from './ConversationsNewItem'; import ConversationsNewItem from './ConversationsNewItem';
@ -28,6 +28,8 @@ const Conversations = ({ mobile }) => {
const addToConversationList = useConversationStore((state) => state.addToConversationList); const addToConversationList = useConversationStore((state) => state.addToConversationList);
const delConversationitem = useConversationStore((state) => state.delConversationitem); const delConversationitem = useConversationStore((state) => state.delConversationitem);
const closedConversationsList = useConversationStore((state) => state.closedConversationsList);
const isVisible = useVisibilityState(); const isVisible = useVisibilityState();
const [tabSelectedConversation, setTabSelectedConversation] = useState({}); const [tabSelectedConversation, setTabSelectedConversation] = useState({});
@ -60,7 +62,7 @@ const Conversations = ({ mobile }) => {
useEffect(() => { useEffect(() => {
setDataSource(conversationsList); setDataSource(conversationsList);
return () => {}; return () => {};
}, [conversationsList]); }, [conversationsList.length]);
const [switchToC, setSwitchToC] = useState({}); const [switchToC, setSwitchToC] = useState({});
const [shouldFetchCList, setShouldFetchCList] = useState(true); const [shouldFetchCList, setShouldFetchCList] = useState(true);
@ -165,10 +167,19 @@ const Conversations = ({ mobile }) => {
// setNewChatFormValues(values); // setNewChatFormValues(values);
} }
const [activeList, setActiveList] = useState(true);
// const closedVisible = closedConversationsList.length > 0;
const toggleClosedConversationsList = () => {
const _active = activeList;
setDataSource(_active ? closedConversationsList : conversationsList);
setActiveList(!activeList);
setCurrentConversation({});
}
return ( return (
<div className='flex flex-col h-inherit'> <div className='flex flex-col h-inherit'>
<div className='flex gap-1'> <div className='flex gap-1'>
{([404, 383].includes(userId)) && <Button onClick={() => setNewChatModalVisible(true)} icon={<PlusOutlined />} type={'primary'} />} {[404, 383].includes(userId) && <Button onClick={() => setNewChatModalVisible(true)} icon={<PlusOutlined />} type={'primary'} />}
<Input.Search <Input.Search
className='' className=''
ref={searchInputRef} ref={searchInputRef}
@ -199,6 +210,13 @@ const Conversations = ({ mobile }) => {
}} }}
placeholder={`搜索名称/号码/订单号${conversationsListLoading ? '...' : ''}`} placeholder={`搜索名称/号码/订单号${conversationsListLoading ? '...' : ''}`}
/> />
<Tooltip key={'conversation-list'} title={activeList ? '历史会话' : '活跃会话'}>
<Button
onClick={toggleClosedConversationsList}
icon={activeList ? <HistoryOutlined className='text-neutral-500' /> : <FireOutlined className=' text-orange-500' />}
type='text'
/>
</Tooltip>
</div> </div>
<div className='flex-1 overflow-x-hidden overflow-y-auto relative'> <div className='flex-1 overflow-x-hidden overflow-y-auto relative'>
{conversationsListLoading && dataSource.length === 0 ? ( {conversationsListLoading && dataSource.length === 0 ? (
@ -244,8 +262,14 @@ const Conversations = ({ mobile }) => {
/> />
</Dropdown> </Dropdown>
))} ))}
{dataSource.length === 0 && <Empty description={'无数据'} />}
</div> </div>
<ConversationsNewItem initialValues={{coli_id: currentConversation.coli_id, coli_sn: currentConversation.coli_sn}} open={newChatModalVisible} onCreate={handleNewChat} onCancel={() => setNewChatModalVisible(false)} /> <ConversationsNewItem
initialValues={{ coli_id: currentConversation.coli_id, coli_sn: currentConversation.coli_sn }}
open={newChatModalVisible}
onCreate={handleNewChat}
onCancel={() => setNewChatModalVisible(false)}
/>
</div> </div>
); );
}; };

Loading…
Cancel
Save