|
|
|
@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react';
|
|
|
|
|
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
|
|
|
|
import { Dropdown, Input, Button, Empty, Tooltip, Tag, Select } from 'antd';
|
|
|
|
|
import { PlusOutlined, WhatsAppOutlined, LoadingOutlined, HistoryOutlined, FireOutlined, MessageFilled, FilterOutlined, PlusSquareOutlined } from '@ant-design/icons';
|
|
|
|
|
import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, fetchConversationsSearch, postNewConversationItem, fetchConversationItemUnread } from '@/actions/ConversationActions';
|
|
|
|
|
import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, fetchConversationsSearch, postNewConversationItem, fetchConversationItemUnread, UNREAD_MARK } from '@/actions/ConversationActions';
|
|
|
|
|
import { ChatItem } from 'react-chat-elements';
|
|
|
|
|
import ConversationsNewItem from './ConversationsNewItem';
|
|
|
|
|
import { isEmpty, olog } from '@/utils/commons';
|
|
|
|
@ -29,7 +29,6 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
const [conversationsListLoading, setConversationsListLoading] = useConversationStore((state) => [state.conversationsListLoading, state.setConversationsListLoading]);
|
|
|
|
|
const addToConversationList = useConversationStore((state) => state.addToConversationList);
|
|
|
|
|
const delConversationitem = useConversationStore((state) => state.delConversationitem);
|
|
|
|
|
const updateConversationItem = useConversationStore((state) => state.updateConversationItem);
|
|
|
|
|
|
|
|
|
|
const closedConversationsList = useConversationStore((state) => state.closedConversationsList);
|
|
|
|
|
const setClosedConversationList = useConversationStore((state) => state.setClosedConversationList);
|
|
|
|
@ -61,11 +60,15 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [isVisible]);
|
|
|
|
|
|
|
|
|
|
const [activeList, setActiveList] = useState(true);
|
|
|
|
|
|
|
|
|
|
const [dataSource, setDataSource] = useState(conversationsList);
|
|
|
|
|
const [listUpdateFlag, setListUpdateFlag] = useState();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setDataSource(conversationsList);
|
|
|
|
|
// setDataSource(conversationsList);
|
|
|
|
|
setDataSource(activeList ? conversationsList: closedConversationsList);
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [conversationsList.length]);
|
|
|
|
|
}, [conversationsList.length, listUpdateFlag, currentConversation.unread_msg_count]);
|
|
|
|
|
|
|
|
|
|
const [switchToC, setSwitchToC] = useState({});
|
|
|
|
|
const [shouldFetchCList, setShouldFetchCList] = useState(true);
|
|
|
|
@ -141,22 +144,9 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleConversationItemUnread = async (item) => {
|
|
|
|
|
// updateConversationItem({ sn: item.sn, unread_msg_count: 1000 });
|
|
|
|
|
// const bak_dataSource = dataSource;
|
|
|
|
|
// const targetIndex = bak_dataSource.findIndex((ele) => String(ele.sn) === String(item.sn));
|
|
|
|
|
// bak_dataSource.splice(targetIndex, 1, {
|
|
|
|
|
// ...conversationsList[targetIndex],
|
|
|
|
|
// ...{ sn: item.sn, unread_msg_count: 1000 },
|
|
|
|
|
// })
|
|
|
|
|
setDataSource((prev) =>
|
|
|
|
|
prev.map((ele) => {
|
|
|
|
|
return String(ele.sn) === String(item.sn) ? { ...ele, unread_msg_count: 1000 } : ele;
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
// setDataSource(bak_dataSource);
|
|
|
|
|
// setDataSource(conversationsList);
|
|
|
|
|
await fetchConversationItemUnread({ conversationid: item.sn });
|
|
|
|
|
refreshConversationList();
|
|
|
|
|
await refreshConversationList();
|
|
|
|
|
setListUpdateFlag(Math.random());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const searchInputRef = useRef(null);
|
|
|
|
@ -181,23 +171,20 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [newChatModalVisible, setNewChatModalVisible] = useState(false);
|
|
|
|
|
const [newChatFormValues, setNewChatFormValues] = useState();
|
|
|
|
|
const [newItemLoading, setNewItemLoading] = useState(false);
|
|
|
|
|
const handleNewChat = async (values) => {
|
|
|
|
|
// console.log(values);
|
|
|
|
|
const hasNewCurrent = await getOrderConversationList(values.coli_sn, values.phone_number);
|
|
|
|
|
if (hasNewCurrent !== false) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
setNewChatModalVisible(false);
|
|
|
|
|
// const newItem = await postNewConversationItem({...values, opi_sn: userId });
|
|
|
|
|
const newChat = { phone_number: values.wa_id, remark_name: values.name };
|
|
|
|
|
setNewItemLoading(true);
|
|
|
|
|
const createdNew = await postNewConversationItem({...newChat, opi_sn: userId });
|
|
|
|
|
// if ( ! isEmpty(newItem)) {
|
|
|
|
|
// addToConversationList(newItem);
|
|
|
|
|
// setCurrentConversation(newItem);
|
|
|
|
|
addToConversationList([createdNew]);
|
|
|
|
|
setCurrentConversation(createdNew);
|
|
|
|
|
// }
|
|
|
|
|
// setNewChatFormValues(values);
|
|
|
|
|
setNewChatModalVisible(false);
|
|
|
|
|
setNewItemLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const [activeList, setActiveList] = useState(true);
|
|
|
|
|
// const closedVisible = closedConversationsList.length > 0;
|
|
|
|
|
const toggleClosedConversationsList = () => {
|
|
|
|
|
const _active = activeList;
|
|
|
|
@ -235,7 +222,7 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
return (
|
|
|
|
|
<div className='flex flex-col h-inherit'>
|
|
|
|
|
<div className='flex gap-1'>
|
|
|
|
|
{['404', 383].includes(userId) && <Button onClick={() => setNewChatModalVisible(true)} icon={<PlusSquareOutlined />} type={'text'} className='text-primary' />}
|
|
|
|
|
<Button onClick={() => setNewChatModalVisible(true)} icon={<PlusOutlined />} type={'primary'} />
|
|
|
|
|
<Input.Search
|
|
|
|
|
className=''
|
|
|
|
|
ref={searchInputRef}
|
|
|
|
@ -288,7 +275,10 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
<Dropdown
|
|
|
|
|
key={item.sn}
|
|
|
|
|
menu={{
|
|
|
|
|
items: [{ label: '标记为未读', key: 'unread' }, { label: '关闭会话', key: 'close', danger: true }, ],
|
|
|
|
|
items: [
|
|
|
|
|
{ label: '标记为未读', key: 'unread' },
|
|
|
|
|
{ label: '关闭会话', key: 'close', danger: true },
|
|
|
|
|
],
|
|
|
|
|
onClick: ({ key, domEvent }) => {
|
|
|
|
|
domEvent.stopPropagation();
|
|
|
|
|
switch (key) {
|
|
|
|
@ -309,9 +299,7 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
String(item.sn) === String(currentConversation.sn) ? '__active text-primary bg-whatsapp-bg' : '',
|
|
|
|
|
String(item.sn) === String(tabSelectedConversation?.sn) ? ' bg-neutral-200' : '',
|
|
|
|
|
].join(' ')}>
|
|
|
|
|
<div className='pl-4 pt-1 text-xs text-right'>
|
|
|
|
|
{/* {filterTags.map((tag) => <Tag color={tag.color} key={tag.value}>{tag.label}</Tag>)} */}
|
|
|
|
|
</div>
|
|
|
|
|
<div className='pl-4 pt-1 text-xs text-right'>{/* {filterTags.map((tag) => <Tag color={tag.color} key={tag.value}>{tag.label}</Tag>)} */}</div>
|
|
|
|
|
<ChatItem
|
|
|
|
|
{...item}
|
|
|
|
|
key={item.sn}
|
|
|
|
@ -337,10 +325,11 @@ const Conversations = ({ mobile }) => {
|
|
|
|
|
{dataSource.length === 0 && <Empty description={'无数据'} />}
|
|
|
|
|
</div>
|
|
|
|
|
<ConversationsNewItem
|
|
|
|
|
initialValues={{ coli_id: currentConversation.coli_id, coli_sn: currentConversation.coli_sn }}
|
|
|
|
|
initialValues={{ is_current_order: false }}
|
|
|
|
|
open={newChatModalVisible}
|
|
|
|
|
onCreate={handleNewChat}
|
|
|
|
|
onCancel={() => setNewChatModalVisible(false)}
|
|
|
|
|
loading={newItemLoading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|