|
|
|
@ -1,19 +1,55 @@
|
|
|
|
|
import { useRef, useEffect, useState } from 'react';
|
|
|
|
|
import { useParams, useNavigate } from 'react-router-dom';
|
|
|
|
|
import { List, Avatar, Flex } from 'antd';
|
|
|
|
|
import { List, Avatar, Flex, Popconfirm, Button, Dropdown } from 'antd';
|
|
|
|
|
import { SendOutlined, MessageOutlined, SmileOutlined, PictureOutlined, CommentOutlined, UploadOutlined, CloudUploadOutlined, FolderAddOutlined, FilePdfOutlined, CloseCircleOutlined, CloseCircleFilled, MoreOutlined } from '@ant-design/icons';
|
|
|
|
|
import { useAuthContext } from '@/stores/AuthContext';
|
|
|
|
|
import { useConversationState, useConversationDispatch } from '@/stores/ConversationContext';
|
|
|
|
|
import {
|
|
|
|
|
fetchCustomerProfile,
|
|
|
|
|
receivedCustomerProfile,
|
|
|
|
|
setCurrentConversation,
|
|
|
|
|
addConversationList,
|
|
|
|
|
postConversationItemClose,
|
|
|
|
|
addConversationList, delConversationitem,
|
|
|
|
|
fetchConversationItemClose,
|
|
|
|
|
fetchMessages, receivedMessageList,
|
|
|
|
|
} from '@/actions/ConversationActions';
|
|
|
|
|
import { ChatList } from 'react-chat-elements';
|
|
|
|
|
import { ChatList, } from 'react-chat-elements';
|
|
|
|
|
import { isEmpty, pick } from '@/utils/utils';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
|
|
|
|
|
const CDropdown = () => {
|
|
|
|
|
const { loginUser } = useAuthContext();
|
|
|
|
|
const { userId } = loginUser;
|
|
|
|
|
const { currentConversation } = useConversationState();
|
|
|
|
|
const dispatch = useConversationDispatch();
|
|
|
|
|
const handleConversationItemClose = async (item) => {
|
|
|
|
|
await fetchConversationItemClose({ conversationid: item.sn, opisn: userId });
|
|
|
|
|
dispatch(delConversationitem(item));
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<Dropdown key={'more-action'}
|
|
|
|
|
trigger={'click'}
|
|
|
|
|
menu={{
|
|
|
|
|
items: [
|
|
|
|
|
{
|
|
|
|
|
key: 'close',
|
|
|
|
|
danger: true,
|
|
|
|
|
label: '关闭会话',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
onClick: ({ key }) => {
|
|
|
|
|
switch (key) {
|
|
|
|
|
case 'close':
|
|
|
|
|
return handleConversationItemClose(currentConversation);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}}>
|
|
|
|
|
<Button key={'More'} type='text' title='More' className=' rounded-none text-gray-400' icon={<MoreOutlined />} size={'middle'} onClick={e => e.stopPropagation() } />
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* []
|
|
|
|
|
*/
|
|
|
|
@ -37,13 +73,14 @@ const Conversations = () => {
|
|
|
|
|
// subtitle: item.lastMessage,
|
|
|
|
|
date: item.last_received_time, // last_send_time // todo: GMT+8
|
|
|
|
|
unread: item.unread_msg_count,
|
|
|
|
|
showMute: true,
|
|
|
|
|
muted: false,
|
|
|
|
|
// showMute: true,
|
|
|
|
|
// muted: false,
|
|
|
|
|
// showVideoCall: true,
|
|
|
|
|
// statusColor: '#ccd5ae',
|
|
|
|
|
// statusColorType: 'badge',
|
|
|
|
|
// statusText: 'online'
|
|
|
|
|
className: String(item.sn) === String(currentConversation.sn) ? 'text-primary underline __active' : '',
|
|
|
|
|
// statusText: 'online',
|
|
|
|
|
className: String(item.sn) === String(currentConversation.sn) ? '__active text-primary underline bg-whatsapp-me ' : '',
|
|
|
|
|
customStatusComponents: [CDropdown],
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -91,6 +128,9 @@ const Conversations = () => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const switchConversation = async (item) => {
|
|
|
|
|
if (String(item.sn) === String(currentConversation.sn)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
dispatch(setCurrentConversation(item));
|
|
|
|
|
const messagesList = activeConversations[`${item.sn}`] || [];
|
|
|
|
|
if (isEmpty(messagesList)) {
|
|
|
|
@ -105,6 +145,8 @@ const Conversations = () => {
|
|
|
|
|
const onSwitchConversation = (item) => {
|
|
|
|
|
if (item.coli_sn) {
|
|
|
|
|
navigate(`/order/chat/${item.coli_sn}`, { replace: true });
|
|
|
|
|
} else {
|
|
|
|
|
navigate(`/order/chat`, { replace: true });
|
|
|
|
|
}
|
|
|
|
|
switchConversation(item);
|
|
|
|
|
};
|
|
|
|
@ -124,7 +166,7 @@ const Conversations = () => {
|
|
|
|
|
// console.log(item, i, e);
|
|
|
|
|
// return ( <p>ppp</p> )
|
|
|
|
|
// }}
|
|
|
|
|
onClickMute={handleConversationItemClose}
|
|
|
|
|
// onClickMute={handleConversationItemClose}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|