关闭会话

dev/chat
Lei OT 2 years ago
parent 006be2a1c4
commit b7e10d1670

@ -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
};
};

@ -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 (
<>
<ChatList className='' dataSource={chatlist} onClick={(item) => onSwitchConversation(item)} />
<ChatList className='' dataSource={chatlist} onClick={(item) => onSwitchConversation(item)}
// onContextMenu={(item, i, e) => {
// console.log(item, i, e);
// return ( <p>ppp</p> )
// }}
onClickMute={poseConversationItemClose}
/>
</>
);
});

Loading…
Cancel
Save