From b7e10d1670f8425bfbff776729f3ac7bde069cbd Mon Sep 17 00:00:00 2001 From: Lei OT Date: Wed, 31 Jan 2024 13:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E9=97=AD=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Conversations/ConversationContext.js | 29 ++++++++++++++++--- .../Components/ConversationsList.jsx | 18 ++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/stores/Conversations/ConversationContext.js b/src/stores/Conversations/ConversationContext.js index 70d5450..198eb39 100644 --- a/src/stores/Conversations/ConversationContext.js +++ b/src/stores/Conversations/ConversationContext.js @@ -17,7 +17,24 @@ export async function fetchJSON(url, data) { const response = await fetch(`${host}${url}${ifp}${params}`); return await response.json(); } - +export async function postJSON(url, obj) { + try { + const response = await fetch(url, { + method: 'POST', + body: JSON.stringify(obj), + headers: { + 'Content-Type': 'application/json', + }, + }); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return await response.json(); + } catch (error) { + console.error('fetch error:', error); + throw error; + } +} // const API_HOST = 'http://202.103.68.144:8888'; const API_HOST = 'https://p9axztuwd7x8a7.mycht.cn/whatsapp_callback'; @@ -54,7 +71,7 @@ export const useConversations = ({loginUser, realtimeAPI}) => { }, []); useEffect(() => { - getConversationsList(); + getConversationsList(); // todo: 和刷新订单会话页面有冲突 getTemplates(); return () => {}; }, []); @@ -66,12 +83,15 @@ export const useConversations = ({loginUser, realtimeAPI}) => { // return () => {}; // }, [conversationsList]); + const poseConversationItemClose = async (item) => { + const res = await postJSON(`${API_HOST}/closeconversation`, { opisn: userId, conversationid: item.sn }); + } const getConversationsList = async () => { const { result: data } = await fetchJSON(`${API_HOST}/getconversations`, { opisn: userId }); // const _data = []; const _data = testConversations; - const list = [..._data, ...data]; + const list = [..._data, ...data.map(ele => ({...ele, customer_name: ele.whatsapp_name.trim()}))]; const dataMapped = list.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {}); setConversationsList(list); setActiveConversations({...dataMapped, ...activeConversations}); @@ -264,7 +284,8 @@ export const useConversations = ({loginUser, realtimeAPI}) => { getConversationsList, switchConversation, templates: templatesList, // setTemplates, getTemplates, - customerOrderProfile, getCustomerProfile + customerOrderProfile, getCustomerProfile, + poseConversationItemClose }; }; diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index 1273994..1095dc3 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -9,7 +9,7 @@ import { useGetJson } from '@/hooks/userFetch'; */ const Conversations = (() => { const navigate = useNavigate(); - const { switchConversation, conversationsList } = useConversationContext(); + const { switchConversation, conversationsList, poseConversationItemClose } = useConversationContext(); // console.log(conversationsList); const [chatlist, setChatlist] = useState([]); useEffect(() => { @@ -24,10 +24,12 @@ const Conversations = (() => { // subtitle: item.lastMessage, date: item.last_received_time, // last_send_time unread: item.unread_msg_count, - // showMute:true, - // mute: true, + showMute: true, + muted: false, // showVideoCall: true, - + // statusColor: '#ccd5ae', + // statusColorType: 'badge', + // statusText: 'online' })) ); @@ -43,7 +45,13 @@ const Conversations = (() => { return ( <> - onSwitchConversation(item)} /> + onSwitchConversation(item)} + // onContextMenu={(item, i, e) => { + // console.log(item, i, e); + // return (

ppp

) + // }} + onClickMute={poseConversationItemClose} + /> ); });