|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
import { useEffect, useState, useRef } from 'react';
|
|
|
|
|
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
|
|
|
|
import { Button, Dropdown } from 'antd';
|
|
|
|
|
import { Button, Dropdown, Input } from 'antd';
|
|
|
|
|
import { MoreOutlined } from '@ant-design/icons';
|
|
|
|
|
import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages } from '@/actions/ConversationActions';
|
|
|
|
|
import { ChatList, ChatItem } from 'react-chat-elements';
|
|
|
|
|
import { isEmpty } from '@/utils/utils';
|
|
|
|
|
import useConversationStore from '@/stores/ConversationStore';
|
|
|
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
|
|
|
import useAuthStore from '@/stores/AuthStore';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* []
|
|
|
|
@ -16,7 +16,7 @@ const Conversations = () => {
|
|
|
|
|
const { coli_guest_WhatsApp } = orderRow || {};
|
|
|
|
|
const { order_sn } = useParams();
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const userId = useAuthStore(state => state.loginUser.userId);
|
|
|
|
|
const userId = useAuthStore((state) => state.loginUser.userId);
|
|
|
|
|
const initialState = useConversationStore((state) => state.initialState);
|
|
|
|
|
const activeConversations = useConversationStore((state) => state.activeConversations);
|
|
|
|
|
const currentConversation = useConversationStore((state) => state.currentConversation);
|
|
|
|
@ -27,6 +27,8 @@ const Conversations = () => {
|
|
|
|
|
const receivedMessageList = useConversationStore((state) => state.receivedMessageList);
|
|
|
|
|
const setMsgLoading = useConversationStore((state) => state.setMsgLoading);
|
|
|
|
|
|
|
|
|
|
const [dataSource, setDataSource] = useState(conversationsList);
|
|
|
|
|
|
|
|
|
|
const [switchToC, setSwitchToC] = useState({});
|
|
|
|
|
const [shouldFetchCList, setShouldFetchCList] = useState(true);
|
|
|
|
|
useEffect(() => {
|
|
|
|
@ -91,14 +93,44 @@ const Conversations = () => {
|
|
|
|
|
navigate(`/order/chat`, { replace: true });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const searchInputRef = useRef(null);
|
|
|
|
|
const [searchContent, setSearchContent] = useState('');
|
|
|
|
|
const handleSearchConversations = (val) => {
|
|
|
|
|
if (val.toLowerCase().trim() !== '') {
|
|
|
|
|
const res = conversationsList.filter(
|
|
|
|
|
(item) => (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
|| (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
|| (item.coli_id.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
);
|
|
|
|
|
setDataSource(res);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
setDataSource(conversationsList);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className=' overflow-x-hidden'>
|
|
|
|
|
{conversationsList.map((item) => (
|
|
|
|
|
<div className='flex flex-col h-inherit'>
|
|
|
|
|
<div className=''>
|
|
|
|
|
<Input.Search
|
|
|
|
|
className=''
|
|
|
|
|
ref={searchInputRef}
|
|
|
|
|
onSearch={handleSearchConversations}
|
|
|
|
|
allowClear
|
|
|
|
|
value={searchContent}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSearchContent(e.target.value);
|
|
|
|
|
handleSearchConversations(e.target.value);
|
|
|
|
|
}}
|
|
|
|
|
placeholder='搜索名称'
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='flex-1 overflow-x-hidden overflow-y-auto relative'>
|
|
|
|
|
{dataSource.map((item) => (
|
|
|
|
|
<Dropdown
|
|
|
|
|
key={item.sn}
|
|
|
|
|
menu={{
|
|
|
|
|
items: [{ label: '关闭会话', key: 'close', danger: true, }],
|
|
|
|
|
items: [{ label: '关闭会话', key: 'close', danger: true }],
|
|
|
|
|
onClick: ({ key, domEvent }) => {
|
|
|
|
|
domEvent.stopPropagation();
|
|
|
|
|
switch (key) {
|
|
|
|
@ -121,13 +153,15 @@ const Conversations = () => {
|
|
|
|
|
subtitle={item.coli_id}
|
|
|
|
|
date={item.last_received_time}
|
|
|
|
|
unread={item.unread_msg_count}
|
|
|
|
|
className={String(item.sn) === String(currentConversation.sn) ? '__active text-primary border-y-0 border-e-0 border-s-4 border-solid border-whatsapp-bg bg-whatsapp-bg' : ''}
|
|
|
|
|
className={
|
|
|
|
|
String(item.sn) === String(currentConversation.sn) ? '__active text-primary border-y-0 border-e-0 border-s-4 border-solid border-whatsapp-bg bg-whatsapp-bg' : ''
|
|
|
|
|
}
|
|
|
|
|
onClick={() => onSwitchConversation(item)}
|
|
|
|
|
/>
|
|
|
|
|
</Dropdown>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
export default Conversations;
|
|
|
|
|