|
|
|
@ -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,16 +78,14 @@ 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(body.conversationid)) {
|
|
|
|
|
// const newChat = _list.find((item) => item.sn === createdNew.conversationid)
|
|
|
|
|
const newChat = createdNew;
|
|
|
|
|
if (!isEmpty(newChat)) {
|
|
|
|
|
const buildChatItem = {
|
|
|
|
|
...CHAT_ITEM_RECORD,
|
|
|
|
|
if (!isEmpty(createdNew)) {
|
|
|
|
|
buildChatItem = {
|
|
|
|
|
// ...CHAT_ITEM_RECORD,
|
|
|
|
|
...createdNew,
|
|
|
|
|
sn: createdNew.conversationid,
|
|
|
|
|
channels: {
|
|
|
|
@ -95,11 +94,20 @@ export function useConversationNewItem() {
|
|
|
|
|
whatsapp_phone_number: createdNew.whatsapp_phone_number,
|
|
|
|
|
},
|
|
|
|
|
conversation_memo: createdNew.remark,
|
|
|
|
|
lasttime: createdNew.session_creatime,
|
|
|
|
|
// 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)
|
|
|
|
|
if (!isEmpty(createdNew)) {
|
|
|
|
|
buildChatItem = {
|
|
|
|
|
...CHAT_ITEM_RECORD,
|
|
|
|
|
...buildChatItem,
|
|
|
|
|
lasttime: createdNew.session_creatime,
|
|
|
|
|
}
|
|
|
|
|
setCurrentConversation(buildChatItem);
|
|
|
|
|
updateConversationItem(buildChatItem);
|
|
|
|
|
addToConversationList([buildChatItem], 'top');
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
@ -109,6 +117,8 @@ export function useConversationNewItem() {
|
|
|
|
|
// })
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
updateConversationItem(buildChatItem);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return { openOrderContactConversation, newConversation };
|
|
|
|
|