|
|
|
@ -5,8 +5,7 @@ import { SendOutlined, MessageOutlined, SmileOutlined, PictureOutlined, CommentO
|
|
|
|
|
import { useAuthContext } from '@/stores/AuthContext';
|
|
|
|
|
import { useConversationState, useConversationDispatch } from '@/stores/ConversationContext';
|
|
|
|
|
import {
|
|
|
|
|
fetchCustomerProfile,
|
|
|
|
|
receivedCustomerProfile,
|
|
|
|
|
fetchConversationsList,
|
|
|
|
|
setCurrentConversation,
|
|
|
|
|
addConversationList, delConversationitem,
|
|
|
|
|
fetchConversationItemClose,
|
|
|
|
@ -83,44 +82,22 @@ const Conversations = () => {
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (order_sn) {
|
|
|
|
|
// getCustomerProfile(order_sn);
|
|
|
|
|
// reset chat window
|
|
|
|
|
dispatch(setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn }));
|
|
|
|
|
getOrderConversationList(order_sn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [order_sn]);
|
|
|
|
|
|
|
|
|
|
const getCustomerProfile = async (colisn) => {
|
|
|
|
|
const data = await fetchCustomerProfile(colisn);
|
|
|
|
|
dispatch(receivedCustomerProfile(data));
|
|
|
|
|
if (isEmpty(data)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!isEmpty(data.conversations)) {
|
|
|
|
|
dispatch(addConversationList(data.conversations));
|
|
|
|
|
dispatch(setCurrentConversation(data.conversations[0]));
|
|
|
|
|
const getOrderConversationList = async (colisn) => {
|
|
|
|
|
const data = await fetchConversationsList({ opisn: userId, colisn });
|
|
|
|
|
if (!isEmpty(data)) {
|
|
|
|
|
dispatch(addConversationList(data));
|
|
|
|
|
switchConversation(data[0]);
|
|
|
|
|
// dispatch(setCurrentConversation(data[0]));
|
|
|
|
|
} else {
|
|
|
|
|
// reset chat window
|
|
|
|
|
if (isEmpty(data.contact?.[0]?.whatsapp_phone_number)) {
|
|
|
|
|
dispatch(setCurrentConversation({ sn: '', customer_name: '', coli_sn: '' }));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 加入新会话
|
|
|
|
|
const newChat = {
|
|
|
|
|
'sn': uuid(),
|
|
|
|
|
// 'opi_sn': 354,
|
|
|
|
|
'coli_sn': colisn,
|
|
|
|
|
'whatsapp_phone_number': data.contact[0].whatsapp_phone_number,
|
|
|
|
|
'last_received_time': '',
|
|
|
|
|
'last_send_time': '',
|
|
|
|
|
'unread_msg_count': 0,
|
|
|
|
|
'whatsapp_name': data.contact[0].name,
|
|
|
|
|
'customer_name': data.contact[0].name,
|
|
|
|
|
};
|
|
|
|
|
dispatch(addConversationList([newChat]));
|
|
|
|
|
const newCurrent = pick(newChat, ['sn', 'coli_sn', 'whatsapp_phone_number', 'whatsapp_name', 'customer_name']);
|
|
|
|
|
dispatch(setCurrentConversation(newCurrent));
|
|
|
|
|
dispatch(setCurrentConversation({ sn: '', customer_name: '', coli_sn: order_sn }));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const switchConversation = async (item) => {
|
|
|
|
@ -134,9 +111,6 @@ const Conversations = () => {
|
|
|
|
|
const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number });
|
|
|
|
|
dispatch(receivedMessageList(item.sn, data));
|
|
|
|
|
}
|
|
|
|
|
if (isEmpty(item.coli_sn) || item.coli_sn === '0') {
|
|
|
|
|
dispatch(receivedCustomerProfile({}));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSwitchConversation = (item) => {
|
|
|
|
|