feat: 订单信息: 号码点击打开新建会话;
parent
015c31f3da
commit
88cedb3a8c
@ -0,0 +1,35 @@
|
||||
import useConversationStore from '@/stores/ConversationStore';
|
||||
import { fetchOrderConversationsList } from '@/actions/ConversationActions';
|
||||
import { isEmpty } from '@/utils/commons';
|
||||
export function useConversationNewItem() {
|
||||
const [currentConversation, setCurrentConversation] = useConversationStore((state) => [
|
||||
state.currentConversation,
|
||||
state.setCurrentConversation,
|
||||
]);
|
||||
const conversationsList = useConversationStore((state) => state.conversationsList);
|
||||
const addToConversationList = useConversationStore((state) => state.addToConversationList);
|
||||
const openOrderContactConversation = async (whatsappID) => {
|
||||
const { coli_sn, opi_sn } = currentConversation;
|
||||
let findCurrentOrderChats = conversationsList.filter(
|
||||
(item) => `${item.coli_sn}` === `${coli_sn}` && `${item.opi_sn}` === `${opi_sn}` && `${item.whatsapp_phone_number}` === `${whatsappID}`
|
||||
);
|
||||
let findCurrentIndex = isEmpty(findCurrentOrderChats) ? -1 : 0; // findCurrentOrderChats.length-1;
|
||||
let findCurrent = findCurrentOrderChats[findCurrentIndex];
|
||||
if (findCurrentIndex !== -1) {
|
||||
addToConversationList(findCurrentOrderChats);
|
||||
} else if (!isEmpty(whatsappID)) {
|
||||
const data = await fetchOrderConversationsList({ opisn: opi_sn, colisn: coli_sn, whatsappid: whatsappID });
|
||||
if (!isEmpty(data)) {
|
||||
addToConversationList(data);
|
||||
findCurrentIndex = data.findIndex((item) => `${item.coli_sn}` === `${coli_sn}` && `${item.opi_sn}` === `${opi_sn}` && `${item.whatsapp_phone_number}` === `${whatsappID}`);
|
||||
findCurrentIndex = findCurrentIndex >= 0 ? findCurrentIndex : 0;
|
||||
findCurrent = data[findCurrentIndex];
|
||||
}
|
||||
}
|
||||
if (findCurrentIndex >= 0) {
|
||||
setCurrentConversation(findCurrent);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return { openOrderContactConversation };
|
||||
}
|
Loading…
Reference in New Issue