fix: 新建/编辑会话: 更新列表

dev/emitter
Lei OT 10 months ago
parent f2a8911d02
commit b6fd3b78a3

@ -137,11 +137,11 @@ export const postNewOrEditConversationItem = async (body) => {
...resultItem,
customer_name: `${resultItem.whatsapp_name || ''}`.trim(),
whatsapp_name: `${resultItem.whatsapp_name || ''}`.trim(),
channels: {},
tags: [],
last_message: {},
// channels: {},
// tags: [],
// last_message: {},
top_state: 0,
conversation_memo: resultItem.session_memo,
// conversation_memo: resultItem.session_memo,
};
};

@ -31,9 +31,10 @@ const CHAT_ITEM_RECORD = {
};
export function useConversationNewItem() {
const [currentConversation, setCurrentConversation] = useConversationStore((state) => [
const [currentConversation, setCurrentConversation, updateConversationItem] = useConversationStore((state) => [
state.currentConversation,
state.setCurrentConversation,
state.updateConversationItem,
]);
const conversationsList = useConversationStore((state) => state.conversationsList);
const addToConversationList = useConversationStore((state) => state.addToConversationList);
@ -77,29 +78,36 @@ export function useConversationNewItem() {
guest_phone: body.phone_number || '',
guest_name: body.name || '',
}
let buildChatItem = {};
const createdNew = await postNewOrEditConversationItem({ ...newChat, opisn: opisn || userId, conversationid });
// addToConversationList([{...createdNew, sn: createdNew.conversationid}]);
// const _list = await fetchConversationsList({ opisn });
// addToConversationList(_list, 'top');
if (!isEmpty(createdNew)) {
buildChatItem = {
// ...CHAT_ITEM_RECORD,
...createdNew,
sn: createdNew.conversationid,
channels: {
email: createdNew.guest_email,
phone_number: createdNew.guest_phone,
whatsapp_phone_number: createdNew.whatsapp_phone_number,
},
conversation_memo: createdNew.remark,
// lasttime: createdNew.session_creatime,
show_default: createdNew.remark || createdNew.guest_name || createdNew.guest_phone || createdNew.guest_email || createdNew.whatsapp_phone_number || '',
}
}
if (isEmpty(body.conversationid)) {
// const newChat = _list.find((item) => item.sn === createdNew.conversationid)
const newChat = createdNew;
if (!isEmpty(newChat)) {
const buildChatItem = {
if (!isEmpty(createdNew)) {
buildChatItem = {
...CHAT_ITEM_RECORD,
...createdNew,
sn: createdNew.conversationid,
channels: {
email: createdNew.guest_email,
phone_number: createdNew.guest_phone,
whatsapp_phone_number: createdNew.whatsapp_phone_number,
},
conversation_memo: createdNew.remark,
...buildChatItem,
lasttime: createdNew.session_creatime,
show_default: createdNew.remark || createdNew.guest_name || createdNew.guest_phone || createdNew.guest_email || createdNew.whatsapp_phone_number || '',
}
setCurrentConversation(buildChatItem);
updateConversationItem(buildChatItem);
addToConversationList([buildChatItem], 'top');
return ;
}
@ -109,6 +117,8 @@ export function useConversationNewItem() {
// })
return ;
}
updateConversationItem(buildChatItem);
};
return { openOrderContactConversation, newConversation };

Loading…
Cancel
Save