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