From e2499e9901c5c283e6da8d33c04c8925b35fa8d3 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 5 Feb 2024 12:00:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E7=AA=97=E5=8F=A3=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=92=8C=E8=8E=B7=E5=8F=96=E6=B6=88=E6=81=AF=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/ConversationActions.js | 4 +- .../Components/ConversationsList.jsx | 46 ++++--------------- .../Conversations/ConversationProvider.jsx | 5 +- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js index 719164d..79d391b 100644 --- a/src/actions/ConversationActions.js +++ b/src/actions/ConversationActions.js @@ -111,8 +111,8 @@ export const fetchTemplates = async () => { return canUseTemplates; }; -export const fetchConversationsList = async (opisn) => { - const { result: data } = await fetchJSON(`${API_HOST}/getconversations`, { opisn }); +export const fetchConversationsList = async (params) => { + const { result: data } = await fetchJSON(`${API_HOST}/getconversations`, params); const list = data.map((ele) => ({ ...ele, customer_name: ele.whatsapp_name.trim() })); return list; }; diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index 4c91748..f05711a 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -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) => { diff --git a/src/views/Conversations/ConversationProvider.jsx b/src/views/Conversations/ConversationProvider.jsx index 473c0b6..8c26c39 100644 --- a/src/views/Conversations/ConversationProvider.jsx +++ b/src/views/Conversations/ConversationProvider.jsx @@ -56,10 +56,9 @@ const ConversationProvider = ({ children }) => { }, []); useEffect(() => { - fetchConversationsList(userId).then((data) => { - console.log(data, 'llllllllllllllllllllllll'); + fetchConversationsList({ opisn: userId }).then((data) => { dispatch(receivedConversationList(data)); - }); // todo: 和刷新订单会话页面有冲突 + }); fetchTemplates().then((data) => dispatch(receivedTemplates(data)));